Hi all!
I have two different apps with two different docker-compose.yml files in different directories. I have a python flask app that fetches data from internet and stores it in a PostgreSQL database. This is working perfectly so far. This app should only accept connections from localhost. The second app is a Golang app that fetches data from internet but should also make requests to the first app, get that data and store it in a PostgreSQL database.
I have tried and my setup works perfectly in my local development machine, but it doesn’t work when it’s deployed in a droplet, and I’ve been trying for a week and I can’t find out why.
From my golang app code, I’m making a GET request to http://jobs-web:5000
or http://jobs:5000
and I’m getting an EOF error.
Here’s my two compose files:
First python app:
web:
container_name: jobs-web
build: .
command:
[
"gunicorn",
"-b",
"0.0.0.0:5000",
"app:create_app()",
"--log-level",
"debug",
"--access-logfile",
"-",
"--error-logfile",
"-",
"--timeout",
"0",
"--preload",
]
environment:
ENABLE_SCHEDULER: ${ENABLE_SCHEDULER}
FLASK_ENV: production
SQLALCHEMY_DATABASE_URI: ${SQLALCHEMY_DATABASE_URI}
volumes:
- .:/app
depends_on:
- db
networks:
- fullstack
db:
container_name: jobs-db
image: postgres:16.4-alpine3.20
restart: always
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- postgres_data:/var/lib/postgresql/data
- ./init-db.sh:/docker-entrypoint-initdb.d/init-db.sh
- ./.env:/app/.env
networks:
- fullstack
networks:
fullstack:
external: true
volumes:
postgres_data:
test_postgres_data:
Second Goland app:
services:
remoti-db:
image: postgres:16.4-alpine3.20
container_name: remoti-db
ports:
- 5432:5432
restart: always
environment:
- POSTGRES_DB=${DB_NAME}
- POSTGRES_USER=${DB_USERNAME}
- POSTGRES_PASSWORD=${DB_PASSWORD}
networks:
- remoti-network
volumes:
- database_postgres:/var/lib/postgresql/data
healthcheck:
test: [CMD-SHELL, "pg_isready -U ${DB_USERNAME}"]
interval: 3s
timeout: 3s
retries: 5
expose:
- "5432"
app:
build:
context: .
dockerfile: Dockerfile
container_name: remoti-app
ports:
- 4000:4000
depends_on:
remoti-db:
condition: service_healthy
networks:
- fullstack
- remoti-network
prometheus:
image: prom/prometheus
ports:
- 9090:9090
volumes:
- prometheus:/prometheus
- ./prometheus/development.yml:/etc/prometheus/prometheus.yml
networks:
- remoti-network
grafana:
image: grafana/grafana
ports:
- 3000:3000
depends_on:
- prometheus
networks:
- remoti-network
volumes:
- grafana:/var/lib/grafana
- ./grafana/provisioning/datasources:/etc/grafana/provisioning/datasources
- ./grafana/provisioning/dashboards:/etc/grafana/provisioning/dashboards
- ./grafana/dashboards:/etc/dashboards
- ./grafana/grafana.ini:/etc/grafana/grafana.ini
migrations:
image: migrate/migrate:latest
env_file:
- .env
command: -path /migrations -database ${DSN} up
volumes:
- ./migrations:/migrations
networks:
- remoti-network
depends_on:
remoti-db:
condition: service_healthy
volumes:
database_postgres:
migrations:
prometheus:
grafana:
networks:
fullstack:
external: true
remoti-network:
driver: bridge
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Hey 👋
The issue you’re encountering when deploying to a DigitalOcean Droplet sounds like it is related to how you’ve configured the Docker networks in your Droplet environment versus your local machine.
In your setup, you have two Docker Compose files with different networks:
fullstack
network, which is defined as external and shared between both apps.remoti-network
network, which is specific to your second app.Since you want your Golang app to communicate with the Python app, both apps need to be on the same network and able to resolve each other by the container names.
Since you’ve defined
fullstack
as an external network, make sure it exists on the Droplet. You can create it manually before deploying:This ensures that when both Docker Compose files run, they’ll correctly connect to the same
fullstack
network.In your Golang app, you’re trying to connect to
http://jobs-web:5000
. This assumes that the Golang container is on the same network (fullstack
) as thejobs-web
container.Since both of your
docker-compose.yml
files mention thefullstack
network, double-check that:fullstack
network.http://jobs-web:5000
if they’re on the same network.Also check the logs from both the Python and Golang containers to see if there are any errors or network issues:
This can give you more insights into what’s going wrong.
You can manually test network connectivity between the containers by entering the shell of the Golang container and using
curl
to test the connection:This will help you determine if the networking between the containers is functioning as expected.
If you continue to have issues, another approach would be to consolidate both applications into a single
docker-compose.yml
file. This way, you can manage everything more easily and avoid any potential issues with external networks.Let me know how it goes and if you need any more help, feel free to ask! 🚀
- Bobby