How to Install OpenGist on Docker with Docker Compose

How to Install OpenGist on Docker with Docker Compose

OpenGist is a powerful open-source tool for sharing code snippets, notes, and configuration files. By using Docker and Docker Compose, you can easily install and manage OpenGist on your local environment or on a server. This article will guide you step-by-step through the process of setting up OpenGist using Docker and Docker Compose.

What is Docker?

Docker is a platform that allows developers to automate the deployment of applications inside lightweight, portable containers. Containers include everything needed to run the application, such as the code, runtime, libraries, and system tools. This ensures that the application behaves the same regardless of where it is run.

What is Docker Compose?

Docker Compose is a tool that allows you to define and manage multi-container Docker applications. It uses a YAML file to configure the application’s services, making it easy to define and run complex applications with multiple components.

Prerequisites

Before you begin, make sure you have the following installed on your system:

  1. Docker: The Docker Engine must be installed and running on your machine.
  2. Docker Compose: This tool should be installed and correctly configured.

Please take a look at this guide if you want to install Docker and Docker Compose.

Step 1: Set Up Your Directory Structure

First, you need to organize your directories to store your Docker containers. Personally, I keep all my Docker setups in a directory named dockers in my home directory. You can create this directory if it doesn’t already exist:

mkdir ~/dockers

Next, within the dockers directory, create a new folder specifically for OpenGist:

mkdir ~/dockers/opengist

This directory will hold all the necessary files and configurations for OpenGist.

Step 2: Create the Docker Compose File

Navigate to the opengist directory and create a Docker Compose file. This file will define how Docker should run your OpenGist container.

cd ~/dockers/opengist
vi docker-compose.yml

In the docker-compose.yml file, add the following content:

services:
  opengist:
    image: ghcr.io/thomiceli/opengist:1.4
    container_name: opengist
    restart: unless-stopped
    ports:
      - "6157:6157" # HTTP port
      - "2222:2222" # SSH port, can be removed if SSH is not needed
    volumes:
      - "/root/dockers/opengist:/opengist"

Save and exit the file by pressing :wq.

Important Note:

Make sure to adjust the path /root/dockers/opengist:/opengist according to your system’s directory structure. This path maps the local directory to the container, ensuring that your data is stored persistently.

Step 3: Customize User and Group Permissions (Optional)

If you need to specify which user or group should manage the container and own the files, you can set the UID and GID environment variables. Add the following lines to the docker-compose.yml file under the opengist service:

   environment:
      UID: 1000
      GID: 1000

Replace 1000 with the appropriate user and group IDs for your setup.

Step 4: Start the Docker Compose File

To start the OpenGist container, use the following command:

docker compose up -d

The -d flag runs the container in detached mode, allowing it to run in the background.

Step 5: Verify the Docker Container is Running

Once the command completes, you can check if the Docker container is running with:

docker ps

his command will list all running containers. You should see opengist in the list if everything is set up correctly.

Step 6: Access OpenGist

You can now access the OpenGist service running in Docker through your web browser. Open your browser and navigate to:

http://SERVER_IP:6157

Replace SERVER_IP with the IP address of the server where Docker is running. If you’re running this on your local machine, you can use localhost instead of SERVER_IP.

Conclusion

Installing OpenGist with Docker and Docker Compose is a straightforward process that offers a robust way to manage your application. By following the steps outlined in this article, you can easily set up, customize, and manage OpenGist in a containerized environment. The combination of Docker and Docker Compose not only simplifies deployment but also ensures that your application runs consistently across different environments.

Fedya Serafiev

Fedya Serafiev

Fedya Serafiev owns the website linuxcodelab.eu. He finds satisfaction in helping people solve even the most complex technical problems. His current goal is to write easy-to-follow articles so that such problems do not arise at all.

Thank you for reading the article! If you found the information useful, you can donate using the buttons below: