Docker application deployment---nginx deployment configuration

1. Search for nginx mirror

docker search nginx

2. Pull nginx image

docker pull nginx

3. Create a container and set port mapping and directory mapping

# 在/root目录下创建nginx目录用于存储nginx数据信息
mkdir ~/nginx
cd ~/nginx
mkdir conf
cd conf
# 在~/nginx/conf/下创建nginx.conf文件,粘贴下面内容
vim nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    
    
    worker_connections  1024;
}


http {
    
    
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

Switch to the nignx directory, otherwise some relative paths will go wrong.

docker run -id --name=c_nginx \
-p 80:80 \
-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf \
-v $PWD/logs:/var/log/nginx \
-v $PWD/html:/usr/share/nginx/html \
nginx

● Parameter description:
○ -p 80:80: Map port 80 of the container to port 80 of the host.
○ -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf: Mount /conf/nginx.conf in the current directory of the host to:/etc of the container /nginx/nginx.conf. Configuration directory
○ -v $PWD/logs:/var/log/nginx: Mount the logs directory in the current directory of the host to /var/log/nginx of the container. Log Directory

4. Create a test page index

cd ~/nginx/html
vim index.html
<h1>hello docker nginx</h1>

5. Access nginx using an external machine

Insert image description here

Guess you like

Origin blog.csdn.net/m0_63622279/article/details/134084313