» Python: Make Web Chat App with Socket.IO » 3. Deployment » 3.2 Docker Compose

Docker Compose

Docker Compose is a tool for defining and running multi-container Docker applications. It allows you to use a YAML file to configure your application's services, networks, and volumes, and then spin up all the containers required to run your application with a single command.

Add compose/docker-compose.yml:

services:
  lr-webchat-py:
    build:
      context: ../
      dockerfile: Dockerfile
    ports:
      - 4000:4000
    environment:
      - PORT=4000
  lr-webchat-react:
    build:
      context: ../../lr_webchat
      dockerfile: Dockerfile
    ports:
      - 3000:3000
    depends_on:
      lr-webchat-py:
        condition: service_started

Run it:

cd compose
docker compose up

You should see something like this:

[+] Running 2/2
 ✔ Container compose-lr-webchat-py-1     Created                                                                                                                                                0.0s 
 ✔ Container compose-lr-webchat-react-1  Recreated                                                                                                                                              0.1s 
Attaching to lr-webchat-py-1, lr-webchat-react-1
lr-webchat-py-1     | INFO:     Started server process [1]
lr-webchat-py-1     | INFO:     Waiting for application startup.
lr-webchat-py-1     | INFO:     Application startup complete.
lr-webchat-py-1     | INFO:     Uvicorn running on http://0.0.0.0:4000 (Press CTRL+C to quit)
...
lr-webchat-react-1  |  INFO  Accepting connections at http://localhost:3000
...

Now, if you visit your page at http://localhost:3000, you should be able to see the UI of the chat app.

Your web chat app works like a charm! 📢