I assume you have Docker installed in your system by now.
- Verify docker is installed by running
Run the docker
hello-world image by following the steps below.
- Run the hello-world image by running
docker -D run hello-world
-D runs the docker command in debug mode, so you can see what exactly happening behind the scene.
- As you observed, docker first checks if there is an image in the given name “hello-world”. As it does not find in the host machine, it pulls from the docker-hub to host (local machine) and then it runs the image. The runnable instance of the image is called a container.
- The container echos some message on the terminal and exits.
- Now, try to delete the image by
docker rmi hello-world , you will notice that the image cannot be removed as it has a dependent container.
- So, remove the container from machine to clean up by running
docker rm docker_id
- Remove the image by running
docker rmi hello-world
- Now the
hello-world image is also cleaned up from your system.
As explained above, Dockerfile has the instructions or commands that explains to the docker how to and what to build. We will look into this little more in details as this is the most important of Docker tutorial.
FROM: Explains the base image that is used to build the custom hello-docker image. This is like inheritance/reusability.
LABEL: This is to set some labels/meta information about your image. Like version, author, email, license, and etc.
CMD: Command to run in the hello-docker image
There are several other commands as below.
FROM, LABEL, COPY, RUN, EXPOSE, ENV, ADD, COPY, ENTRYPOINT, VOLUME, USER, WORKDIR, ARG, ONBUILD, STOPSIGNAL, HEALTHCHECK, SHELL. All these commands need to be written in capital letter.
In the next tutorial, we will spend some more time in understanding each of these commands. Let me know your questions in the comment below.