docker-compose.yml for flask celery rabbitmq

version: '3' services: web: build: . ports: - "5000:5000" volumes: - .:/app depends_on: - rabbitmq - worker worker: build: . volumes: - .:/app depends_on: - rabbitmq rabbitmq: image: rabbitmq:3 ports: - "5672:5672"

Explanation: The provided docker-compose.yml file is used to define and configure the services required for running Flask with Celery and RabbitMQ. Let's break down each step:

  1. version: '3'
  2. This line specifies the version of the Docker Compose file syntax being used. In this case, it is version 3.

  3. services:

  4. This section defines the different services that will be created and used.

  5. web:

  6. This service is responsible for running the Flask application.

  7. build: .

  8. The "build" instruction specifies that the Docker image for the web service should be built using the Dockerfile in the current directory.

  9. ports:

  10. This line maps the host machine's port 5000 to the container's port 5000, allowing access to the Flask application.

  11. volumes:

  12. This line mounts the current directory (where the docker-compose.yml file is located) to the /app directory inside the container. This allows for live code reloading and easy development.

  13. depends_on:

  14. This line specifies that the web service depends on the rabbitmq and worker services. This ensures that RabbitMQ and Celery are running before the Flask application starts.

  15. worker:

  16. This service is responsible for running the Celery worker.

  17. rabbitmq:

  18. This service is responsible for running the RabbitMQ message broker.

  19. image: rabbitmq:3

    • This line specifies that the RabbitMQ service should use the rabbitmq:3 Docker image.
  20. ports:

    • This line maps the host machine's port 5672 to the container's port 5672, allowing access to the RabbitMQ service.

This docker-compose.yml file sets up a Flask application with Celery and RabbitMQ. The web service runs the Flask application, the worker service runs the Celery worker, and the rabbitmq service runs the RabbitMQ message broker. The services are interconnected and work together to provide a scalable and distributed application architecture.