Skip to content

Instantly share code, notes, and snippets.

@burningTyger
Last active August 13, 2016 16:39
Show Gist options
  • Save burningTyger/caf5db4a6998df7323369efe196901af to your computer and use it in GitHub Desktop.
Save burningTyger/caf5db4a6998df7323369efe196901af to your computer and use it in GitHub Desktop.
Docker Gogs systemd script

Starting Gogs as a Docker container on startup via systemd

Gogs is that great Github clone which is also available as a docker image. Works perfectly if started by the user but since you probably want to run it on your server and without interruption you can add a systemd script to start up Gogs on boot. My script looks like this:

# /etc/systemd/system/docker.gogs.service
[Unit]
Description=Gogs container
Requires=docker.service
Require=postgresql.service
After=docker.service
After=postgresql.service

[Service]
Restart=always
ExecStart=/usr/bin/docker run --name=gogs -p 10022:22 -p 10080:3000 -v /var/gogs:/data gogs/gogs
ExecStop=/usr/bin/docker stop -t 2 gogs ; /usr/bin/docker rm -f gogs

[Install]
WantedBy=multi-user.target

This script expects to find docker and postgres running since those are the two dependencies.

It will always restart if it crashes and run on ports 10022 for ssh and 10088 for http. Data is stored under /var/data. If the container stops it is immediately purged and restarted.

In order to activate your script you need to:

sudo systemctl enable docker.gogs

You can now either just connect to your ip:10080 or set up a webserver backproxy so that you can easily integrate your service with other web services.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment