Docker installs Gogs and git services

Keywords: Docker git github

Technical Party: Su Xuefeng

Mirror installation

gihub address:

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

How to install gogs for gihub official 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:


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

|-- 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


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 has created symbolic links for you.

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

Domain: use Docker container IP (for example, 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 ).

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:


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)


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 /.


❗ ️ ❗ ️ ❗ 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'
      image: postgres:9.5
      restart: always
       - "POSTGRES_DB=gogs"
       - "db-data:/var/lib/postgresql/data"
       - gogs
      image: gogs/gogs:latest
      restart: always
       - "10022:22"
       - "3000:3000"
       - postgres
       - "RUN_CROND=true"
       - gogs
       - "gogs-data:/data"
       - postgres

      driver: bridge

      driver: local
      driver: local


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