Docker 101 : Building, pulling and pushing images
To pull the nginx image from the docker repository ,we could use the below command:
To run our image, we use the below command which also maps the port "8080 of the host to the port "80" of the container:
We could test our nginx image by using the below command:
We could also build a customized image using the below command, the image is build from a file called Dockerfile that is located in the current directory:
We could check our image using the following:
We could also host our image on a repository by "pushing" it to it:
Below are some of the major commands used in the Dockerfile, which is the file we use to write the instructions that are going to make up an image:
- FROM: a Dockerfile starts with a FROM instruction which specifies the base OS image that the image is going to use, "FROM nginx:latest"
- ENV: is used for setting the environment variables which are used in the rest of Dockerfile's instructions, "ENV APACHE_VERSION 2.4.43"
- RUN: is used to run command in the form of a docker image layer, "RUN ["/bin/bash"]"
- ADD: we use it to copy files into the image, it includes lot of other features like remote addresses, "ADD file /files_directory".
- COPY: it copies local files into the container, "COPY source destination_in_container".
- CMD: it is used to provide arguments for the ENTRYPOINT commands parameters. It also provides a default command for the container. We could override it using the "docker run" command
- ENTRYPOINT: allows a container to run a command when it starts. It will the CMD - if available - as arguments.
- WORKDIR: sets the working directory for the following instructions in the Dockerfile.
- USER: specifies the user under which the following instructions in the Dockerfile are going to run, "USER nginx_user".
- We could override the USER through the "docker run" command through the "--user" parameter.
- A Dockerfile can only have one CMD parameter.