4
votes

I am following this tutorial on python-eve. I use docker container for mongodb and python3 for eve.

It works fine if I use venv for the eve app, but I cannot connect to the mongo container, if I run my eve app in another docker container. I always get the following error in the eve app: pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused. Although, I am still able to connect to the mongo container manually.

What I have done so far

I searched around and tried a few propositions, which did not work out.

  • I changed the bindip in the mongod.conf to 0.0.0.0.
  • I removed the bindip line completely.
  • I tried to start the mongodb as mongod -f /etc/mongod.conf.
  • I tried to remove completely all containers and start fresh.

My docker-compose.yml

version: '3.3'

volumes:

  mongodata:

services:

  mongodb:
    container_name: 'mongodb'
    image: mongo:3.4
    volumes: 
      - mongodata:/data/db
    env_file:
      - environments/local.env
    expose:
      - 27017

  api:
    container_name: 'mymoney'
    build:
      context: ./src
      dockerfile: Dockerfile
    volumes:
      - ./src:/app/src
    ports:
      - '5000:5000'
    depends_on:
      - mongodb
    links:
      - mongodb

My Dockerfile for the eve app:

FROM python:3.6
MAINTAINER alpy

ENV PYTHONUNBUFFERED 1

RUN apt-get update && apt-get install -qq -y build-essential libffi-dev python3-dev

RUN mkdir -p /app/src
# We copy the requirements.txt file first to avoid cache invalidations
COPY requirements.txt /app/src
WORKDIR /app/src
RUN pip install -r requirements.txt
COPY . /app/src
EXPOSE 5000
CMD ["python", "run.py"]

I have no idea, what else I can do. Need your help.

1

1 Answers

2
votes

It appeared, that the MONGO_HOST in the settings.py of the app, must be set to the mongo container name as specified in the docker-compose.yml:

...
MONGO_HOST = 'mongodb'
...