Docker 部署 Nginx
Docker Nginx DevOps About 1,591 words搜索镜像
docker search nginx
拉取镜像
版本号可以去官网查看:https://hub.docker.com/_/nginx
docker pull nginx:1.20.2
创建目录
mkdir ~/nginx
cd ~/nginx
mkdir conf
cd conf
vim nginx.conf
nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
端口配置
server {
listen 80;
location / {
root html;
index index.html index.htm;
}
}
创建容器
-p 80:80
:冒号前的80
是宿主机端口,冒号后的80
是容器端口。
docker run -d \
--name=nginx \
-p 80:80 \
-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf \
-v $PWD/conf/conf.d:/etc/nginx/conf.d \
-v $PWD/logs:/var/log/nginx \
-v $PWD/html:/usr/share/nginx/html \
nginx:1.20.2
不指定配置(快速测试用)
docker run -d \
--name=nginx \
-p 80:80 \
-v $PWD/conf.d:/etc/nginx/conf.d \
-v $PWD/logs:/var/log/nginx \
-v $PWD/html:/usr/share/nginx/html \
nginx:1.20.2
可能出现的错误
WARNING: IPv4 forwarding is disabled. Networking will not work.
开启ipv4
转发
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
systemctl restart network
进入容器
docker exec -it c_nginx bash
重启
docker exec -it nginx nginx -s reload
Views: 1,836 · Posted: 2022-02-02
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...