Reputation: 299
I am new to DevOps and I am trying to Dockerize my Django-Mysql connection.My Docker file looks like this:-
FROM python:3.6
ENV PYTHONUNBUFFERED 1
RUN mkdir /docker_dir
WORKDIR /docker_dir
ADD . /docker_dir/
RUN pip install -r requirements.txt
My docker-compose.yml file looks like this:-
version: '3'
services:
db:
image: mysql
restart: always
command: --default-authentication-plugin=mysql_native_password --mysqlx=0
environment:
- MYSQL_HOST=127.0.0.1
- MYSQL_PORT=3306 # cannot change this port to other number
- MYSQL_DATABASE=cgi_assignments # name you want for the database
- MYSQL_USER="root" # change to whatever username you want
- MYSQL_PASSWORD="root" #change to the password you want for user
- MYSQL_ROOT_PASSWORD="root" #change to good root password
ports:
- "3307:3306"
volumes:
- .setup.sql:/docker-entrypoint-initbd.d/setup.sql
web:
build: .
# command: python manage.py runserver 0.0.0.0:8000
command: python manage.py runserver 0.0.0.0:8000
container_name: docker_dir
volumes:
- .:/docker_dir
ports:
- "8000:8000"
depends_on:
- db
links:
- db
and my database on Django settings file looks like this:-
DATABASES = {
'default': {
'NAME': 'cgi_assignments',
'ENGINE': 'django.db.backends.mysql',
'USER': 'root',
'PASSWORD': 'root',
'HOST': 'db',
'PORT': 3306,
},
}
If I use ports:-"3307:3306" it gives me the following error:-
django.db.utils.OperationalError: (1130, "Host '172.18.0.3' is not allowed to connect to this MySQL server")
and I use ports:-"3306:3306" it gives me the following error:-
listen tcp 0.0.0.0:3306: bind: address already in use
Upvotes: 2
Views: 934