These two days I have studied the Docker deployment vue+ Express +mongodb project, and briefly made a small example to review.

First, deploy vUE

Packaging vue

The first step is to package the completed VUE project:

npm build
Copy the code

default.conf

Add the default.conf file to the root directory

server {
    listen       80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html { root /usr/share/nginx/html; }}Copy the code

Dockerfile

FROM nginx
COPY dist/ /usr/share/nginx/html/
COPY ./default.conf /etc/nginx/conf.d/default.conf
Copy the code

Build a VUE image

docker build -t zhihu/portal .
Copy the code

Boot image

docker run -p 3000:80 -d --name zhihu-mcn-portal zhihu/portal
Copy the code

2. Deploy Express +mongodb

Add the.dockerignore file

node_modules
npm-debug.log
Copy the code

Add the Dockerfile file

FROM node:10.15.3

LABEL maintainer="[email protected]"

COPY . /app

WORKDIR /app

RUN npm install

RUN ls

RUN npm install --registry=https://registry.npm.taobao.org

RUN ls

EXPOSE 3981

CMD [ "npm"."start" ]
Copy the code

Add the docker-comemage. yml file

version: "3" # version
services:
  app: 
    container_name: service # container name
    restart: on-failure Restart mode
    build: ./ Build the dockerfile directory
    ports: # Exposed port
      - "3981:3981"
    # volumes:
    # - .:/app
    links: # dependency container
      - mongo
  mongo:
    container_name: mongo
    image: mongo:4.0.8 # dependency mirror
    volumes: 
      - ~/mongo/db:/data/db # Data mount
    ports:
      - "27017:27017"
Copy the code

Modifying the env File

MONGODB_URL=mongodb://localhost:27017/ service to MONGODB_URL = mongo: / / mongo:27017/service
Copy the code

perform

docker-compose up -d
Copy the code