Gogs in Docker git clone woes


I’ve read other answers to issues trying to do an SSH clone with Gogs and attempted to apply suggested fixes all to no avail. What makes this a bit different is the way I’m doing things.

My GOGS is a container in Docker (I used docker-compose to build it) and here is the compose file I am using for the curious.

version: "3"
    hostname: git
    domainname: berghold.net
    build: gogs
    restart: always
      - "9024:22"
      - "3000:3000"
   - /data:/data
     hostname: gogs-db
     domainname: docker.berghold.net
     image: local-mariadb:latest
     build: gogs-db
       - gogs_db_data:/var/lib/mysql
     restart: always
       MYSQL_ROOT_PASSWORD: <redacted>
       MYSQL_DATABASE: <censored>
       MYSQL_USER: gogs
       MYSQL_PASSWORD: <nopeitsasecret>


     name: "middleware"
      name: "backend"

One reason I’m bothering post that is note the mapping for the SSH port for the gogs engine itself. I’ve got the host port 9024 mapped to the container port 22. I made sure my front end firewall is passing 9024 into the container and so far as I can tell it is.

I tried cloning with HTTP and all is hunky-dory but I do not want to use HTTP (in fact I’m considering disabling HTTP) I want to use SSH. Ultimately Jenkins is going to be talking to the repositories on this host.

So I try SSH thusly:

$ git  clone git@git.berghold.net:9024/peter/testapp.git
Cloning into 'testapp'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

well… that didn’t work. Previously I uploaded my keys to Gogs that work fine on BitBucket (want to move from there) with all my repos there.

I guess my question is there something special I need to do to make it work within Docker?

The Gogs Docker image was built from gogs/gogs:latest.


Hi, if you 100% believe the SSH request has arrived the Docker container runs Gogs, read part 1 of How to config SSH settings.

It works only proved you have a valid public key, but that’s all it means.

I’m like ->


Let’s make an assumption that it is not. Is there some sort of logging I can turn on in Gog that would either prove that it is?



It is matter that handles by OpenSSH server, the request not even reached to Gogs yet.


The issue was with the URL. The URL that Gogs supplies is actually wrong.

What Gogs supplied was: git@git.berghold.net:peter/testapp.git

I used: git@git.berghold.net:9024/peter/testapp.git

What it should be is: ssh://git@git.berghold.net:9024/peter/testapp.git

Works well… lasts a long time. (I hope)


Just to do penance I’m going to write up a “how to” on my blog to expand on the existing one dealing with how to deploy Gogs to a docker container.



Gogs will generate this URL if you tells the Gogs the port is 9024 in the installation page.


If that’s the case where in the config file do you set that. Almost afraid to mess with it I broke stuff last time…


Here you go: https://github.com/gogs/gogs/blob/a1098384c09bc0d569ec82d19c26415e00cc364b/conf/app.ini#L30-L31