Docker Community Forums

Share and learn in the Docker community.

Connect to mongodb from flask app


(Togobananas) #1

Hello
There is my stackfile in docker cloud

mongo:
  image: 'mongo:latest'
  ports:
    - '27017:27017'
web:
  image: 'theshakedown/flask-app:latest'
  autoredeploy: true
  links:
    - mongo
  ports:
    - '80:80'

And dockerfile for flask app(web)

FROM ubuntu:14.04.4

MAINTAINER Andrei Khaliaukin endpoo@gmail.com

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update
RUN apt-get -y install nginx sed python3-pip python3-dev uwsgi-plugin-python3 supervisor

RUN mkdir -p /var/log/nginx/app
RUN mkdir -p /var/log/uwsgi/app/

RUN rm /etc/nginx/sites-enabled/default
COPY flask.conf /etc/nginx/sites-available/
RUN ln -s /etc/nginx/sites-available/flask.conf /etc/nginx/sites-enabled/flask.conf
COPY uwsgi.ini /var/www/app/
RUN echo “daemon off;” >> /etc/nginx/nginx.conf

RUN mkdir -p /var/log/supervisor
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

copy app /var/www/app
RUN pip3 install -r /var/www/app/requirements.txt

EXPOSE 80

CMD ["/usr/bin/supervisord"]

Test flask app without db connection running perfectly and fails(and nothing in docker cloud logs) when I am trying to connect to mongodb

my flask app mongodb config

app = Flask(name)

client = MongoClient(
‘MONGO_PORT_27017_TCP_PORT/test’,
27017)
db = client.tododb

Do you have any assumptions?