Use Vue.js + Docker deployment project with me.

Learn from this article: https://juejin.im/post/5bee5ddde51d457b8a33938c
project environment is under ubuntu, remember to be in the root directory, otherwise the installation will complain vue

npm install -g vue-cli
vue init webpack demo01
cd demo01
npm run dev


Detailed dockerfile profiling
base image node, and a mounting nginx.
Node the FROM: Slim. 8-
the RUN APT-GET Update the install && APT-GET -Y Nginx
create the directory / usr / src / app in the mirror and enters the directory. Used to temporarily store the item code.

FROM node:8-slim
RUN apt-get update  && apt-get install -y nginx

Create a directory / usr / src / app in the mirror and into the directory. Used to temporarily store the item code.

WORKDIR /usr/src/app

Download node-dependent.

# 拷贝三个依赖相关的json文件到 "/usr/src/app" 目录下

COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]

# 下载依赖
RUN npm install

Copy all the files to the project / under usr / src / app directory. (This is an alternative to downloading dependencies, and then copy all the files in the project to the mirror.)

COPY . .

Run the Package command

RUN npm run build

The nginx logs soft connection to the standard output and standard error. This view nginx log by docker logs.

RUN ln -sf /dev/stdout /var/log/nginx/access.log \
    && ln -sf /dev/stderr /var/log/nginx/error.log
EXPOSE 80

File after moving to the next package of html directory nginx. And project source files removed (not used, only the static files to the package).

RUN cp -r dist/* /var/www/html \
    && rm -rf /user/src/app

Configuration project start command. -g 'daemon off;' configuration parameters will cause nginx foreground, if running in the background, docker vessel will exit.

CMD ["nginx","-g","daemon off;"]

Deployed
to move the item to the system deployment (to linux for example), and enter into the project root directory.

The project packaged into docker mirror. Mirroring the name demo, version 1.0

docker build -t demo:1.0 .

-t <image name>: <version>

Create a container and run. Here is nginx-proxy proxy. Directly open <domain name> to access.

docker run -d -p 80 -e VIRTUAL_HOST=<域名> demo:1.0

Note the port number here, otherwise you will get an error


# 可以开多个容器。nginx-proxy会自动配置负载均衡
docker run -d -p 80 -e VIRTUAL_HOST=<域名> demo:1.0

Guess you like

Origin www.cnblogs.com/smart-girl/p/11512952.html