- 🏆🏆🏆 Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
- 📣📣 welcome to give your thumbs up and follow!!
preface
Nginx (Engine X) is a high-performance HTTP and reverse proxy Web server that also provides IMAP/POP3/SMTP services.
Pull the Nginx image in docker
-
Find nginx images on Docker Hub
[root@localhost ~]# docker search nginx Copy the code
-
Pull the official Nginx image
[root@localhost ~]# docker pull nginx Copy the code
-
REPOSITORY is an image of nginx in the local image list
[root@localhost ~]# docker images nginx\ REPOSITORY TAG IMAGE ID CREATED SIZE\ docker.io/nginx latest f949e7d76d63 5 weeks ago 126 MB\ Copy the code
-
The following command uses the default configuration of NGINX to start an NGINX container instance:
[root@localhost ~]# docker run --rm --name nginx-test -p 8080:80 -d nginx\ 358354f206fdbc5c20199a307392c11972b1bedab306144e5af56995edbb3e4b Copy the code
-
The meanings of the four command line parameters are as follows:
--rm: After the container stops running, the container file is automatically deleted. --name nginx-test: indicates that the container is named nginx-test, and the name is self-defined. -p: indicates that port mapping is performed to map local port 8080 to port 80 inside the containerCopy the code
-
Pull the official Nginx image
[root@localhost ~]# docker container ps\ CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES\ 4a7494723341 nginx "nginx -g 'daemon ..." 11 seconds ago Up 7 seconds 0.0.0.0:8080->80/ TCP nginx-testCopy the code
Successful startup, as shown below:
Nginx service deployment, mapping local directories to nginx containers
- Create a local directory for storing nginx-related file information.
# mkdir -p /home/nginx/www /home/nginx/logs /home/nginx/conf
Copy the code
Among them:
WWW: directories will be mapped to virtual directories configured by the Nginx container. Logs: The directory will be mapped to the log directory of the Nginx container. Conf: Configuration files in the directory will be mapped to configuration files in the nginx container.Copy the code
- Copy the Nginx default configuration file to the conf directory of the current directory on the local.
[root@localhost home]# docker ps\ CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES\ 358354f206fd nginx "nginx -g 'daemon ..." 29 minutes ago Up 29 minutes 0.0.0.0:8080->80/ TCP nginx-test\ [root@localhost home]#\ [root@localhost home]# docker cp 358354f206fd:/etc/nginx/nginx.conf /home/nginx/conf/Copy the code
- The deployment command
# docker run --rm -d -p 8081:80 --name nginx-test-web \\
-v /home/nginx/www:/usr/share/nginx/html \\
-v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \\
-v /home/nginx/logs:/var/log/nginx \\
nginx
Copy the code
- Command description:
--rm: After the container stops running, the container file is automatically deleted. -p 8081:80: maps port 80 of the container to port 8081 of the host. --name nginx-test-web: The container named nginx - test - web - v/home/nginx/WWW: / usr/share/nginx/HTML: will we create the WWW directory mounted to the container's/usr/share/nginx/HTML. - v/home/nginx/conf/nginx. Conf: / etc/nginx/nginx. Conf: will we create nginx. Conf mounted to the container of the/etc/nginx/nginx. Conf. - v/home/nginx/logs: / var/log/nginx: will we create logs mounted to the container/var/log/nginx.Copy the code
- /home/nginx/ WWW
[root@localhost ~]# cd /home/nginx/www/\ [root@localhost www]# vim index.html\ \ <! DOCTYPE html>\ <html>\ <head>\ <meta charset="utf-8">\ <title>Nginx test !!! < / title >, < / head >, < body > \ < h1 > my first title < / h1 > \ < p > my first paragraph. </p>\ </body>\ </html>Copy the code
Access link, as shown below:
🏆