This has thrown for a loop but I’m sure it’s something very simple that I’m misunderstanding. I’m putting together a docker development environment for a blog site. It consist of three components: strapi, API service which pulls data from a third party, and a mongodb database.
I followed along with the tutorial on the docker-compose section of the docs and used the docker-compose.yml
from this blog: How to run a Strapi dev stack using Docker compose
Although, I’m hitting a snag. If attempt to compose my containers using the compose file below, Strapi fails to connect to my mongo instances.
version: '3'
services:
# fitbit-stats-graph-service:
# build: ./api
# ports:
# - "3000:3000"
# links:
# - mongo # link this service to the database service
# volumes:
# - .:/usr/src/app
# depends_on:
# - mongo
mongo_db:
image: mongo
container_name: mongo_db
ports:
- '27016:27017'
environment:
MONGO_INITDB_ROOT_USERNAME: strapi
MONGO_INITDB_ROOT_PASSWORD: strapi
networks:
- strapi-app-network
volumes:
- strapidata:/data/db
strapi:
image: strapi/strapi
depends_on: mongo_db
restart: unless-stopped
environment:
DATABASE_CLIENT: mongo
DATABASE_NAME: strapi
DATABASE_HOST: mongo_db
DATABASE_PORT: 27016
DATABASE_USERNAME: strapi
DATABASE_PASSWORD: strapi
networks:
- strapi-app-network
volumes:
- ./app:/srv/app
ports:
- '1337:1337'
depends_on:
- mongo_db
networks:
strapi-app-network:
driver: bridge
volumes:
strapidata:
I commented out my service since I thought maybe it had a play into it.
mongodb spins up but if Strapi tries to connect to it, I get connection refusals
strapi_1 | [2020-10-05T21:12:53.266Z] debug ⛔️ Server wasn't able to start properly.
strapi_1 | [2020-10-05T21:12:53.268Z] error Error connecting to the Mongo database. connect ECONNREFUSED 172.19.0.2:27016
I’ve tried a couple of things: I thought maybe that mongo isn’t up and running by the time Strapi starts is loading and added a depends_on
property to the yaml. I also played around different host names thinking the issue was related to the use of the ip address in Strapi but that didn’t lead to anything fruitful.
I’m using a Debian operating system
Is this enough information that you need?