部署静态资源
docker run --name nginx-test -p 8080:80 -d nginx
运行下容器,查看nginx的安装位置
mkdir -p /opt/nginx/{conf,conf.d,html,logs}
本地创建挂载目录
docker cp 4ff3d4e08230:/etc/nginx/nginx.conf /opt/nginx/conf/
docker cp 4ff3d4e08230:/etc/nginx/conf.d/default.conf /opt/nginx/conf.d/
拷贝容器内的nginx配置文件到宿主机做挂载
docker run \
--name nginx8088 \
-d -p 8088:80 \
-v /opt/nginx/log:/var/log/nginx \
-v /opt/nginx/html:/usr/share/nginx/html \
-v /opt/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /opt/nginx/conf.d:/etc/nginx/conf.d \
nginx
sudo docker run --name nginx8102 -d -p 8102:80 -v /opt/nginx8102/log:/var/log/nginx -v /opt/nginx8102/html:/usr/share/nginx/html -v /opt/nginx8102/conf/nginx.conf:/etc/nginx/nginx.conf -v /opt/nginx8102/conf.d:/etc/nginx/conf.d b5390718bd8e
-v 是将:后面的容器内的文件挂载到宿主机上,也就是说用宿主机的配置来代替容器内的配置
将静态资源放到/opt/nginx/html目录下,就可以访问了
ip+8088端口
命令小记
docker compose来连接容器中间的信息
docker exec -it 775c7c9ee1e1 /bin/bash
进入容器内的命令
docker restart 2bce07635f37
重启容器,会保留之前启动的配置