I was trying to run a Django project with Docker + Nginx + MySQL, by following this Link After successfull build, by running
docker-compose up --build
Here is my setting.py Database connection
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'smartCut',
'USER': 'antu',
'PASSWORD': 'secure',
'HOST': 'mysql',
'PORT': 3306,
}
}
If I use HOST: 'mysql'
(1045, "Access denied for user 'antu'@'172.25.0.3' (using password: YES)")
Error But If I use If I use HOST: 'localhost'
(2002, "Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)")
Also, this project cannot find the static file in the admin panel.
Whats I'm doing wrong?
Update:
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
07a5a13e15a1 projectone_web "nginx -g 'daemon of…" 16 seconds ago Up 8 seconds 0.0.0.0:8888->80/tcp web
2431afe3eed2 projectone_python "uwsgi --ini /uwsgi.…" 21 seconds ago Up 17 seconds python
83572753b4ae projectone_mysql "docker-entrypoint.s…" 56 seconds ago Up 52 seconds (healthy) 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
docker-compose.yml
version: "2.4"
services:
web:
container_name: web
build: ./docker/nginx
ports:
- 8888:80
volumes:
- ./app:/var/www/html
working_dir: /etc/nginx
links:
- python
python:
container_name: python
build: ./docker/python
volumes:
- ./app:/var/www/html
working_dir: /var/www/html
depends_on:
mysql:
condition: service_healthy
mysql:
build: docker/mysql
container_name: mysql
ports:
- 3306:3306
volumes:
- data-volume:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=secure
- MYSQL_DATABASE=smartCut
healthcheck:
test: "exit 0"
volumes:
data-volume:
$ docker logs 83572753b4ae
2019-07-21T10:00:06.327977Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2019-07-21T10:00:06.328151Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.16) starting as process 1
2019-07-21T10:00:06.332333Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2019-07-21T10:00:12.001312Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2019-07-21T10:00:12.150341Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2019-07-21T10:00:12.290955Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.16' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
2019-07-21T10:00:12.817464Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
app/config/settings.pyfile and the database configuration? Show this file.USERshould berootin your database settings. And also leavemysqlas host.