三考杉、部署Nginx
- 搜索nginx鏡像
docker search nginx
- 拉取nginx鏡像
docker pull nginx
- 創(chuàng)建容器袋哼,設(shè)置端口映射逐抑、目錄映射
# 在/root目錄下創(chuàng)建nginx目錄用于存儲(chǔ)nginx數(shù)據(jù)信息
mkdir ~/nginx
cd ~/nginx
mkdir conf
cd conf
# 在~/nginx/conf/下創(chuàng)建nginx.conf文件,粘貼下面內(nèi)容
vim nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
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;
}
docker run -id --name=c_nginx \
-p 80:80 \
-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf \
-v $PWD/logs:/var/log/nginx \
-v $PWD/html:/usr/share/nginx/html \
nginx
- 參數(shù)說明:
-
-p 80:80:將容器的 80端口映射到宿主機(jī)的 80 端口膏燕。
-
-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf:將主機(jī)當(dāng)前目錄下的 /conf/nginx.conf 掛載到容器的 :/etc/nginx/nginx.conf钥屈。配置目錄
-
-v $PWD/logs:/var/log/nginx:將主機(jī)當(dāng)前目錄下的 logs 目錄掛載到容器的/var/log/nginx。日志目錄
- 使用外部機(jī)器訪問nginx