docker-compose of docker deployment backend egg.js

The last chapter is to deploy eggs through Dockerfile.

This chapter is to build and deploy egg.js through docker-compose.

Create a new docker-compose.yml file

version: "3.8"
 
services:
  #myegg是容器名称
  myegg:
    #通过build构建镜像
    build:
      context: ./myegg  #构建的文件夹./myegg  context意思是要的build的目录
      dockerfile: Dockerfile  # Dockerfile的名字
    image: myegg:latest  #镜像的名称
    ports:
      - 7001:7001

have to be aware of is:

The docker-compose.yml file cannot be placed under the egg project folder, otherwise the deployment will fail.

The following is my Alibaba Cloud directory:

 myegg and docker-compose.yml should be in the same directory.

input the command

docker-compose build

In fact, the meaning of the docker-compose.yml file is to read the Dockerfile file through the code, and automatically build the image and open the container for you. It saves you to build the image yourself, and it is easy to run.

Now docker-compose is successful. Restart, -d background start

docker-compose up -d

 The status of the docker-compose ps command is up, and the image mirror and container container are built for you

 Open the browser: ip address + port number

Next time, I want to join mysql redis together. 

Guess you like

Origin blog.csdn.net/deng_zhihao692817/article/details/129629848