Local GitHub-like source control on Mac with Gogs, Docker, and Dropbox

Dan Guilak // Dec 4th, 2017


It's easy to get used to the source control UI that comes with web applications like GitHub, GitLab, Bitbucket, etc. But what if you're not using it for collaboration but you'd still like a private free repository, or would like to use it without an internet connection?

Enter Gogs—an incredibly lightweight git service, that's super easy to run locally via Docker for Mac.

Install Docker for Mac

It's real painless to install, and it lives in a cute little icon on your taskbar.

Create a folder in your Dropbox where you want to store your Gogs data

$ mkdir ~/Dropbox/gogs

All the configuration information and the SQLite3 database will be stored here.

Pull the Gogs docker image

You can follow along with the instructions in the official repository, but there are a few key differences when you're running on Docker for Mac.

# Pull image from Docker Hub.
$ docker pull gogs/gogs

# Use `docker run` for the first time.
# Link the data file in the container to the Dropbox folder
$ docker run --name=local-gogs -p 10022:22 -p 10080:3000 -v ~/Dropbox/gogs:/data gogs/gogs

You'll see some output similar to this:
docker run terminal output

And then go ahead and open up localhost:10080 in your browser, and you'll see the setup page for Gogs.

Setup

Gogs installation screen

I chose the SQLite3 database so I don't have to run a database server in the container—I want to keep the setup as simple and lightweight as possible.

Leave the domain as localhost, change the SSH port to 10022, leave HTTP Port as 3000, and make sure to change Application URL to http://localhost:10080.

Leave everything else as default, despite what the documentation on the Gogs docker repository says, the instructions are not suited for Docker for Mac1.

Then go ahead and hit the Big Blue Button™.

Create a user

You'll be greeted with a login screen where you can create a new account (the first user will by default be the administrator).

Before you do anything else, make sure to head to your settings and add an SSH key so you're able to create & push repositories.

You're in!

Gogs dashboard

You'll see your dashboard, where things operate pretty similarly to what you'd see on GitHub. When creating a repository you'll see instructions copy and paste to add your remote—the path should be correct as long as you followed the above instructions to change the SSH port to 10022:

git remote add origin ssh://git@localhost:10022/dan/test-repo.git  

And now you can use it similarly to how you would use GitHub or GitLab.

Starting and stopping

Hyperkit memory usage

This solution hardly takes any memory at all
(less than a couple of Chrome tabs for me), so I generally keep the container running all the time.

If you're not going to be using it, you can stop the docker process by running

docker stop local-gogs  # or whatever you named the process  

and starting it up again when you're ready with

docker start local-gogs  

You can also run it through Kitematic, a slick docker UI available in the Docker for Mac toolbar icon—you can easily hit start, stop, and even delete the image if you want (just remember to remove the Dropbox folder too, if you want to do a full clean).

Kitematic screenshot

Happy coding!

  1. According to this StackOverflow post, All the port mappings on Docker for Mac are set to localhost, whereas the instructions on the Gogs docker repository say to use the 'Docker container IP'.