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
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)
- pull Mirror
docker pull nginx
- View docker Mirror
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
- accessed using a browser, ip: port
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
- 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
- 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
Access test:
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
Save and Exit
ESC: wq
visit:
Into the log folder to see the log
[root @ bogon nginx] # cd / data / nginx / logs /
carry out! ! !
Third, the ending.
Delete test container
1 - container to view the running
docker ps
2, - stop the container
docker stop nginx-test
3, - delete the test container
[root@bogon logs]# docker rm nginx-test
-view all
docker ps -a
Well, then we only need to modify the configuration file mapping project under /data/nginx/nginx.conf can be.