Docker installs Gogs and git services

Keywords: Docker git github

Technical Party: Su Xuefeng

Mirror installation

gihub address: https://github.com/gogs/gogs

gogs official website: Gogs: A painless self-hosted Git service

How to install gogs for gihub official docker: https://github.com/gogs/gogs/tree/master/docker

Pull gogs image:

#from Docker Hub Extract images from.
$ docker pull gogs/gogs

#Create a local directory.
$ mkdir -p /mydata/gogs

#First use`docker run`. 
$ docker run -d --name=gogs -p 10022:22 -p 3000:3000 -v /mydata/gogs:/data gogs/gogs

#If you have stopped it, please use`docker start`. 
$ docker start gogs

Note: it is important to map the Gogs ssh service from the container to the host and set the appropriate SSH port and URI settings when setting up Gog for the first time. To access and clone the Gogs Git repository using the above configuration, you can use:

git clone ssh://git@hostname:10022/username/myrepo.git

For example:

/mydata/gogs

In my case, the file will be stored in the local path

/mydata/gogs
|-- git
|   |-- gogs-repositories
|-- ssh
|   |-- # ssh public/private keys for Gogs
|-- gogs
    |-- conf
    |-- data
    |-- log

Volume of data container

If you prefer to load data into a data container, the first command you execute is as follows:

#Create data container 
docker run --name=gogs-data --entrypoint /bin/true gogs/gogs#First use`docker run`. 
docker run --name=gogs --volumes-from gogs-data -p 10022:22 -p 3000:3000 gogs/gogs

Using Docker 1.9 Volume command

#establish docker Volume.
$ docker volume create --name gogs-data    #First use`docker run`. 
$ docker run --name=gogs -p 10022:22 -p 3000:3000 -v gogs-data:/data gogs/gogs

set up

application

Most settings are obvious and easy to understand, but some settings may make running Gogs in Docker confusing:

Repository root path: leave it as the default, / home / git / gogs repositories because start.sh has created symbolic links for you.

Run user: leave it as the default, git, because build.sh has set the named user git.

Domain: use Docker container IP (for example, 192.168.99.100). However, if you want to access the Gogs instance from another physical machine, please fill in the host name or IP address of the Docker host.

SSH port: use the public port in the Docker container. For example, your ssh server 22 listens inside Docker, but you expose it to 10022:22, and then 10022 is used for this value. Built in ssh server is not recommended in Docker container

HTTP port: use the port on which you want Gogs to listen inside the Docker container. For example, your Gogs 3000 listens inside Docker and exposes it to 10080:3000, but you still use this value.

Application URL: use a combination of domain and exposed HTTP port values (for example http://192.168.99.100:10080/ ).

Can be in here Locate the complete documentation for the application settings.

Container options

This container provides options through environment variables, which are optional features that can help manage this container:

SOCAT_LINK

Possible values: true, false, 1, 0

Default: true

Action: use socat to bind the linked docker container to the localhost socket. Any export port from the linked container will be bound to a matching port on localhost.

Disclaimer: since this option depends on the environment variables created by Docker when linking containers, it should be disabled in the managed environment, such as Rancher or Kubernetes (set to 0 or false)

RUN_CROND

Possible values: true, false, 1, 0

Default: false

Action: request crond to run inside the container. Its default configuration will run all scripts periodically, / etc/periodic/${period}, but you can add custom crontabs /var/spool/cron/crontabs /.

upgrade

❗ ️ ❗ ️ ❗ Ensure that you have stored the data in a location outside the Docker container ❗ ️ ❗ ️ ❗ ️

To upgrade Gogs using Docker:

docker pull gogs/gogs
docker stop gogs
docker rm gogs

Note: finally, when creating a container for the first time, don't forget to do the same for volume and port mapping.

Gogs docker-compose

version: '2'
services:
    postgres:
      image: postgres:9.5
      restart: always
      environment:
       - "POSTGRES_USER=${POSTGRES_USER}"
       - "POSTGRES_PASSWORD=${POSTGRES_PASSWORD}"
       - "POSTGRES_DB=gogs"
      volumes:
       - "db-data:/var/lib/postgresql/data"
      networks:
       - gogs
    gogs:
      image: gogs/gogs:latest
      restart: always
      ports:
       - "10022:22"
       - "3000:3000"
      links:
       - postgres
      environment:
       - "RUN_CROND=true"
      networks:
       - gogs
      volumes:
       - "gogs-data:/data"
      depends_on:
       - postgres

networks:
    gogs:
      driver: bridge

volumes:
    db-data:
      driver: local
    gogs-data:
      driver: local

function

POSTGRES_USER=<your_db_user> POSTGRES_PASSWORD=<your_db_password> docker-compose up -d

Posted by nickihandy on Wed, 20 Oct 2021 19:26:49 -0700