To configure Docker within the development environment for helixml/live-coding, follow the steps outlined below. This documentation provides detailed code examples and configurations necessary to set up Docker effectively for your development workflow.

Prerequisites

Ensure that Docker is installed and running on your machine. You can verify your installation by running:

docker --version

Setting Up Your Development Environment

  1. Clone the Repository

    First, you need to clone the helixml/live-coding repository to your local machine:

    git clone https://github.com/helixml/live-coding.git
    cd live-coding
    
  2. Create a Dockerfile

    In the root of your project, create a Dockerfile. This file defines the environment that your application will run in:

    # Using an official Node.js runtime as a parent image
    FROM node:14
    
    # Set the working directory
    WORKDIR /usr/src/app
    
    # Copy package.json and package-lock.json
    COPY package*.json ./
    
    # Install app dependencies
    RUN npm install
    
    # Copy the rest of your application code
    COPY . .
    
    # Expose the port the app runs on
    EXPOSE 3000
    
    # Command to run the app
    CMD ["npm", "start"]
    
  3. Create a .dockerignore File

    This file tells Docker which files and directories to ignore during the build process. Create a .dockerignore file to exclude unnecessary files:

    node_modules
    npm-debug.log
    Dockerfile
    .dockerignore
    
  4. Build the Docker Image

    With your Dockerfile in place, you can now build your Docker image. Run this command in your terminal:

    docker build -t helixml-live-coding .
    

    This command builds the Docker image using the current directory (.) context, tagging it as helixml-live-coding.

  5. Running the Docker Container

    After building your image, you can run it in a container. Use the following command:

    docker run -p 3000:3000 -d helixml-live-coding
    

    This command runs the container in detached mode (-d), mapping port 3000 of the container to port 3000 on your host.

  6. Accessing the Application

    The application should now be accessible at http://localhost:3000. Open a web browser and visit this URL to verify that your application is running correctly.

  7. Using Docker Compose for Complex Applications

    If your application requires multiple services (like a database), using Docker Compose can simplify the management of your containers. Create a docker-compose.yml file:

    version: '3'
    
    services:
      app:
        build: .
        ports:
          - "3000:3000"
        volumes:
          - .:/usr/src/app
        environment:
          - NODE_ENV=development
    
      db:
        image: mongo
        ports:
          - "27017:27017"
    

    Build and start all services with:

    docker-compose up
    

    This command starts both your application and MongoDB as defined in the docker-compose.yml file.

  8. Stopping the Containers

    To stop the containers created by Docker Compose, use the following command:

    docker-compose down
    

This stops and removes the containers defined in the docker-compose.yml file.

  1. Accessing Logs

    To view logs from your running application, you can use:

    docker logs <container_id>
    

    Replace <container_id> with the actual ID or name of your running container.

  2. Debugging Issues

    If you encounter issues while working with Docker, inspect the running containers and their statuses by executing:

    docker ps
    

    For further diagnosis, connect to a running container for shell access:

    docker exec -it <container_id> /bin/bash
    

By following these steps, you can effectively configure and use Docker in your development environment for helixml/live-coding.

Source: helixml/live-coding