Docker deployment nginx implementation process graphic and text detailed explanation

Docker deployment nginx implementation process graphic and text detailed explanation

1. Download nginx

[root@localhost my.Shells]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/redis latest 1e70071f4af4 6 weeks ago 106.7 MB
[root@localhost my.Shells]# docker pull nginx //Download nginx
Using default tag: latest
Trying to pull repository docker.io/library/nginx ... 
latest: Pulling from docker.io/library/nginx
e7bb522d92ff: Pull complete 
6edc05228666: Pull complete 
cd866a17e81f: Pull complete 
Digest: sha256:285b49d42c703fdf257d1e2422765c4ba9d3e37768d6ea83d7fe2043dad6e63d
[root@localhost my.Shells]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/nginx latest 3f8a4339aadd 3 weeks ago 108.5 MB
docker.io/redis latest 1e70071f4af4 6 weeks ago 106.7 MB

2. Run nginx

[root@localhost my.Shells]# docker run -p 8080:80 -d docker.io/nginx //Map port 80 to 8080, or 80:80 or the original port 80. It cannot be omitted.
c0462d5e18783e20f9515108fa62ab0f2ac808ea85370a7c82aee9407abf4672
[root@localhost my.Shells]# netstat -anp | grep 8080 //Port tcp6 is enabled 0 0 :::8080 :::* LISTEN 2529/docker-proxy-c 
[root@localhost my.Shells]# docker ps //nginx is already running CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c0462d5e1878 docker.io/nginx "nginx -g 'daemon off" 4 minutes ago Up 4 minutes 0.0.0.0:8080->80/tcp angry_mccarthy

3. Operation results

[root@localhost my.Shells]# ./openFirewallPort.sh //Open a port on the firewall first enter the port: 
success

---openFirewallPort.sh-------

 echo "enter the port: "
 read port
 firewall-cmd --add-port=$port/tcp

#The following image has been successfully accessed 

Notice:

When docker runs nginx, external access is still the IP address where docker is located, which is equivalent to nginx running on that machine.

But for the machine where docker is located, nginx is an image attached to docker. If you want to operate nginx, you can log in to the nginx container through docker and perform the operation.

The logged-in nginx container is a Linux system, but it only has nginx, which is installed according to the default Linux path. for example
root@c0462d5e1878:/usr/share/nginx/html# ls This path is the default static page storage path
50x.html index.html

The bash commands are the same, but vi cannot be used on my machine. However, commands such as cp and mv can be used because nginx is configured and cannot be changed.

1) Before logging into the nignx container, you can write the required files and copy them to the specified directory:

[root@localhost my.Shells]# docker cp hello.html c0462d5e1878://usr/share/nginx/html
[root@localhost my.Shells]# docker exec -it c0462d5e1878 bash
root@c0462d5e1878:/usr/share/nginx/html# ls
50x.html hello.html index.html

2) Mapping to container via host directory

docker run -p 80:80 -d -v $PWD/html:usr/share/nginx/html docker.io/nginx
-v $PWD/html:usr/share/nginx/html means mapping the html directory in the current path to usr/share/nginx/html

That is to say, the html under the host is usr/share/nginx/html under the container

Modifying and adding files in html is equivalent to file operations in the container usr/share/nginx/html

It can be accessed through the external network, so there is no need to log in to the container to operate the file

4. Stop the service

[root@localhost my.Shells]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c0462d5e1878 docker.io/nginx "nginx -g 'daemon off" 56 minutes ago Up 56 minutes 0.0.0.0:8080->80/tcp angry_mccarthy
[root@localhost my.Shells]# docker stop c0462d5e1878 
c0462d5e1878
[root@localhost my.Shells]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

5. Restart the service

[root@localhost my.Shells]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@localhost my.Shells]# docker start c0462d5e1878 
c0462d5e1878
[root@localhost my.Shells]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c0462d5e1878 docker.io/nginx "nginx -g 'daemon off" 59 minutes ago Up 12 seconds 0.0.0.0:8080->80/tcp angry_mccarthy

6. Open the same service again

