Docker 101 : Building, pulling and pushing images
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 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".
Remarks:
- We could override the USER through the "docker run" command through the "--user" parameter.
- A Dockerfile can only have one CMD parameter.
Comments