Using docker to build a private code repository from scratch

Keywords: Linux Nginx MySQL Docker

docker builds nginx tutorials

Through< MySQL Construction of Building Private Code Warehouse from scratch with docker > and< Using docker to build gogs of private code repository from scratch > In fact, the code warehouse has been built successfully, but in order to facilitate access, we sometimes need to bind domain names, so we can forward through nginx.

Add nginx container

Open the docker-compose.yml file in the previous tutorial and fill in the following:

  gogs_nginx:
    build:
      context: nginx
    tty: true
    depends_on:
      - gogs
    restart: always
    networks: 
      frontend:
    ports:
      - 80:80
    volumes:
      - ./nginx/conf:/etc/nginx/conf.d
      - ${DATA_DIR}/nginx/conf:/var/log/nginx

The final docker-compose.yml file is as follows:

version: "3"

networks:
  frontend:

services:
  mysql:
    image: mysql:${MYSQL_VERSION}
    networks: 
      frontend:
    tty: true
    restart: always
    ports:
      - 3306:3306
    volumes:
      - ${DATA_DIR}/mysql/:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_USER=${MYSQL_USER}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
  gogs:
    image: gogs/gogs
    depends_on:
      - mysql
    tty: true
    networks: 
      frontend:
    restart: always
    volumes:
      - ${DATA_DIR}/gogs:/data
  gogs_nginx:
    build:
      context: nginx
    tty: true
    depends_on:
      - gogs
    restart: always
    networks: 
      frontend:
    ports:
      - 80:80
    volumes:
      - ./nginx_conf:/etc/nginx/conf.d
      - ${DATA_DIR}/nginx/conf:/var/log/nginx

Create the nginx_conf directory in the project root directory and create the default.conf configuration file for nginx

> mkdir nginx_conf && cd nginx_conf && touch default.conf

Edit default.conf configuration file and add the following configuration:

upstream gogs {
    server gogs:3000;
}

server {
    listen       80 default_server;
    server_name  gogs.me; # domain name

    location / {
        #The address of the reverse proxy
        proxy_pass http://gogs;  
        #Setting the real address of the host and client so that the server can get the real IP of the client
        proxy_set_header Host $host;
        proxy_set_header X-Real-Ip $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        access_log /var/log/nginx/gogs.log main;
    }
}

This configuration binds the domain name gogs.me and forwards the request to port 3000 of the gogs container

start nginx

> docker-compose up -d gogs_nginx

With this command, mysql and gogs are started together.

All containers were started successfully.

Install gogs

Entering gogs.me in the browser will give you the interface to install gogs:

Add the following configuration:

After adding, click Install immediately and wait for the installation to complete.

More wonderful articles, please pay attention to my blog SOCKSTACK Share my work experience.

Posted by BMurtagh on Wed, 09 Oct 2019 09:08:24 -0700