Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Docker detailed steps for installing Nginx

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "Docker installation Nginx detailed steps", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's take you to learn the detailed steps of Docker installation of Nginx!

Docker Installation Nginxdocker pull nginx Command Installation

Find nginx images on Docker Hub

runoob@runoob:~/nginx$ docker search nginxNAME DESCRIPTION STARS OFFICIAL AUTOMATEDnginx Official build of Nginx. 3260 [OK] jwilder/nginx-proxy Automated Nginx reverse proxy for docker c... 674 [OK]richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable ... 207 [OK]million12/nginx-php Nginx + PHP-FPM 5.5, 5.6, 7.0 (NG), CentOS... 67 [OK]maxexcloo/nginx-php Docker framework container with Nginx and ... 57 [OK]...

Here we pull the official mirror image

$ docker pull nginx

After waiting for the download to complete, we can find the REPOSITORY image for nginx in the local mirror list.

runoob@runoob:~/nginx$ docker images nginxREPOSITORY TAG IMAGE ID CREATED SIZEnginx latest 555bbd91e13c 3 days ago 182.8 MB

The following command starts an instance of an Nginx container using NGINX default configuration:

$ docker run --name runoob-nginx-test -p 8081:80 -d nginx

runoob-nginx-test container name.

The -d Settings container runs in the background.

The -p port maps local port 8081 to port 80 inside the container.

Executing the above command will generate a string like 6dd4380ba70820bd2acc55ed2b326dd8c0ac7c93f68f0067daecad82aef5f938, which represents the ID of the container and is usually used as the file name of the log.

We can use docker ps command to see if the container is running:

$ docker psCONTAINER ID IMAGE ... PORTS NAMES6dd4380ba708 nginx ... 0.0.0.0:8081->80/tcp runoob-nginx-test

The PORTS section indicates port mapping, where local port 8081 maps to port 80 inside the container.

Open http://127.0.0.1:8081/in your browser and the effect is as follows:

nginx deployment

First, create the directory nginx, which is used to store the following related things.

$ mkdir -p ~/nginx/www ~/nginx/logs ~/nginx/conf

Copy the Nginx default configuration file in the container to the conf directory under the local current directory. The container ID can be viewed in the first column of the docker ps command input:

docker cp 6dd4380ba708:/etc/nginx/nginx.conf ~/nginx/conf

The www: directory maps to the virtual directory of the nginx container configuration.

logs: directory maps to the logs directory of the nginx container.

The configuration files in the conf: directory are mapped to the configuration files of the nginx container.

Ministry Order $ docker run -d -p 8082:80 --name runoob-nginx-test-web -v ~/nginx/www:/usr/share/nginx/html -v ~/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v ~/nginx/logs:/var/log/nginx

Command Description:

-p 8082:80: Map port 80 of the container to port 8082 of the host.

--name runoob-nginx-test-web: Name the container runoob-nginx-test-web.

-v ~/nginx/www:/usr/share/nginx/html: Mount our own www directory to the container's/usr/share/nginx/html.

-v ~/nginx/conf/nginx.conf:/etc/nginx/nginx.conf: Mount our own nginx.conf to the container's/etc/nginx/nginx.conf.

-v ~/nginx/logs:/var/log/nginx: Mount our own logs to the container's/var/log/nginx.

Start the above command and enter ~/nginx/www directory:

$ cd ~/nginx/www

Create an index.html file with the following content:

Rookie tutorial (runoob.com) My first title.

My first paragraph.

The output is:

related commands

If you want to reload NGINX, you can send the HUP signal to the container using the following command:

$ docker kill -s HUP container-name

Restart NGINX container command:

$ docker restart container-name At this point, I believe that everyone has a deeper understanding of the "Docker installation Nginx detailed steps", may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report