Working on my first Docker image. It is a dotnet program that uses CMD to launch (only one CMD allowed in Docker). I would like to pass the program an argument (an API key) at runtime. After some googling, not finding a clear answer. Entrypoint doesn't seem helpful. Maybe ENV, but it seems ENV is only for Docker. My Dockerfile:
FROM microsoft/dotnet
WORKDIR /app
COPY . /app
CMD [ "dotnet", "/app/netcore/Somename.dll"]
Thanks
Docker joins ENTRYPOINT and CMD into single command line, if both use JSON notation, like in your example.
This is JSON notation: CMD [ "dotnet", "/app/netcore/Somename.dll"]
This is shell notation: CMD dotnet /app/netcore/Somename.dll
Another thing you need to know - what is written in docker run ... <image_name> ... after - considered as CMD.
So, to conclude.
The constant (immutable) part of command line, like dotnet foo.dll you can put in ENTRYPOINT.
Variable part, like additional arguments, you supply with docker run and optionally put defaults to CMD in Dockerfile
Example:
Dockerfile
...
ENTRYPOINT ["dotnet", "/app/netcore/Somename.dll"]
CMD ["--help"]
Command line 1:
docker run ... <your image name> --environment=Staging --port=8080
Will result in dotnet /app/netcore/Somename.dll --environment=Staging --port=8080
Command line 2:
docker run ... <your image name>
Will result in dotnet /app/netcore/Somename.dll --help. --help comes from default value, defined in Dockerfile.
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