I run tests inside docker image and I need to pass custom arguments all the time.
When I put arguments after image name docker thinks that argument is image name.
docker run -t -i image-name -s test.py
docker run -t -i image-name -- -s test.py
Error:
Failed no image test_arena2.py
Docker version 1.11.2, build b9f10c9
When we launch our Docker container, we can pass environment variables as key-value pairs directly into the command line using the parameter –env (or its short form -e). As can be seen, the Docker container correctly interprets the variable VARIABLE1.
If you want to pass multiple build arguments with docker build command you have to pass each argument with separate — build-arg. docker build -t <image-name>:<tag> --build-arg <key1>=<value1> --build-arg <key2>=<value2> .
Running Commands in an Alternate Directory in a Docker Container. To run a command in a certain directory of your container, use the --workdir flag to specify the directory: docker exec --workdir /tmp container-name pwd.
You can build your Dockerfile with a combination of ENTRYPOINT
and CMD
instructions, which will let you run containers with or without arguments, e.g:
FROM ubuntu
ENTRYPOINT ["/bin/echo"]
CMD ["hello"]
That says the entrypoint is the echo
command, and the default argument is hello
. Run a container with no arguments:
> docker run temp
hello
Run with arguments and they all get passed to the entrypoint command:
> docker run temp -s stackoverflow
-s stackoverflow
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With