Day 4: Setting Up Development Environment with Docker Compose

logo

Virtual Assistant, Web Design and bookkeeping services

GitHub Repository

You can find all the necessary files used inside Docker Compose in the GitHub repository.

Local Development Tools

To streamline your local development environment, ensure you have the following tools:

  • IDE: Use VSCode or any other IDE of your preference.
  • Docker and Docker-Compose: Avoid installing individual tools like ElasticSearch and Redis on your local machine.
  • RabbitMQ
  • ElasticSearch and Kibana: These serve as the database for various types of data and provide a dashboard to view the data.
  • MongoDB
  • MySQL
  • PostgreSQL
  • Redis

Docker Installation

  1. Create an account on Docker Hub.
  2. Install Docker Desktop for your specific operating system.

Redis Setup with Docker Compose

Redis, a powerful key-value data store, is essential for caching. Here’s how to set it up:

  • Create a docker-compose.yaml file in your main project folder.
  • Use the official Redis image from Docker Hub, specifically the Alpine version for its lightweight nature.
  • Map Redis data to a local volume for storage.
yamlCopy codeversion: "3.9"
services:
  redis:
    container_name: redis_container
    image: redis:alpine
    restart: always
    ports:
      - "6379:6379"
    command: redis-server --loglevel warning
    volumes:
      - ./docker-volumes/cache:/data

MongoDB with Docker Compose

MongoDB can be set up without initial authentication for local development. Here’s a snippet:

yamlCopy codemongodb:
    container_name: mongodb_container
    image: mongo:latest
    restart: always
    ports:
      - "27017:27117"
    volumes:
      - ./docker-volumes/data:/data/db

MySQL and PostgreSQL Setup with Docker Compose

For MySQL and PostgreSQL, define environment variables and volumes for data persistence:

yamlCopy codemysql:
    container_name: mysql_container
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      - MYSQL_USER=jobber
      - MYSQL_DATABASE=jobber_auth
      - MYSQL_ROOT_PASSWORD=api
      - MYSQL_PASSWORD=api
    ports:
      - "3306:3306"
    volumes:
      - ./docker-volumes/mysql:/var/lib/mysql
postgres:
    container_name: postgres_container
    image: postgres
    restart: always
    environment:
      - POSTGRES_PASSWORD=api
      - POSTGRES_USER=jobber
      - POSTGRES_DB=jobber_reviews
    ports:
      - "5432:5432"
    volumes:
      - ./docker-volumes/postgres:/var/lib/postgresl

RabbitMQ Setup with Docker Compose

For RabbitMQ, utilize the management Alpine version. Here, no volumes are created for data storage:

yamlCopy coderabbitmq:
    container_name: rabbitmq_container
    image: rabbitmq:3.13-management-alpine
    restart: always
    ports:
      - "5672:5672" # AMQP protocol port
      - "15672:15672" # Management UI port

ElasticSearch and Kibana

To set up ElasticSearch and Kibana, follow the steps outlined in the Elasticsearch Guide and Elastic Blog. Ensure you allocate sufficient memory for Docker Desktop.

Running the Services

Ensure Docker service is running, then execute the following command to start services in detached mode:

bashCopy codedocker compose up -d redis mongodb mysql postgres rabbitmq elasticsearch kibana

Elasticsearch Configuration

After starting Elasticsearch, set up security by executing the following commands:

bashCopy code# Update Kibana user password
curl -s -X POST -u elastic:admin1234 -H "Content-Type: application/json" http://localhost:9200/_security/user/kibana_system/_password -d '{"password":"kibana"}'
# Generate service token for Kibana
elasticsearch-service-tokens create elastic/kibana jobber-kibana

Ensure to recreate the password for kibana_system and the service token if you stop the container and delete the volume.

With these steps, you’ll have a fully functional local development environment set up using Docker Compose. Happy coding!

You May Also Like…

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *