Posted on January 16, 2023
An image contains all the software you need to run within your container. Container images can be stored locally on your machine, as well as in a container registry. There are public registries, such as https://hub.docker.com/, or private registries such as ACR (Azure Container Registries). You can pull existing images from the docker hub or private registries using In the following example, we will pull an image from the public Docker Hub repository and run the actual container. In the previous example, you saw that it is possible to run a container without building an image first. however, it is very common in the practical world that you will want to build an image first. To do this, you use a Dockerfile. Docker images can be created using a special file format called a “Dockerfile”. This file has commands that allow you to: In the next example, you will build a custom Docker Image. This custom image will display inspirational quotes in the whale output. You typically save a Dockerfile in a file called Dockerfile, without an extension. You will now see Docker execute a number of steps Following is the command output with inspirational quotes and if you run the container multiple times, you will see different quotes appear. That concludes our overview and demo of containers. In this section, you started with an existing container image and launched it on the machine. Afterward, you took that a step further and built your own container image, then started containers using that image. You have now learned what it takes to build and run a container.Prerequisite
Once installation is finished and your environment setup is completed.
docker pull
#First, we will pull an image
docker pull docker/whalesay
#We can then look at which images are stored locally
docker images
#Then we will run our container
docker run docker/whalesay cowsay boo
Following is the command output
Let's look at what happing behind the scene.
FROM docker/whalesay:latest
RUN apt-get -y -qq update
RUN apt-get install -qq -y fortunes
CMD /usr/games/fortune -a | cowsay
Let's look at what happing behind the scene.
#To run your container
docker run smartwhale