How to make a Docker environment variable value to get a random id How to make a Docker environment variable value to get a random id docker docker

How to make a Docker environment variable value to get a random id


Add uuidgen package to the image. In case you are using alpine add

RUN apk add --no-cache util-linux

to the Dockerfile

Then in the entrypoint of your Dockerfile add

Below is a sample Dockerfile

FROM alpine:latestRUN apk add --no-cache util-linuxENTRYPOINT export UUID=`uuidgen` && echo $UUIDFROM alpine:latest


You should pass the environment variable from a docker run -env parameter generated uuid or guid from your shell, eg:

bash:

docker run --env SERVICE_TAG=$(uuidgen) yourimage

See more details at the official docker docs: