启动普通的nginx创建目录文件然后删除
//启动容器 docker run -p 10080:80 --name mynginx -d nginx //进入容器 docker exec -it mynginx bash //查看nginx目录 ls -al /etc/nginx //退出容器复制mynginx容器中/etc/nginx下的文件到当前目录 exit docker cp mynginx:/etc/nginx/nginx.conf . docker cp mynginx:/etc/nginx/conf.d . docker cp mynginx:/usr/share/nginx/html . //删除容器 docker stop mynginx && docker rm mynginx
创建docker-compose文件
cat > docker-compose.yaml << EOF version: '3' services: nginx: container_name: nginx image: nginx restart: always ports: - 11080:80 privileged: true volumes: - /etc/localtime:/etc/localtime:ro - ./conf/nginx/log/:/var/log/nginx # 注意:如下挂载都是覆盖 #- ./conf/nginx/conf.d:/etc/nginx/conf.d #- ./conf/nginx/nginx.conf:/etc/nginx/nginx.conf:ro #- ./conf/nginx/html:/usr/share/nginx/html EOF
在当前目录启动nginx
docker-compose up -d
访问测试
ip:11080/index.html
原创文章,作者:,如若转载,请注明出处:https://blog.ytso.com/274331.html