Deano
Deano

Reputation: 12190

Docker passing environment variable

Here is my DockerFile, it has a default EN, which I would like to override upon container deployment if specified.

ENV domain example.com

CMD ["cd","/etc/httpd/conf.d/"]
CMD [ "cp", "VirtualHost", "${domain}" ]

However when passing EN using -e command

docker run -it -e domain="test.com" container_id

I'm able to login to the container, echo $domain and it displays EV which has been passed however the copy command didn't copy the file.

Any ideas on what possibly I'm doing wrong?

Thanks

Upvotes: 1

Views: 95

Answers (1)

Adrian Mouat
Adrian Mouat

Reputation: 46480

You can't have two CMD lines, the second one will simply override the first. But in your case, I think you want to use the WORKDIR command to set the directory, not CMD e.g:

WORKDIR /etc/httpd/conf.d/

This should set the current directory for all following instructions and container start-up.

BTW I'm not sure how you're logging into this container - when you run it, the cp command will fire and the container will exit once it has completed. If you override the CMD to get a shell (for example with docker run -it mycontainer bash) the cp command will never be executed.

Upvotes: 1

Related Questions