sajad torkamani

EXPOSE

The EXPOSE instruction informs Docker that the container will listen on the specified network ports at runtime. It won’t actually publish the port. It documents what ports are intended to be published. To actually publish the port at runtime, you can use the -p flag (e.g., docker run -p 800:80).

It’s useful to remember that the docker network command supports creating networks for communication among containers without the need to expose or publish specific ports (See networking overview).

FROM

The FROM instruction initialises a new build stage and sets the base image for subsequent instructions.

COPY

COPY [--chown=<user>:<group>] [--chmod=<perms>] <src>... <dest>

The COPY instruction copies new files or directories from <src> to the filesystem of the container at the path <dest>.

All new files and directories are created with a UID and GID of 0, unless the optional --chown flag specifies a specific username, groupname or UID/GID combination.

Important points to note:

  • The <src> path must be inside the context of the build. You cannot COPY ../something /something.
  • If <dest> doesn’t exist, it is created along with all missing directories in its path.

CMD

Provides the default command for an executing container. In other words, it’s the default command that will execute when the container is started. If the user specifies an argument to docker run <user-args...>, then they will override the default specified in CMD.

Forms

  • CMD ["executable","param1","param2"] (exec form, this is the preferred form)
  • CMD ["param1","param2"] (as default parameters to ENTRYPOINT)
  • CMD command param1 param2 (shell form)

RUN

The RUN instruction will execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile.

The default shell for the shell form can be changed using the SHELL command.

Forms

  • RUN <command> ( the command is run in a shell, which by default is /bin/sh -c on Linux or cmd /S /C on Windows) (shell form)
  • RUN ["executable", "param1", "param2"] (exec form)

Sources

Tagged: Docker

Leave a comment

Your email address will not be published. Required fields are marked *