[root@localhost my.Shells]# docker run -p 8081:80 -d docker.io/nginx 
//Open another service, port is 8081
1fd8a0b5d138203150f1cdbfb9690235159159881785a4654abb04c7c96c5b18
[root@localhost my.Shells]# docker ps //There will be two processes, one on 8080 and one on 8081
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1fd8a0b5d138 docker.io/nginx "nginx -g 'daemon off" 4 seconds ago Up 3 seconds 0.0.0.0:8081->80/tcp suspicious_hypatia
c0462d5e1878 docker.io/nginx "nginx -g 'daemon off" About an hour ago Up 4 minutes 0.0.0.0:8080->80/tcp angry_mccarthy 

The above picture accesses the newly started 8081 service. Note: The newly started service and the original service are two containers. The original hello.html is not in the new service.

7. Uninstall service

[root@localhost my.Shells]# docker ps //Both 8080 and 8081 are running CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1fd8a0b5d138 docker.io/nginx "nginx -g 'daemon off" 4 minutes ago Up 4 minutes 0.0.0.0:8081->80/tcp suspicious_hypatia
c0462d5e1878 docker.io/nginx "nginx -g 'daemon off" About an hour ago Up 8 minutes 0.0.0.0:8080->80/tcp angry_mccarthy
[root@localhost my.Shells]# docker stop 1fd8a0b5d138 //Stop 8081
1fd8a0b5d138
[root@localhost my.Shells]# docker ps //Only 8080 is still running CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c0462d5e1878 docker.io/nginx "nginx -g 'daemon off" About an hour ago Up 9 minutes 0.0.0.0:8080->80/tcp angry_mccarthy
[root@localhost my.Shells]# docker ps -a //You can see that 8080 is running and 8081 has Exited
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1fd8a0b5d138 docker.io/nginx "nginx -g 'daemon off" 5 minutes ago Exited (0) 7 seconds ago suspicious_hypatia
c0462d5e1878 docker.io/nginx "nginx -g 'daemon off" About an hour ago Up 9 minutes 0.0.0.0:8080->80/tcp angry_mccarthy
[root@localhost my.Shells]# 

[root@localhost my.Shells]# docker rm 1fd8a0b5d138 //Remove this process. Note that the running process cannot be rm, so stop it first
1fd8a0b5d138

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Docker builds Nginx+PHP+MySQL environment and deploys WordPress practice
  • How to deploy nginx with Docker and modify the configuration file
  • Docker for Beginners and Detailed Steps for Deploying NGINX
  • Docker nginx example method to deploy multiple projects
  • Docker deploys Nginx and configures reverse proxy
  • Try Docker+Nginx to deploy single page application method
  • Docker Nginx container production and deployment implementation method
  • How to deploy Nginx on Docker

<<:  Detailed explanation of the idea of ​​setting up login verification interception function in Vue

>>:  Introduction to HTML_PowerNode Java Academy

Recommend

Vue multi-page configuration details

Table of contents 1. The difference between multi...

Superficial Web Design

<br />I have always believed that Yahoo'...

MySQL password is correct but cannot log in locally -1045

MySQL password is correct but cannot log in local...

MySQL series 15 MySQL common configuration and performance stress test

1. Common MySQL configuration All the following c...

MySQL encryption and decryption examples

MySQL encryption and decryption examples Data enc...

js realizes horizontal and vertical sliders

Recently, when I was doing a practice project, I ...

Implementation of mounting NFS shared directory in Docker container

Previously, https://www.jb51.net/article/205922.h...

Detailed explanation of JavaScript to monitor route changes

Table of contents history pushState() Method push...

How to select all child elements and add styles to them in CSS

method: Take less in the actual project as an exa...

Import backup between mysql database and oracle database

Import the data exported from the Oracle database...

Installation tutorial of MySQL 5.1 and 5.7 under Linux

The operating system for the following content is...

Nginx configuration file detailed explanation and optimization suggestions guide

Table of contents 1. Overview 2. nginx.conf 1) Co...

A brief summary of my experience in writing HTML pages

It has been three or four months since I joined Wo...