Module IV Docker
Module IV Docker
APPLICATION WITH
DOCKER
Docker is a containerization tool that became open source in 2013.
2
}}
13
2. COPY and ADD: These are used to copy one or more local files into an image.
The ADD instruction supports an extra two functionalities, to refer to a Uniform
Resource Locator (URL) and to extract compressed files.
3.RUN and CMD: These instructions take a command as a parameter that will be
executed during the construction of the image. The RUN instruction creates a
layer so that it can be cached and versioned. The CMD instruction defines a
default command to be executed during the call to run the image.
BUILDING AND RUNNING A CONTAINER 15
ON A LOCAL MACHINE
T he execution of Docker is performed by different operations, as
outlined here:
The -t argument indicates the name of the image and its tag. Here,
in our example, we call our image demobook, and the tag we've
added is v1.
When you execute the docker build command, it downloads the 17
base image indicated in the Dockerfile from Docker Hub, and
then Docker executes the various instructions that are
mentioned in the Dockerfile.
At the end of the execution, we obtain a locally stored Docker
demobook image.
We can also check if the image is successfully created by
executing the following Docker command:
After the execution of each container, we have its shortcut ID, its
associated image, its name, its execution command, and its
translation port information displayed.
20
TESTING A CONTAINER LOCALLY
Everything that runs in a container remains inside it—this is the
principle of container isolation.
However, in the port translation that we did previously, you can
test your container on your local machine with the run command.
To do this, open a web browser and enter http://localhost:8080
with 8080, which represents the translation port indicated in the
command.
PUSHING AN IMAGE TO DOCKER HUB 21
If you want to create a public image, you can push (or upload) it
to Docker Hub, which is Docker's public (and free, depending on
your license) registry.
To push a Docker image to Docker Hub, perform the following
steps:
1. Sign In to Docker Hub: Log in to Docker Hub using the following
command:
2.Retrieve the image ID: The next step consists of retrieving the ID of
the image that has been created. To do so, we will execute the docker
images command to display a list of images with their ID.
3. Tag the image for Docker Hub:
With the ID of the image we retrieved, we will now tag the image for
Docker Hub. To do so, the following command is executed:
23
4. Push the Docker image to Docker Hub:
After tagging the image, the last step is to push the tagged image to
Docker Hub. For this purpose, we will execute the following command:
We can see from this execution that the image is uploaded to Docker Hub. To view
the pushed image in Docker Hub, we connect to the Docker Hub web portal at
https://hub.docker.com/ and see that the image is present.
By default, the image pushed to Docker Hub is in public mode—everybody can
view it in the explorer and use it.