Docker is utilized in the development environment to streamline the setup process, ensuring that all developers can work in a consistent environment regardless of their local machine setup. Below are detailed instructions that outline the configuration and operation of Docker within the context of the trackjs/javascript-gameshow development environment.

Prerequisites

Ensure that Docker is installed on your development machine. You can download the appropriate version from the official Docker website.

Dockerfile

In the root of your project, create a Dockerfile to define your development environment. Below is an example configuration:

# Base image
FROM node:14

# Set working directory
WORKDIR /app

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

# Install dependencies
RUN npm install

# Copy source code
COPY . .

# Expose port
EXPOSE 5000

# Command to run the application
CMD ["npm", "run", "dev"]

In this Dockerfile:

  • The base image used is node:14, which provides a Node.js environment.
  • The working directory is set to /app.
  • Package files are copied to the working directory and dependencies installed using npm install.
  • The entire application code is copied into the container.
  • Port 5000 is exposed, allowing local access via HTTP.
  • The default command runs the development server using npm run dev.

Docker Compose Configuration

To simplify multi-container setups and allow for easier orchestration of services, create a docker-compose.yml file in the root directory:

version: '3.8'

services:
  audience-app:
    build: .
    ports:
      - "5000:5000"
    volumes:
      - .:/app
    environment:
      - NODE_ENV=development

  presenter-app:
    build:
      context: ./presenter-app
    ports:
      - "3000:3000"
    volumes:
      - ./presenter-app:/app
    environment:
      - NODE_ENV=development

In this docker-compose.yml file:

  • Two services are defined: audience-app and presenter-app.
  • Each service builds from the respective directory and exposes necessary ports.
  • Volumes are mounted, allowing live code updates and ensuring that changes made in the local filesystem are reflected inside the containers.
  • Environment variables can be set to indicate the development environment.

Building and Running the Docker Containers

To build and start the Docker containers, execute the following command from the root of the project:

$ docker-compose up --build

This command will build the images and start the containers for both applications.

Accessing the Applications

Once the containers are up and running, the audience application will be accessible at http://localhost:5000 and the presenter application at http://localhost:3000.

Stopping the Docker Containers

To stop and remove the running containers, use:

$ docker-compose down

Conclusion

The provided configurations allow for a robust development environment using Docker, ensuring consistency across development setups. Adjustments can be made to the Dockerfile and Docker Compose configuration to accommodate additional services or specific development requirements.