docker pull nginxhtml |
docker run -di --name=nginx -p 80:80 nginx/bin/bashnginx |
瀏覽器地址欄輸入: Linux系統ipdocker
官方的nginx鏡像,nginx配置文件nginx.conf 在/etc/nginx/目錄下。瀏覽器
在容器內編輯配置文件不方便,咱們能夠先將配置文件從容器內拷貝到宿主機,編輯修改後再拷貝回去。tomcat
(1)從容器拷貝配置文件到宿主機bash
docker cp nginx:/etc/nginx/nginx.conf nginx.confapp |
(2)編輯nginx.conf,添加反向代理配置(將以前部署tomcat反向代理到nginx的80端口,172.17.0.4:8080是tomcat的ip,須要用docker inspect tomcat查看)tcp
user nginx;測試 worker_processes 1;spa error_log /var/log/nginx/error.log warn;
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' access_log /var/log/nginx/access.log main; sendfile on; keepalive_timeout 65; #gzip on;
include /etc/nginx/conf.d/*.conf; |
(3)將修改後的配置文件拷貝到容器
docker cp nginx.conf nginx:/etc/nginx/nginx.conf |
(4)從新啓動容器
docker restart nginx |
瀏覽器測試:Linux系統ip