copy a file using an environment var in a docker file then execute the entrypoint

时间:2018-07-25 04:22:31

标签: dockerfile

I'm trying to deploy a container and dynamically set the correct configuration (dev, qa, prod) at run time

basically I want to do this....(which doesn't work)

FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
WORKDIR /usr/share/nginx/html
COPY dist/ .
CMD cp configuration.$env.json configuration.json
ENTRYPOINT [ "nginx", "-g", "daemon off;" ]

And then when I start the container I pass the env that I want

docker run -d -p 8080:80 --name MyUI -e env=qa myimage

Ideally I want the CMD to be a shell command, so I get the environment var and the ENTRYPOINT to be exec form (if this is possible)

1 个答案:

答案 0 :(得分:0)

您是否尝试过使用ARG?另外,如果这些只是qa,prod等,那么还可以,但是如果您打算以这种方式使用机密,那么最好使用env_file并将其加密为ARG留下痕迹