Mega Menu

Tuesday, April 21, 2020

Docker - Command and Entrypoint

If a process inside the container is dead, the container exits and will no longer be running. 

Command is a process that is specified in the DockerFile, which should be executed when a Docker image is run.
The arguments will have to be hard-coded within the Dockerfile.

Docker File:

    FROM ALPINE

    CMD ["sleep","10"]    OR     
    CMD sleep 10
   
Docker Run:   

    docker run alpine
            This will execute
                    docker run alpine sleep 10
               
Entry point is the command that executes at the start of the container. The argument passed as input while running the container will be passed as input to the entry point command.
This will allow the command arguments to be dynamic, rather than hard-coded in the DockerFile
       
Docker File:

    FROM ALPINE

    ENTRYPOINT ["sleep"]
   
Docker Run:   

    docker run alpine 15
            This will execute
                    docker run alpine sleep 15
               
               
To set a default value to an EntryPoint command,

Docker File:

    FROM ALPINE

    ENTRYPOINT ["sleep"]

    CMD ["5"]   

   
Docker Run:   

    docker run alpine
            This will execute
                    docker run alpine sleep 5
               
    docker run alpine 20
            This will execute
                    docker run alpine sleep 20


To override the entrypoint command runtime, pass an entrypoint argument while running a docker container -

Eg:
         docker run --entrypoint sleep2 alpine 10   
                ----- this executes sleep2 process instead of sleep which is in the dockerfile


No comments:

Post a Comment