This document provides a comprehensive guide on how Docker is utilized within the development environment of the gitlab-org/coming-soon project. This section will focus on the configuration files, the setup process, and any pertinent commands that enhance the development workflow via Docker.

Overview of Docker Usage

In the context of developing gitlab-org/coming-soon, Docker is utilized primarily to streamline the development process, ensuring a consistent environment across different machines. This encapsulation helps avoid the common pitfalls associated with “it works on my machine” scenarios.

Prerequisites

Before diving into the configuration steps and examples, ensure that the following prerequisites are satisfied:

Dockerfile Configuration

The Dockerfile in the gitlab-org/coming-soon repository defines the build configuration for the development environment. Below is the essential content typically found in the Dockerfile:

# Use the official Node.js image.
FROM node:14

# Set the working directory.
WORKDIR /app

# Copy package.json and package-lock.json.
COPY package*.json ./

# Install dependencies.
RUN npm install

# Copy the project files.
COPY . .

# Expose the port the app runs on.
EXPOSE 3000

# Command to run the application in development mode.
CMD ["npm", "run", "dev"]

This configuration covers the fundamental aspects:

  • Base Image: Starts from a Node.js image which is suitable for JavaScript applications.

  • Working Directory: Sets /app as the working directory in the container for better organization.

  • Dependency Handling: Copies the necessary package files and executes npm install to install dependencies as defined in the project.

  • Port Exposure: The application listens on port 3000, making it accessible on that port when running in Docker.

Docker Compose Configuration

For simpler orchestration involving multiple services, the docker-compose.yml file is often utilized. Below is a basic example of how this file may be configured for development:

version: '3'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - .:/app
    ports:
      - "3000:3000"
    environment:
      NODE_ENV: development

Breakdown of Docker Compose

  • Versioning: The version specifies which syntax version for Docker Compose to use.

  • Services: Defines the main service for the application.

  • Build Context: Points to the Dockerfile to build the app image.

  • Volumes: Maps the local directory to the container’s working directory. This is crucial for live-reloading during development.

  • Ports: Maps container port 3000 to host port 3000, enabling access to the application.

  • Environment Variables: Sets NODE_ENV to development for necessary configuration management.

Commands to Build and Run

With the configuration files in place, the following commands may be used to build and run the Docker environment for development:

  1. Building the Docker Image:

    docker-compose build
    
  2. Running the Application:

    docker-compose up
    
  3. Accessing the Application: Open a web browser and navigate to http://localhost:3000 to view the application in action.

  4. Stopping the Services:

    docker-compose down
    

Development Workflow

Incorporating these Docker configurations into your development workflow provides several advantages:

  • Isolated Environment: Develop in an environment identical to your teammates, eliminating discrepancies.

  • Live Reload: With the volume configuration, changes in the codebase automatically reflect in the running application.

  • Easy Setup: New developers can quickly get started with the project using Docker without extensive setup.

Conclusion

This documentation provides the foundational guidelines for utilizing Docker in the development environment of gitlab-org/coming-soon. By adhering to these configurations, developers can leverage Docker’s capabilities to enhance productivity and ensure consistency across collaborative efforts.

For further details, please refer to the code documentation within the repository.