1、nginx配置,命名为default.conf

  1. server {
  2. listen 8999;
  3. server_name localhost;
  4. #charset koi8-r;
  5. #access_log logs/host.access.log main;
  6. location / {
  7. root /usr/share/nginx/html;
  8. index index.html index.htm;
  9. }
  10. location /wcs{
  11. proxy_pass http://192.168.1.124:30664;
  12. rewrite ^/wcs/(.*)$ /$1 break;
  13. proxy_set_header Host $host;
  14. proxy_set_header x-forwarded-for $remote_addr;
  15. proxy_set_header X-Real-IP $remote_addr;
  16. proxy_redirect off;
  17. }
  18. location /task{
  19. proxy_pass http://192.168.1.124:30440;
  20. rewrite ^/task/(.*)$ /$1 break;
  21. proxy_set_header Host $host;
  22. proxy_set_header x-forwarded-for $remote_addr;
  23. proxy_set_header X-Real-IP $remote_addr;
  24. proxy_redirect off;
  25. }
  26. }

2、Dockerfile文件编写如下

  1. FROM nginx:latest
  2. COPY default.conf /etc/nginx/conf.d/default.conf
  3. COPY dist /usr/share/nginx/html

dist文件夹default.conf和Dockerfile文件都要在同一级目录

3、编译docker镜像(进入Dockerfile同级目录)

  1. docker build -t <镜像名称> -f Dockerfile .

如:

  1. [root@localhost front]# docker build -t wcs400:v1 -f Dockerfile .
  2. Sending build context to Docker daemon 9.062MB
  3. Step 1/3 : FROM nginx:latest
  4. ---> c316d5a335a5
  5. Step 2/3 : COPY default.conf /etc/nginx/conf.d/default.conf
  6. ---> 37becc1d8b18
  7. Step 3/3 : COPY dist /usr/share/nginx/html
  8. ---> f22c76f0928b
  9. Successfully built f22c76f0928b
  10. Successfully tagged wcs400:v1

4、查看镜像是否创建成功

  1. [root@localhost front]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. wcs400 v1 f22c76f0928b 54 seconds ago 151MB

5、运行

  1. [root@localhost front]# docker run --name wcs400 -it -d -p 8999:8999 --restart=always wcs400:v1

6、查看是否运行成功

  1. [root@localhost front]# docker ps
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. fb62e8058095 wcs400:v1 "/docker-entrypoint.…" 32 seconds ago Up 15 seconds 80/tcp, 0.0.0.0:8999->8999/tcp, :::8999->8999/tcp wcs400