This document provides a step-by-step guide on how Docker is utilized within the development environment of the gitlab-org/gitlab-discussions. This will focus exclusively on development setup, disregarding any production-related configurations.

Overview

Within the gitlab-org/gitlab-discussions repository, Docker is employed to streamline the development process by ensuring consistent environments across different setups. This document details how to configure Docker for development purposes, including image building, container management, and running services.

Prerequisites

Before beginning, ensure that the following software is installed on your machine:

  • Docker
  • Docker Compose
  • Git

Setting Up Docker

Step 1: Clone the Repository

Begin by cloning the gitlab-org/gitlab-discussions repository to your local development machine:

git clone https://gitlab.com/gitlab-org/gitlab-discussions.git
cd gitlab-discussions

Step 2: Dockerfile and Docker Compose Configuration

Inside the cloned repository, you will find a Dockerfile and docker-compose.yml file. These are crucial for building the Docker image and orchestrating the containers.

Dockerfile

The Dockerfile defines the environment configuration. A typical setup might look like this:

FROM ruby:2.7

# Install dependencies
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev libxml2-dev libxslt1-dev

# Set the working directory
WORKDIR /usr/src/app

# Copy the Gemfile and install gems
COPY Gemfile Gemfile.lock ./
RUN bundle install

# Copy the application code
COPY . .

# Command to run the application
CMD ["rails", "server", "-b", "0.0.0.0"]

docker-compose.yml

The docker-compose.yml file is used to define and run multi-container Docker applications. Here’s an example snippet:

version: '3.8'

services:
  web:
    build: .
    ports:
      - "3000:3000"
    volumes:
      - .:/usr/src/app
    environment:
      - RAILS_ENV=development

  db:
    image: postgres:13
    environment:
      - POSTGRES_USER=gitlab
      - POSTGRES_PASSWORD=secret
      - POSTGRES_DB=gitlab_development

Step 3: Building the Docker Container

After ensuring your Dockerfile and docker-compose.yml files are correctly configured, build the Docker images with the following command:

docker-compose build

This command reads the configuration from the docker-compose.yml file, builds your application image, and prepares to run the service.

Step 4: Running the Development Environment

Now that the Docker images are built, you can start your development environment:

docker-compose up

This command will start all services defined in the docker-compose.yml. You should see output indicating that the web server is running, typically accessible at http://localhost:3000.

Step 5: Accessing the Web Application

Once the services are up, you can open your web browser and navigate to http://localhost:3000 to access the application. It should now be fully operational within a Docker container.

Step 6: Stopping the Development Environment

To stop the running containers, you can use:

docker-compose down

This command will stop all containers and remove them along with the associated networks.

Conclusion

Using Docker for development in the gitlab-org/gitlab-discussions repository ensures a consistent and replicable development environment. By following the outlined steps, developers can set up their local environments efficiently, allowing them to focus on contributing to the project.

For more in-depth details about Docker’s usage, consult the source references: