docker run ubuntu [COMMAND]
docker run ubuntu sleep 5
The above is helpful when creating docker images when you just want to see how the container has been configured without actually running it. It can be helpful when a container crashes to examine the container as maybe something inside the container (file system, permissions) are missing/incorrect.
If you want to be able to pass a variable to a docker image (say, you want to have an image that sleeps, but want to be able to pass in how long it sleeps. If you build the image with the ENTRYPOINT ["sleep"] line, y ou can then run the container and pass the number of seconds to for the image to sleep.
FROM Ubuntu
ENTRYPOINT ["sleep"]
run the unbuntu-sleeper image and pass an argument of 10 seconds to the sleep Entrypoint of the docker container.
docker run ubuntu-sleeper 10
In order to create a default value ,you can use both the CMD and ENTRYPOINT in the docker container.
docker build -t ubuntu-sleeper
FROM Ubuntu
ENTRYPOINT["sleep"]
#Adding a default of 5 sec for sleep command
CMD["5"]
This will run the ubuntu-sleeper container for 5 seconds (container default)
kubectl run ubuntu-sleeper
the above will result in the following command being run when the container starts:
sleep 5
You can override the defaut CMD time of 5 and replace it with 10:
kubectl run ubuntu-sleeper 10
In this example, a docker file has been created with the entrypoint of sleep (which means it will execute the sleep command) for 5 seconds
You can override the entrypoint and cmd lines from a DOCKERFILE in the YAML file at runtime.
Dockerfile -> yamlfile
ENTRYPOINT. -> command
CMD -> args
You can override the sleep command (specified by the ENTRYPOINT in the DOCKERFILE) by specifying a command argument in the container section. You can also override the CMD line with the args line.
You can override the sleep command (specified by the ENTRYPOINT in the DOCKERFILE) by specifying a command argument in the container section. You can also override the CMD line with the args line.
apiVersion: v1
kind: Pod
metadata:
name: ubuntu-sleeper-2
spec:
containers:
- name: ubuntu
image: ubuntu
command:
- "sleep"
- "5000"