Docker Hub
Pulling pre-built images from Docker Hub is a common practice, as Docker Hub serves as a centralized registry for Docker images. Here's how you can pull pre-built images from Docker Hub:
- Search for an Image:
If you know the name of the image you want to pull, you can search for it on the Docker Hub website or by using the "docker search" command. For example, let's search for the official NGINX image:
docker search nginx
Once you've found the desired image, you can pull it using the "docker pull" command followed by the image name and optionally the tag (version). For example, to pull the latest version of the NGINX image, run:
docker pull nginx
If you want to pull a specific version of the image, you can specify the tag. For example, to pull version 1.19.8 of the NGINX image, run:
docker pull nginx:1.19.8
After the pull operation completes, you can verify that the image has been successfully pulled by running the following command:
docker images
This command lists all the Docker images on your system, and you should see the pulled NGINX image listed among them.
Once the image is pulled, you can run a container from it using the "docker run" command. For example, to start a container based on the NGINX image, run:
docker run -d -p 80:80 nginx
- "-d" runs the container in detached mode (in the background).
- "-p 80:80" maps port 80 of the host to port 80 of the container, allowing access to the NGINX web server.
- "nginx" specifies the name of the image to use for creating the container.
After running this command, you should have an NGINX container running in the background, serving web content on port 80 of your host machine.
This process allows you to quickly and easily deploy applications using pre-built images from the Docker Hub registry.