# Dockerfile

# ENTRYPOINT vs CMD

No ENTRYPOINT ENTRYPOINT exec_entry p1_entry ENTRYPOINT [“exec_entry”, “p1_entry”]
No CMD error, not allowed /bin/sh -c exec_entry p1_entry exec_entry p1_entry
CMD [“exec_cmd”, “p1_cmd”] exec_cmd p1_cmd /bin/sh -c exec_entry p1_entry exec_entry p1_entry exec_cmd p1_cmd
CMD [“p1_cmd”, “p2_cmd”] p1_cmd p2_cmd /bin/sh -c exec_entry p1_entry exec_entry p1_entry p1_cmd p2_cmd
CMD exec_cmd p1_cmd /bin/sh -c exec_cmd p1_cmd /bin/sh -c exec_entry p1_entry exec_entry p1_entry /bin/sh -c exec_cmd p1_cmd

# ENTRYPOINT

  1. exec

    ENTRYPOINT ["executable", "param1", "param2"]

    Example:

    FROM ubuntu
    ENTRYPOINT ["top", "-b"]
    CMD ["-c"]
    

    Run: Command line arguments to docker run will be appended after all elements in an exec form ENTRYPOINT, and will override all elements specified using CMD

    docker run -it --rm --name test  top -H
    
    top -b -H
    
  2. shell

    ENTRYPOINT command param1 param2

# CMD

CMD commands are ignored by Daemon when there are parameters stated within the docker run command

# ENV

The ENV instruction sets the environment variable to the value. The environment variables set using ENV will persist when a container is run from the resulting image.

# to override
docker run -e xx=yy

# ARG

They are only available from the moment they are ‘announced’ in the Dockerfile with an ARG instruction up to the moment when the image is built. Running containers can’t access values of ARG variables.

ARG some_variable_name
# or with a hard-coded default:
#ARG some_variable_name=default_value
# ${xx:-yy}
docker build --build-arg some_variable_name=a_value

# .dockerignore

DOCKER_BUILDKIT=1 docker ...: as long as .dockerignore is in the same directory of Dockerfile, it will be processed.

Last Updated: 3/11/2022, 9:08:49 PM