How to search for docker images and launch a container

Introduction

Docker Images: In our last guide setting up Docker on RHEL server have been covered. Let’s now start to use docker by searching for existing images and run with a container.

Docker command has several options and arguments. Using those all options under the required circumstance is necessary while we about to launch containerized services.

Now we are about to know only how to do a search for images, how to download those images and how to launch a container from the downloaded images. Assume you need two versions of Nginx web servers to deploy with the legacy application and latest one. Let find the image and launch two containers for our requirement.

Articles related to Docker Series

  1. How to install Docker on Red Hat Enterprise Linux and CentOS Linux 7
  2. How to search for docker images and launch a container
  3. How to connect Docker containers and expose the network
  4. How to manage Docker containers

Step 1: Search for container images

Start to search for a docker image, In the list, we will get the official and most trusted image file in the first line.

# docker search nginx
Docker search command to list available images
  1. Docker command used to search the image
  2. The name of the image file in the docker registry.
  3. A short description of the image.
  4. Stars provided by users how they trust the image file.
  5. OK” represent its an Official image from Nginx.

Step 2: Download images to the local server

By using pull command we are able to download the docker images from the docker registry. To download with the latest image file we don’t require to mention the version. All the image files in the docker registry will be marked with a “tag” to identify them as latest or any other earlier versions. While downloading an image without a tag it will pull the latest image which has “nginx: latest“.

# docker pull nginx               # Downloading without tag
Pulling docker images from docker registry

[stextbox id=”info”]Docker does not have an option to list all the available image versions.[/stextbox]

To know the available docker image versions, navigate to docker hub.

https://hub.docker.com/

Create with a docker Hub ID and search for Nginx image.

click on explore to list all official repositories.

Start to explore all available docker images

From the list find Nginx and click on “Details” to know more information about the image.

Nginx Docker container information

Detailed information about the Nginx image.

Information about docker images in the docker registry
  1. Latest image updated to docker registry 10 days before.
  2. The official build of nginx
  3. The latest image file version is 1.15. Note:> we don’t require to mention the version if we required to download the latest.
  4. An earlier stable release version of nginx from docker registry.

Let’s download the earlier and latest version of nginx.

# docker pull nginx                       # Downloading latest version without tag
# docker pull nginx:1.14                  # Downloading earlier stable version with tag
“docker pull nginx” to download the latest image

Step 3: List the downloaded images

To list the downloaded docker images use below command, we can notice all downloaded images in our previous steps.

# docker images
“docker images” to list all downloaded images

Step 4: Launch a container from docker images

Now time to launch a container from the downloaded images.

To launch the container without any options.

# docker run nginx

Launch a container from image nginx:1.14 in the background, To run a container in the background we should use the option “-d” detached mode.

# docker run -d nginx:1.14
“docker run nginx” to launch a container from the image

Launch two containers using downloaded images for test and prod servers.

To identify the server with a unique name we can assign with one by using “–name” option while launching a container.

# docker run -d --name nginx-test-server nginx
# docker run -d --name nginx-prod-server nginx:1.14
Docker run nginx with a different image

To list the running container

# docker ps
“docker ps” command to list the running containers
  1. Image used by the container
  2. Command used to bring up the service in the container
  3. When the container was created
  4. How long container Up and running
  5. Ports exposed from the container
  6. Name of the container to identify
  7. Container name in the form of a random ID.

That’s it we have launched two numbers of Nginx web servers using different image versions.

Conclusion

We have seen how to search, pull and launch a docker container from downloaded images. By following let see how to log in and expose the network of Docker containers, till then subscribe to our newsletter and stay up-to-date with docker articles.

Exit mobile version