查看Nginx镜像并拉取镜像:
[root@localhost nginx]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 18730 [OK]
unit Official build of NGINX Unit: Universal Web … 6 [OK]
nginxproxy/nginx-proxy Automated Nginx reverse proxy for docker con… 92
nginxproxy/acme-companion Automated ACME SSL certificate generation fo… 116
bitnami/nginx Bitnami nginx Docker Image 168 [OK]
bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Contr… 29 [OK]
ubuntu/nginx Nginx, a high-performance reverse proxy & we… 96
nginxproxy/docker-gen Generate files from docker container meta-da… 12
kasmweb/nginx An Nginx image based off nginx:alpine and in… 6
rancher/nginx-ingress-controller 11
rancher/nginx-ingress-controller-defaultbackend 2
bitnami/nginx-exporter 5
rancher/nginx 2
rapidfort/nginx-ib RapidFort optimized, hardened image for NGIN… 10
rapidfort/nginx RapidFort optimized, hardened image for NGINX 14
vmware/nginx-photon 1
rapidfort/nginx-official RapidFort optimized, hardened image for NGIN… 10
nginxproxy/forego Foreman in Go 0
vmware/nginx 2
rancher/nginx-conf 0
linuxserver/nginx An Nginx container, brought to you by LinuxS… 203
bitnamicharts/nginx 0
privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al… 76 [OK]
elestio/nginx-auto-ssl The simpliest solution to add SSL cert to yo… 0
rancher/nginx-ssl 0
[root@localhost nginx]# docker pull nginx
查看拉取镜像:
[root@localhost nginx]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mongo latest 1f3d6ec739d8 3 days ago 654MB
nginx latest 021283c8eb95 3 days ago 187MB
先启动Nginx,目的是提取配置文件等
docker run --name my-nginx -p 80:80 -d nginx
创建存放数据的文件目录
mkdir -p /root/nginx/html /root/nginx/conf /root/nginx/logs
将 nginx 容器内数据复制到存放数据的文件目录
docker cp my-nginx:/etc/nginx/nginx.conf /root/nginx
docker cp my-nginx:/etc/nginx/conf.d/default.conf /root/nginx/conf
然后停止 nginx 并删除容器
docker stop my-nginx
docker rm my-nginx
重新开启 nginx 容器,挂载目录:
docker run --privileged=true -e TZ="Asia/Shanghai" -it -d --name my-nginx -p 1888:80 -v /root/nginx/html:/usr/share/nginx/html -v /root/nginx/nginx.conf:/etc/nginx/nginx.conf -v /root/nginx/conf/default.conf:/etc/nginx/conf.d/default.conf -v /root/nginx/logs:/var/log/nginx nginx
配置Nninx COnfig如下:
[root@localhost nginx]# pwd
/root/nginx
[root@localhost nginx]# cat 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;
upstream powerjob{
server 192.168.56.1:8800; #转发主机的PowerJob调度器1
server 192.168.56.1:7700; #转发主机的PowerJob调度器2
}
server {
listen 80;
server_name nginx.****.com;
location / {
#转发到负载服务上
proxy_pass http://powerjob;
}
}
include /etc/nginx/conf.d/*.conf;
}
部署完成查看访问效果: