Containerizing an App - The Commands

Examine the major commands used for containerizing an application.

The summary of commands for containerizing an app

  • docker build containerizes applications. It reads a Dockerfile and follows the instructions to create an OCI image. The -t flag tags the image, and the -f flag lets you specify the name and location of the Dockerfile. The build context is where your application files exist and can be a directory on your local Docker host or a remote Git repo.

  • The Dockerfile FROM instruction specifies the base image. It’s usually the first instruction in a Dockerfile, and it’s considered a good practice to build from Docker Official Images or images from Verified Publishers. FROM is also used to identify new build stages in multi-stage builds.

  • The Dockerfile RUN instruction lets you run commands during a build. It’s commonly used to update packages and install dependencies. Every RUN instruction creates a new image layer.

  • The Dockerfile COPY instruction adds files to images, and you’ll regularly use it to copy your application code into a new image. Every COPY instruction creates an image layer.

  • The Dockerfile EXPOSE instruction documents an application’s network port.

  • The Dockerfile ENTRYPOINT and CMD instructions tell Docker how to run the app when starting a new container.

  • Some other Dockerfile instructions include LABEL, ENV, ONBUILD, HEALTHCHECK and more.

Get hands-on with 1400+ tech skills courses.