1、nginx配置,命名为default.conf
server {
listen 8999;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /wcs{
proxy_pass http://192.168.1.124:30664;
rewrite ^/wcs/(.*)$ /$1 break;
proxy_set_header Host $host;
proxy_set_header x-forwarded-for $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
}
location /task{
proxy_pass http://192.168.1.124:30440;
rewrite ^/task/(.*)$ /$1 break;
proxy_set_header Host $host;
proxy_set_header x-forwarded-for $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
}
}
2、Dockerfile文件编写如下
FROM nginx:latest
COPY default.conf /etc/nginx/conf.d/default.conf
COPY dist /usr/share/nginx/html
dist文件夹default.conf和Dockerfile文件都要在同一级目录
3、编译docker镜像(进入Dockerfile同级目录)
docker build -t <镜像名称> -f Dockerfile .
如:
[root@localhost front]# docker build -t wcs400:v1 -f Dockerfile .
Sending build context to Docker daemon 9.062MB
Step 1/3 : FROM nginx:latest
---> c316d5a335a5
Step 2/3 : COPY default.conf /etc/nginx/conf.d/default.conf
---> 37becc1d8b18
Step 3/3 : COPY dist /usr/share/nginx/html
---> f22c76f0928b
Successfully built f22c76f0928b
Successfully tagged wcs400:v1
4、查看镜像是否创建成功
[root@localhost front]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
wcs400 v1 f22c76f0928b 54 seconds ago 151MB
5、运行
[root@localhost front]# docker run --name wcs400 -it -d -p 8999:8999 --restart=always wcs400:v1
6、查看是否运行成功
[root@localhost front]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fb62e8058095 wcs400:v1 "/docker-entrypoint.…" 32 seconds ago Up 15 seconds 80/tcp, 0.0.0.0:8999->8999/tcp, :::8999->8999/tcp wcs400