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 required circumstance is necessary while we about to launch a 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.
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 command used to search the image
- The name of the image file in the docker registry.
- A short description of the image.
- Stars provided by users how they trust the image file.
- “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
To know the available docker image versions, navigate to docker hub.
Create with a docker Hub ID and search for Nginx image.
click on explore to list all official repositories.
From the list find Nginx and click on “Details” to know more information about the image.
Detailed information about the Nginx image.
- Latest image updated to docker registry 10 days before.
- The official build of nginx
- The latest image file version is 1.15. Note:> we don’t require to mention the version if we required to download the latest.
- 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
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
Step 4: Launch a container from docker images
Now time to launch 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
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
To list the running container
# docker ps
- Image used by the container
- Command used to bring up the service in the container
- When the container was created
- How long container Up and running
- Ports exposed from the container
- Name of the container to identify
- 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.
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.