As a result of their own idle demo server was invaded, into a mining machine. With this in mind, the server is blocked and ready for redeployment.

However, the old way of installing Postgres one by one, deploying the Golang API, and deploying Nginx to run Angular is a bit annoying. So a few days ago, I took a look at docker-compose for one-click deployment of a project.

The first step:

Install the docker – compose

root@hrgdrc:~/project# curl -sSL https://get.daocloud.io/docker | sh root@hrgdrc:/home# curl -L https://get.daocloud.io/docker/compose/releases/download/1.28.4/docker-compose- ` ` uname - s - ` uname -m ` - o /usr/local/bin/docker-compose root@hrgdrc:/usr/local/bin# chmod +x docker-composeCopy the code

Then create a directory to hold the files

➜ docker-hr git:(main) cat Dockerfile FROM golang:alpine RUN set -eux && sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories RUN apk update && \ apk add postgresql-dev bash RUN addgroup -S appgroup && adduser -S appuser -G appgroup RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime RUN echo 'Asia/Shanghai' > /etc/timezone USER appuser RUN mkdir /home/appuser/config RUN mkdir /home/appuser/src WORKDIR  /home/appuser/src COPY --chown=appuser:appgroup ./project/ ./Copy the code

Then place the Golangr binary after the project directory. One thing to note here is that since we use the Alpine version of our container, we can do this when compiling Go:

CGO_ENABLED=0 go build main.go  
Copy the code

Step 2: Create docker-comedy.yaml

➜ docker-hr git:(main) cat docker-composite. yml version: '3' services: db: image: latest container_name: postgres01 environment: POSTGRES_PASSWORD: 123456 POSTGRES_USER: postgres POSTGRES_DB: db_hr ports: - "5433:5432" networks: ['mynetwork'] web: build: . container_name: hr command: bash -c "./main" volumes: - ./project:/src expose: - "8081" - "8080" ports: - "8090:8080" stdin_open: false links: - db tty: false networks: ['mynetwork'] restart: always nginx: image: nginx container_name: nginx03 ports: - "8010:80" volumes: - ./project/front:/usr/share/nginx/html - ./config/nginx:/etc/nginx/conf.d links: - web networks: ['mynetwork'] restart: always networks: {mynetwork: {}}Copy the code

Networks are used here: [‘ myNetwork ‘] deploys all three containers on the same network.

Step 3: Nginx configuration

server { listen 80 default_server; listen [::]:80 default_server; root /usr/share/nginx/html; index index.html index.htm index.nginx-debian.html; server_name _; location / { try_files $uri $uri/ /index.html =404; # This line is the most critical}}Copy the code

Final step:

1. Log in to the server

shell 
        root@hrgdrc:/home# apt update
     	root@hrgdrc:/home# apt install git 
Copy the code

Docker-compose install docker-compose

See step 1 aboveCopy the code

3. Go to the server and pull down Github

root@hrgdrc:~/project# git pull https://github.com.cnpmjs.org/yeelone/salary-docker-compose.git
Copy the code

Docker-compose: docker-compose

root@hrgdrc:~/project# docker-compose build 
root@hrgdrc:~/project# docker-compose up 
Copy the code

Remember to open up ports on your cloud server

Summary: With Docker-compose, deployment is fairly simple.

Project related:

Experience the address: http://47.104.154.41:8010/dashboard

Github address: github.com/yeelone/sal…

Core open source: github.com/yeelone/hr-…