部署Nginx
搜尋nginx映象
docker search nginx
拉取nginx映象
docker pull nginx
建立容器、設定埠對映、目錄對映
#在root目錄下建立nginx目錄用於儲存nginx資料資訊 mkdir ~/nginx cd ~/nginx mkdir conf cd conf #在~/nginx/conf/下建立nginx.conf檔案,貼上下面內容 vim nginx.conf
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] "$requesr" ' '$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
- 引數說明
- -p 80:80 將容器80埠對映到宿主機的80埠。
- -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf 將宿主機當前目錄下的/conf/nginx.conf/掛載到容器的/etc/nginx/nginx/conf。配置目錄
- -v $PWD/logs/var/log/nginx 將主機當前目錄下的logs目錄掛載到容器的/var/log/nginx。日誌目錄配置
- 使用外部機器訪問nginx
本作品採用《CC 協議》,轉載必須註明作者和本文連結