Reputation: 45
I'm tying to dockerize a webservice, I configured the following files:
dockerfile
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
docker-compose.yml
version: '3'
services:
db:
image: mysql
container_name: DB_test
environment:
MYSQL_DATABASE: 'test'
MYSQL_USER: 'user'
MYSQL_PASSWORD: 'password'
MYSQL_ROOT_PASSWORD: 'password'
ports:
- "3306:3306"
volumes:
- ./sql:/docker-entrypoint-initdb.d
web:
build: .
command: gunicorn --bind 0.0.0.0:8000 manage:app
ports:
- "8000:8000"
depends_on:
- db
sql/init.sql
GRANT ALL PRIVILEGES ON test TO 'user'@'%';
FLUSH PRIVILEGES;
sqlalchemy_conf
{
"HR_API_ID" : "api_id",
"HR_API_CODE" : "api_code",
"DB_HOST" : "0.0.0.0",
"DB_PORT" : "3306",
"DB_USERNAME" : "user",
"DB_PASSWORD" : "password",
"DB_NAME" : "test",
"DB_CONNECTION" : "mysql"
}
After that I run:
docker-compose build
docker-compose up
And the log error that appears in the console is the following one when I try to access http://0.0.0.0:8000/:
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on '0.0.0.0' ([Errno 111] Connection refused)") (Background on this error at: http://sqlalche.me/e/e3q8)
And in http://0.0.0.0:8000/:
Internal Server Error
What am I doing wrong?
UPDATE:
DB_HOST" : "db"
new error:
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1045, "Access denied for user 'user'@'172.19.0.3' (using password: YES)") (Background on this error at: http://sqlalche.me/e/e3q8)
not sure, but running init.sql at the beggining should avoid this error
Upvotes: 0
Views: 972
Reputation: 104
according to https://docs.docker.com/compose/networking/
your DB_HOST should be db
which is your db service name not 0.0.0.0
Upvotes: 1