The method of installing Nginx under docker
I. Environmental description
Docker: 18.03.1-cenginx: 1.15.1
2. Pull the latest Nginx image
Pull the image
$docker pull nginx
View the current image
$docker images# query result: REPOSITORY TAG IMAGE ID CREATED SIZEnginx latest 8b89e48b5f15 7 hours ago 109MB
III. Preparatory work
This time, deploy the web service under / srv/web directory:
3.1 create the / srv/web directory and enter it
$cd / srv & & mkdir web & & cd web
Create a random Nginx container and copy the default configuration of Nginx:
Create a container:
$docker run-d-- name nginx nginx copy the configuration file from the container to the local: # View = > get the container ID$ docker container ls# create directory under the current directory: conf $mkdir conf# copy the Nginx default configuration file in the container to the local conf directory under the current directory $docker cp a89b2c5f3dd1:/etc/nginx/nginx.conf $PWD/conf delete container: # stop container $docker container stop a89b2c5f3dd1# delete container $docker container rm a89b2c5f3dd1
IV. Start formal deployment
Deployment commands:
$docker run-d-p 8081 PWD/html:/usr/share/nginx/html 80-- name nginx-web-6666-v $PWD/html:/usr/share/nginx/html-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf-v $PWD/logs:/var/log/nginx nginx command details:-d # indicates that the container has been running in the background-p 8081 PWD/html:/usr/share/nginx/html 80 # to map the port Map local port 8081 to port 80 inside the container-container name created by name # setting-v # mount local directory (file) to container specified directory
5. Testing
5.1 Test
opens if it is a local test deployment: localhost:8081 can access the web server
5.2 add:
mounts the root directory of the nginx in the container to the local specified directory, so the page visited above should report a 403 error. Next, we can start our project at / srv/web/html/.
5.3 enter the local directory: / srv/web/html/ to create the test file index.html
$cd / srv/web/html# create and randomly write content to refresh the page $vim index.html
Summary
The above is the method of installing Nginx under docker introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave a message for me, and the editor will reply you in time. Thank you very much for your support to the website!