[root@localhost docker]# docker search nginx NAME DEscriptION STARS二、拉取镜像至本地
如拉取最新版本至本地
docker pull nginx
也可以指定版本号,不加版本号默认获取最新版本,也可以使用 docker search nginx查看镜像来源
docker pull nginx:6.2.5
三、查看本地镜像
[root@localhost docker]# docker images | grep nginx四、安装 1、简单安装
可以使用以下命令来运行 nginx 容器:
$ docker run --name nginx-test -p 8080:80 -d nginx
参数说明:
–name nginx-test:容器名称。
-p 8080:80: 端口进行映射,将本地 8080 端口映射到容器内部的 80 端口。
-d nginx: 设置容器在在后台一直运行。
新建宿主机文件存储目录:
创建nginx的数据存储和配置文件目录
mkdir -p /deploy/nginx/{conf,logs,html}
将第一步简单安装的文件夹复制到指定目录
然后按需编辑nginx相关的配置文件
如编辑conf.d的default.conf文件
upstream gateway{ server 192.168.0.232:9999; server 10.10.26.34:9999; } server { listen 80; listen [::]:80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; #For WebSocket upgrade header proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; # 静态文件映射 root /usr/share/nginx/html; # 访问路径代理 location ~* ^/(auth|code|upms|gen|weixin|mall|payapi|doc|webjars|swagger-resources) { proxy_pass http://gateway; #proxy_set_header Host $http_host; proxy_connect_timeout 60s; proxy_send_timeout 300s; proxy_read_timeout 300s; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location = /index.html { root /usr/share/nginx/html; add_header Cache-Control "no-cache, no-store"; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ .php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ .php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param script_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /.ht { # deny all; #} }
启动容器
docker run --restart=always --name nginx -d -p 9909:8 0 -v /deploy/nginx/html:/usr/share/nginx/html -v /deploy/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /deploy/nginx/conf.d:/etc/nginx/conf.d -v /deploy/nginx/logs:/var/log/nginx nginx
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)