注:项目根目录为vue项目下 有package.json目录
一、进入项目根目录创建DockerFile文件
FROM nginx
MAINTAINER arkj
RUN rm /etc/nginx/conf.d/default.conf
ADD default.conf /etc/nginx/conf.d/
COPY dist/ /usr/share/nginx/html/
二、在项目根目录创建default.conf文件
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
三、根目录 执行命令
docker build -f Dockerfile -t 镜像名 .
[+] Building 3.3s (10/10) FINISHED docker:desktop-linux
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 189B 0.0s
=> [internal] load metadata for docker.io/library/nginx:latest 2.4s
=> [auth] library/nginx:pull token for registry-1.docker.io 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> CACHED [1/4] FROM docker.io/library/nginx:latest@sha256:447a8665cc1dab95b1ca778e162215839ccbb9189104 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 735B 0.0s
=> [2/4] RUN rm /etc/nginx/conf.d/default.conf 0.4s
=> [3/4] ADD default.conf /etc/nginx/conf.d/ 0.1s
=> [4/4] COPY dist/ /usr/share/nginx/html/ 0.1s
=> exporting to image 0.1s
=> => exporting layers 0.1s
=> => writing image sha256:cd37f4ff72f21ee075d80c342f8de129d32e952183fede50b6b9d27385a10db0 0.0s
=> => naming to docker.io/library/arkj
writing image sha256:后为镜像id
docker run -d -p 映射端口:80 --name 容器名 镜像名