A, docker mount installation and configuration nginx

First, make sure the state is already running state docker

systemctl status docker

And make sure the firewall is turned off (or ip and port configurations accessible)
(see fire state)

systemctl status firewalld  

(Turn off the firewall)

systemctl stop firewalld       
systemctl disable firewalld		

Here Insert Picture Description

Second, the installation Nginx
. 1, mirrored pull docker

docker search nginx

- What are the mirror image search nginx (tag is the official release, we pull the official Mirror)
Here Insert Picture Description
- pull Mirror

docker pull nginx 	

- View docker Mirror
Here Insert Picture Description

docker images 	

2, after installation to test selected 8081

[root@bogon ~]# docker run -di --name=nginx-test -p 8081:80 nginx

- View the container has up

[root@bogon ~]# docker ps       

Here Insert Picture Description

- accessed using a browser, ip: port
Here Insert Picture Description

3, the mount profile, regenerate vessel

-Create a directory

[root@bogon data]# mkdir -p /data/nginx/www  /data/nginx/logs  /data/nginx/conf

- enter the directory and view the directory created successfully

cd /data/nginx

Here Insert Picture Description

- copy the default profile to the container Nginx conf local directory of the current directory, the container ID may view the docker ps command input of the first column:

[root@bogon nginx]# docker cp 2b99a3d53ab4:/etc/nginx/nginx.conf /data/nginx/conf

Here Insert Picture Description

- use way to start the container mount directory

[root@bogon conf]# docker run -di -p 80:80 --name=nginx-pro -v /data/nginx/www:/usr/share/nginx/html -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v/data/nginx/logs:/var/log/nginx nginx

Parameter analysis:
Docker run: Create a container
-d: run behind the -d parameter will create a guard vessel in the background (this will not automatically logged container after container is created, if only two plus -i -t parameters, after you create will automatically go in the container).
-i: Run indicates a container
-p: mapping the port, the former is a host port, which is mapped in the port of the container. You can use multiple -p do more port mapping
-v: representing the directory mapping relationship (the former is the host directory, which is mapped to a directory on the host), you can use multiple -v do multiple directories or file mappings . Note: It is the directory for mapping, making changes on the host, and then to share the container.

- View has been created to

docker ps

Here Insert Picture Description

Access test:
Here Insert Picture Description

Since there is no place in the home, we create an index.html in / data / nginx / www / under

[root@bogon nginx]# vim /data/nginx/www/index.html

Here Insert Picture Description

Save and Exit
ESC: wq
visit:
Here Insert Picture Description

Into the log folder to see the log
[root @ bogon nginx] # cd / data / nginx / logs /
Here Insert Picture Description

carry out! ! !

Third, the ending.
Delete test container
1 - container to view the running

docker ps

Here Insert Picture Description

2, - stop the container

docker stop nginx-test

Here Insert Picture Description

3, - delete the test container

[root@bogon logs]# docker rm nginx-test

-view all

docker ps -a

Here Insert Picture Description

Well, then we only need to modify the configuration file mapping project under /data/nginx/nginx.conf can be.

Published 14 original articles · won praise 2 · Views 171

Guess you like

Origin blog.csdn.net/weixin_41402056/article/details/105079080