Docker Gogs - How To
Setup Gogs using official docker image.
Image
Docker Hub: gogs/gogs1
Mappings
Host | Inside Container | Usage |
---|---|---|
$MY_GOGS_DIR | /data | Gogs persistent storage(configuration, data, log) |
$MY_GOGS_SSH_PORT | 22/tcp | Gogs ssh listening port |
$MY_GOGS_WEB_PORT | 3000/tcp | Gogs http listening port |
$MY_GOGS_DIR, $MY_GOGS_SSH_PORT and $MY_GOGS_WEB_PORT will be used in compose section below.
Preparation
$MY_GOGS_DIR
Create a directory for Gogs persistent storage. We will use /var/lib/my_gogs as our Gogs persistent storage.
|
|
In this case $MY_GOGS_DIR=/var/lib/my_gogs, you can create the directory in other location.
$MY_GOGS_SSH_PORT
Gogs uses standard ssh port 22 inside container. We will map it to 22222 in the host for this example.
In this case $MY_GOGS_SSH_PORT=22222, you can use other port as long as it does not conflict with other services running.
NOTE: Do not map to port 22 on your host. That will likely conflict with your host ssh.
$MY_GOGS_WEB_PORT
Gogs web interface uses port 3000 inside container. We will map it to port 3000 on the host.
In this case $MY_GOGS_WEB_PORT=3000, again, you can use other port as long as it does not conflict with other services running.
Preparation Summary
Variable | Value |
---|---|
$MY_GOGS_DIR | /var/lib/my_gogs |
$MY_GOGS_SSH_PORT | 22222 |
$MY_GOGS_WEB_PORT | 3000 |
Setup
Testing
Following is the format using variables mentioned above:
|
|
docker run option | Usage |
---|---|
–rm | Automatically remove the container when it exits |
-v <source path in host>:<target path in container> | Map a path(file/dir) from host to a path in container |
-p <host port>:<container port> | Map a port from host to a port in container |
Let just plug in all the values manually for now:
|
|
Output:
|
|
If you check /var/lib/my_gogs, sub-directories are created:
|
|
Keep it running for now and go to next step.
Configuration
Open your browser to http://<hostname/ip>:3000 and fill out the form as follow:
Once you click Install Gogs:
The config file is located at ${MY_GOGS_DIR}/gogs/conf/app.ini. In this example the path will be /var/lib/my_gogs/gogs/conf/app.ini.
Most of the values should not be changed except ROOT_URL in [server] section:
|
|
The ROOT_URL should be the URL used in your browser. For example, if you put a nginx front proxy with https at standard port 443, then ROOT_URL will be https://<hostname>/.
After updating app.ini, stop the container with ctrl-c and run it again. The output will be shorter:
|
|
Stop it with ctrl-c.
Compose
Gogs configuration is done. But we don’t want to enter the long train of options every time restarting Gogs or after server reboot. This is where docker-compose comes in.
Let create the two necessary files below.
.env
Create /var/lib/my_gogs/.env:
|
|
MY_GOGS_TAG: You can use specific version other than latest. List of valid version is in gogs/gogs docker tags page2.
docker-compose.yml
Create /var/lib/my_gogs/docker-compose.yml:
|
|
Start
|
|
docker-compose command/Option | Usage |
---|---|
up | create and start container |
-d | daemon/run in background |
When docker-compose3 is executed, it automatically look for two default files in current directory: docker-compose-yml4 and .env5.
It will use variables in .env as environment variables. The .env file must be present in the current working folder.
Currently there is no command line option to specify an alternative .env file.
Variables already set in shell and command line will override .env.
It will create containers(s) base on docker-compose.yml.
-f can specify one or more compose file, other than the default.
Output:
|
|
Status
Check status with ps
|
|
Output:
|
|
Stop
|
|
Output:
|
|
Now Gogs is ready!