This article to share the content is about Docker under how to install Nginx environment detailed process, the content is very detailed, the need for friends can refer to, hope can help you.
I. Environmental description
Docker:18.03.1-ce
nginx:1.15.1
Second, pull up the latest Nginx image
$ Docker Pull Nginx
$ docker images# Query result: REPOSITORY TAG IMAGE ID CREATED sizenginx latest 8b89e48b5f15 7 Hours ago 109MB
Iii. preparatory work
This time you deploy the Web service under the/srv/web directory:
3.1 Create the/srv/web directory and enter the directory
$ cd/srv && mkdir Web && CD Web
3.2 Create an nginx container and copy the default configuration of Nginx:
$ docker run-d--name Nginx
# view ==> get container id$ Docker container ls# Create directory under current directory: Conf $ mkdir conf# copy container Nginx default profile to local current directory conf directory $ docker CP a89b 2c5f3dd1:/etc/nginx/nginx.conf $PWD/conf
# Stop container $ docker container Stop a89b2c5f3dd1# Remove container $ docker container RM a89b2c5f3dd1
Iv. start of formal deployment
$ docker run-d-P 8081:80--name nginx-web-6666-v $PWD/html:/usr/share/nginx/html-v $PWD/conf/nginx.conf:/etc/nginx/ng Inx.conf-v $PWD/logs:/var/log/nginx Nginx
-D # indicates that the container is running in the background,-P 8,081:80 # Mapping the port, mapping the local 8081 port to the 80 port inside the container--name # setting creates the container name-V # mounts The local directory (file) to the container-specified directory;
V. Testing
5.1 Testing
If the local test deployment is open: localhost:8081 can access the Web server;
5.2 Supplement:
Because it is to mount the root directory of the nginx inside the container to the local designated directory, so the above page should be reported 403 error, the next can be /srv/web/html/
started in our project;
5.3 Go to local directory:/srv/web/html/Create test file index.html
$ cd/srv/web/html# Create and re-refresh pages with whatever content you want vim index.html