1. 创建目录
mkdir -p /usr/local/nginx/conf
mkdir -p /usr/local/nginx/www
2. 创建配置文件
touch /usr/local/nginx/conf/nginx.conf
在nginx.conf文件添加如下配置
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://www.baidu.cn/;
}
# axios 跨域配置
location /api {
proxy_pass http:/localhost:8080;
}
# FastDFS 工作目录映射
location /group1/M00{
alias /data/fastdfs/store_path/data;
}
# MinIO 工作目录映射
location /avatar{
alias /data/minio/data/avatar;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
3. 拉取镜像
docker pull nginx
查看镜像
docker images
4. 创建容器并启动
docker run -it -d --name nginx -p 80:80 -v /usr/local/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /usr/local/nginx/www:/home/nginx/www nginx
两个-v 分别表示配置文件和nginx工作空间目录的映射,冒号左边是宿主机,右边是容器的,这样修改宿主机的配置文件和工作空间就可以同步到容器
5. 查看容器
docker ps -a
6. 查看nginx启动日志
docker logs nginx
7. 启动、关闭、重启nginx
docker start nginx
docker stop nginx
docker restart nginx
原文:https://www.cnblogs.com/fly4j/p/13591429.html