Deploy Your First Docker Container

The command docker runserves to launch Docker containers from images.

In this article, We’ll show you how to run a container from an image using the example of the latest official base Docker image of Ubuntu.

We’ll show you how to install apache2inside a container with Ubuntu and how to save this container as a new image.

And in the end, you will be able to run containers from this new image in the interactive and background modes.

Good advice: An image vs. Container … What’s the difference? Read More →

Running the Container from the Image into the Docker

Do not Confuse: The Docker image itself cannot be “run”. The command docker runtakes the Docker image as a template and creates a container from it, which is launched.

Locate the required image on the Docker Hub :

Download the Docker image from the repository using the command docker pull:

Start the container from the Docker image:

When you execute Docker run image, the Docker engine takes image, adds the writeable top layer and initializes various parameters (network ports, container name, identifier and resource limits).

Install the Web server apache2inside the container, and then exit it:

From the stopped container in which you installed apache2, create a new image and name it apache_snapshot:

To view all the images on the Docker host:

Now from the new Docker-image, you can start the containers in interactive mode:

Alternatively, you can run the container from the Docker image in the background with the port :80inside the Docker container flown to the :8080Docker host port :

In this case, to make sure that apache2inside the container is running, simply open http://localhost:8080/ and you will see the start page: “Apache2 Ubuntu Default Page”.

Authored By Imran Yousaf

I am Imran Yousaf, a computer geek, founder of the site I am a die hard fond of open-source software and Linux operating system. In addition to Linux, I am interested in everything related to information technology and modern science.

Leave a Reply

Your email address will not be published. Required fields are marked *