简体   繁体   中英

Docker Entrypoint environment variables not printed

I'm new to Docker. All I want is to print an environment variable I pass to docker run via the -e flag. My Dockerfile looks like this:

FROM openjdk:8-jdk-alpine
ENTRYPOINT echo $TEST

I build my image with docker build -t test-docker . and execute it with docker run test-docker -e TEST=bar . It just prints an empty line and exits.

This happens because you run the image having parameters in wrong order, should be:

docker run --rm -e TEST=bar test-docker

Notice the env var is specified before the image name. Everything after your image name is considered as an argument of your container.

Use --rm always when playing to prevent garbage containers from piling up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM