Docker installs Redis and Nginx

Docker installs Redis and Nginx

1. Docker install redis

1. Pull the image

docker pull redis:6.2.7

2. Create and upload redis configuration files and modify redis configuration files

# 允许远程访问
#bind 127.0.0.1 -::1
bind 0.0.0.0

# 关闭保护模式    
#protected-mode yes
protected-mode no

# 关闭后台启动模式
daemonize no

3. Create a container

docker run -p 6379:6379 --name=redis --privileged=true -v /usr/local/redis/redis.conf:/etc/redis/redis.conf -v /usr/local/redis/data:/data -d redis:6.2.7 redis-server /etc/redis/redis.conf
# docker run -p 6379:6379 --name=redis   启动动容器、设置端口映射6379、容器名称redis
# -v /usr/local/redis/redis.conf:/etc/redis/redis.conf   添加的配置文件和容器中的配置文件双向绑定
# -v /usr/local/redis/data:/data                         外部文件和容器数据文件进行绑定
# redis-server /etc/redis/redis.conf                     使用配置文件启动

4. View the remote tool to connect to redis and test it

2. Install nginx

1. Pull the image

docker pull nginx

2. Start the container

docker run --name nginx -p:80:80 -v /docker/conf/nginx.conf:/etc/nginx/nginx.conf -d nginx
# docker run --name nginx -p:80:80 启动容器、80端口映射、容器名称nginx
# -v /docker/conf/nginx.conf:/etc/nginx/nginx.conf    自己添加的配置文件和容器中的配置文件进行绑定

3. Configuration file

#user  nobody;
worker_processes  1;

events {
    worker_connections  1024;
}


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

    sendfile        on;


    server {
        listen       80;
        server_name  192.168.31.128;
        location / {
		    proxy_pass http://192.168.31.128:8080;
            root   html;
            index  index.html index.htm;
        }
       
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

Note: My test setting localhost proxy does not take effect, you need to set the specified ip address

The above configuration can access tomcat through nginx. If there is no tomcat, how to access the nginx page?
Let's look at the operation:

1. Create a data volume

# 创建挂载目录
mkdir -p /root/nginx/conf  /root/nginx/log  /root/nginx/html

2. Add the configuration file
nginx.conf

#user  nobody;
worker_processes  1;

events {
    worker_connections  1024;
}

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

    sendfile        on;

    server {
        listen       80;
        server_name  192.168.31.134;
        
        location / {
            root   /usr/share/nginx/html;   //访问的html 
            index  index.html index.htm;
        }
        
        error_page   500 502 503 504  /50x.html;
        location = /50x.html { 
            root   /usr/share/nginx/html;   // 访问的html         
        }
    }
}

Need to modify the html file under the root directory
Add the html directory under the html folder directory, store index.html yem
3, start the nginx command

docker run -itd --net host --name nginx80 -v /root/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /root/nginx/log:/var/log/nginx -v /root/nginx/html:/usr/share/nginx/html nginx

4. Browser access

image-20230705104327496

Guess you like

Origin blog.csdn.net/hekai7217/article/details/128877368