Issue
I have a flask application that runs with MongoDB.
Locally, When I build and run the container using the following below, the app runs perfectly good locally.
docker-compose build
docker-compose up
These are the created containers:
/application$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9e054b28bb46 application_web "/bin/sh -c 'python …" 38 seconds ago Up 37 seconds 0.0.0.0:80->80/tcp, 27017/tcp application_web_1
2a19a8e9a267 mongo:3.0.2 "/entrypoint.sh mong…" 39 seconds ago Up 38 seconds 0.0.0.0:27017->27017/tcp application_db_1
I have the following in my app.py:
MONGODB_HOST = os.environ['DB_PORT_27017_TCP_ADDR']
MONGODB_PORT = 27017
app = Flask(__name__)
bootstrap = Bootstrap(app)
client = MongoClient(MONGODB_HOST, MONGODB_PORT)
docker-compose.yml
web:
build: .
command: python -u app.py
ports:
- "80:80"
volumes:
- .:/project
environment:
MONGODB_HOST: db
links:
- db
db:
image: mongo:3.4
command: mongod
ports:
- "27017:27017"
Dockerfile
FROM python:3.6.1-alpine
MAINTAINER [email protected]
WORKDIR /project
ADD . /project
RUN pip install -r requirements.txt
EXPOSE 80
EXPOSE 27017
CMD ["mongod"]
ENV NAME Cheppers_DevOps_Challenge
ENTRYPOINT python app.py
The problem that I am facing, after pushing the images into AWS ECS then I create the cluster with given pushed repository for the container image, I always get this error in the task definition logs:
2019-10-08 14:19:02
MONGODB_HOST = os.environ['DB_PORT_27017_TCP_ADDR']
KeyError: 'DB_PORT_27017_TCP_ADDR'
Solution
I suggest you to change mongo host :
MONGODB_HOST = "db"
this os.environ['DB_PORT_27017_TCP_ADDR']
will use the IP address of the container which you do not need since compose
will handle that for you using the service names.
I think AWS
handle the IP address in different way that is not a dict
anymore ("KeyError")
Answered By - LinPy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.