The Commands

Examine the major commands to work with containerizing an application.

We'll cover the following

Docker commands

  • docker image build is the command that reads a Dockerfile and containerizes an application. The -t flag tags the image, and the -f flag lets you specify the name and location of the Dockerfile. With the -f flag, it is possible to use a Dockerfile with an arbitrary name and in an arbitrary location. The build context is where your application files exist, and this can be a directory on your local Docker host or a remote Git repo.

  • The FROM instruction in a Dockerfile specifies the base image for the new image you will build. It is usually the first instruction in a Dockerfile and a best-practice is to use images from official repos on this line.

  • The RUN instruction in a Dockerfile allows you to run commands inside the image. Each RUN instruction creates a single new layer.

  • The COPY instruction in a Dockerfile adds files into the image as a new layer. It is common to use the COPY instruction to copy your application code into an image.

  • The EXPOSE instruction in a Dockerfile documents the network port that the application uses.

  • The ENTRYPOINT instruction in a Dockerfile sets the default application to run when the image is started as a container.

  • Other Dockerfile instructions include LABEL, ENV, ONBUILD, HEALTHCHECK, CMD, and more.

Get hands-on with 1200+ tech skills courses.