Docker pulls nginx image and creates nginx-test container
1. Install dependent packages
Since nginx is developed based on C language, it is necessary to install a C language compilation environment and third-party dependent libraries such as regular expression libraries.
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
2. Get nginx mirror list
docker search nginx
3. Pull the nginx image
docker pull nginx
Use docker pull nginx
the command to pull the nginx image to the local. Here we get the latest official image that ranks first. For other versions, you can go to DockerHub to check
4. Create a container to test whether it is available
First test whether the nginx image is available, create and start the nginx container
sudo docker run --name nginx-test -p 8081:80 -d nginx
-
-d specifies that the container runs in the background as a daemon
-
--name specifies the container name, here I specify nginx-test
-
-p Specifies the mapping relationship between the host and the port number inside the container, format -p
-
[Host port number]: [Container internal port], here I use port 8081 of the host to map port 80 of the container
Visit http://IP:port/ , the installation is successful during the test
http://IP: port, the web page is accessed normally, which means that the creation of nginx image and the creation of nginx-test container have been successful in this step