Kubernetes - Commands and Arguments π£
Description π
To pass arguments to a container, you can use the args field of the container spec. Arguments to the entrypoint can be passed using the command field of the container spec.
- example
containercmd-and-args-example/Dockerfile - example
pod definitioncmd-and-args-example/pod-definition.yaml
Docker Commands and Arguments π³
-
generic
DOCKERFILEtemplateFROM <image> RUN <command> CMD <command> -
commands template with parameters
CMD command param CMD ["command", "param"] -
example command with arguments
CMD sleep 5 CMD ["sleep", "5"] -
makes a custom image of ubuntu and makes it sleep 5 seconds then exits
FROM Ubuntu CMD sleep 5 - makes a custom image of ubuntu and makes it sleep from passed in param in entrypoint
- entrypoint is the command that is run when the container is started
FROM Ubuntu ENTRYPOINT ["sleep"] -
makes a custom image of ubuntu and makes it sleep from passed in param in entrypoint with default of 5 seconds
FROM Ubuntu ENTRYPOINT ["sleep"] CMD ["5"]- you can override the entrypoint command with the βentrypoint flag
-
Docker
Securityπ-
to run docker as a non-root user
docker run --user=<user id> <image> -
users can also be defined in the dockerfile
FROM ubuntu USER <user id>
-
Examples π§©
-
sample
Dockerfileπ³FROM ubuntu ENTRYPOINT [ "sleep" ] CMD [ "5" ] -
sample
poddefinition withcontainercommands and argumentsapiVersion: v1 kind: Pod metadata: name: ubuntu-sleeper-pod spec: containers: - image: ubuntu-sleeper name: ubuntu-sleeper # overrides the entrypoint instruction command: ["echo"] # overrieds the commad instruction args: ["10"]