目录
一、搜索镜像
linux
docker search docker-0.unsee.tech/nginx:1.14.2
二、拉取镜像
linux
docker pull nginx:1.14.2
三、创建本地挂载目录
linux
mkdir -p /root/nginx/{conf,html,log}
四、编写nginx配置文件
需要注意的是,这里的root
目录一定要写/usr/share/nginx/html
否则找不到
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 192.168.98.129;
charset utf-8;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
五、启动容器
linux
docker run -d --name nginx -p 80:80 \
--restart=unless-stopped \
-v /root/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /root/nginx/html:/usr/share/nginx/html \
-v /root/nginx/log:/var/log/nginx \
--network 网络名称 \
nginx:1.14.2