Docker安装Nginx
创建本地文件夹
mkdir -p /root/nginx/www /root/nginx/logs /root/nginx/conf
创建容器
docker run -p 80:80 --name nginx \
-v ~/nginx/html:/usr/share/nginx/html \
-v ~/nginx/nginx.conf:/etc/nginx/nginx.conf \
-v ~/nginx/conf.d:/etc/nginx/conf.d \
-v ~/nginx/logs:/var/log/nginx \
-d nginx
复制Nginx配置
docker cp nginx:/etc/nginx/nginx.conf /root/nginx/conf
在本机www目录下创建index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>docker搭建nginx</title>
</head>
<body>
<h1>docker搭建nginx映射成功</h1>
<p>test</p>
</body>
</html>
Docker-compose.yaml
version: "3.9"
services:
web:
image: nginx
container_name: nginx
restart: always
ports:
- 80:80
volumes:
- /usr/local/docker/mysql/conf:/etc/mysql
- /usr/local/docker/mysql/logs:/var/log/mysql
- /usr/local/docker/mysql/data:/var/lib/mysql
评论区