Detailed procedures for how to install nginx environments under Docker

Source: Internet
Author: User
Tags docker cp docker run
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

    • Pull Mirror

$ Docker Pull Nginx
    • View current Mirror

$ 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:

    • To create a container:

$ docker run-d--name Nginx
    • Copy the configuration file from the container to the Local:

# 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
    • To delete a container:

# Stop container $ docker container Stop a89b2c5f3dd1# Remove container $ docker container RM a89b2c5f3dd1

Iv. start of formal deployment

    • Deployment command:

$ 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
    • Command Detailed Description:

-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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.