Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
  1. For building images, we create Dockerfile and add instructions to it.

Detailed description of all instructions to create a Dockerfile are given as follows -

...

The difference between “RUN” and “CMD” instructions is that the “RUN” instruction executes at the time image is getting created whereas “CMD” instruction executes when a container based on this image starts.

2. Once we have this Dockerfile ready, we can build an image based on this Dockerfile by executing the following command -

Code Block
docker build <dockerfile_path>

Here, “dockerfile_path” specifies the path in which the Dockerfile is present.

*** NOTE: EXPOSE instruction does NOT do anything. It is added only as a best practice so as to document which port will be exposed by your container. To tell docker so as to which port an internal docker container port should be made accessible to the outside network, we specify “-p” flag while running the container. For e.g. -

Code Block
docker run -p 3000:80 <docker_id>