I'm trying to pack my working student application into containers. Here is my docker-compose.yaml:
version: "3.8"
services:
mysql_db:
build:
context: .
dockerfile: ./docker/mysql/Dockerfile
restart: unless-stopped
env_file: env.dev
ports:
- "33061:3306"
networks:
- autopark_network
backend:
build:
context: .
dockerfile: docker/django/Dockerfile
env_file: env.dev
restart: on-failure
depends_on:
- mysql_db
working_dir: "/app/autopark"
expose:
- 800
ports:
- "8001:8000"
command: ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
networks:
- autopark_network
networks:
autopark_network:
Here is env.dev:
DEBUG=1
SECRET_KEY=<...>
DJANGO_ALLOWED_HOSTS="localhost 127.0.0.1 [::1]"
MYSQL_ENGINE=django.contrib.gis.db.backends.mysql
MYSQL_DATABASE=autopark
MYSQL_DATABASE_HOST=mysql_db
MYSQL_DATABASE_PORT=33061
MYSQL_ROOT_PASSWORD=<...>
MYSQL_USER=pavel
MYSQL_PASSWORD=<...>
I thought that both of my services will get those environment variables so I can be sure everything is ok. As if.
I need GDAL for my project, that's why I started backend not with python but with ubuntu (here's my Dockerfile for backend):
FROM ubuntu:22.04
MAINTAINER Pavel Vasilev <pvlvslv@yandex.ru>
RUN apt -y update
RUN apt -y install python3-dev python3-pip gdal-bin gdal-data
WORKDIR /app/autopark
ADD . /app/autopark
RUN pip install -r requirements.txt
Then I need initialization for my mysql_db (here's my Dockerfile for mysql_db):
FROM mysql/mysql-server:latest
COPY ./docker/mysql/init_db.sh /docker-entrypoint-initdb.d/
COPY ./docker/mysql/init_db.sql /usr/local/
RUN chmod +x /docker-entrypoint-initdb.d/init_db.sh
And here is init_db.sh:
#!/bin/bash
mysql -u root --password="$MYSQL_ROOT_PASSWORD" << EOF
SOURCE /usr/local/init_db.sql
USE ${MYSQL_DATABASE};
GRANT ALL PRIVILEGES ON ${MYSQL_DATABASE}.* TO '${MYSQL_USER}';
EOF
init_db.sql was made this way with mysqldump.
When I do docker-compose build
everything goes smooth. When I go docker-compose up
, I have this:
Recreating autopark_docker_mysql_db_1 ... done
Recreating autopark_docker_backend_1 ... done
Attaching to autopark_docker_mysql_db_1, autopark_docker_backend_1
mysql_db_1 | [Entrypoint] MySQL Docker Image 8.0.32-1.2.11-server
mysql_db_1 | [Entrypoint] Initializing database
mysql_db_1 | 2023-03-29T05:11:30.618219Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
mysql_db_1 | 2023-03-29T05:11:30.622277Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.32) initializing of server in progress as process 17
mysql_db_1 | 2023-03-29T05:11:30.653228Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
mysql_db_1 | 2023-03-29T05:11:31.643747Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
backend_1 | Watching for file changes with StatReloader
backend_1 | Exception in thread django-main-thread:
backend_1 | Traceback (most recent call last):
<... skip ...>
backend_1 | ConnectionRefusedError: [Errno 111] Connection refused
backend_1 |
backend_1 | During handling of the above exception, another exception occurred:
backend_1 |
backend_1 | Traceback (most recent call last):
<... skip ...>
backend_1 | pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'mysql_db' ([Errno 111] Connection refused)")
backend_1 |
backend_1 | The above exception was the direct cause of the following exception:
backend_1 |
backend_1 | Traceback (most recent call last):
<... skip ...>backend_1 | django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on 'mysql_db' ([Errno 111] Connection refused)")
mysql_db_1 | 2023-03-29T05:11:33.028156Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
mysql_db_1 | [Entrypoint] Database initialized
mysql_db_1 | 2023-03-29T05:11:36.080939Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
mysql_db_1 | 2023-03-29T05:11:36.084369Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.32) starting as process 58
mysql_db_1 | 2023-03-29T05:11:36.120288Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
mysql_db_1 | 2023-03-29T05:11:36.339612Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql_db_1 | 2023-03-29T05:11:36.668690Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
mysql_db_1 | 2023-03-29T05:11:36.669242Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
mysql_db_1 | 2023-03-29T05:11:36.689594Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
mysql_db_1 | 2023-03-29T05:11:36.690338Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.32' socket: '/var/lib/mysql/mysql.sock' port: 0 MySQL Community Server - GPL.
mysql_db_1 | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
mysql_db_1 | Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
mysql_db_1 | Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
mysql_db_1 | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
mysql_db_1 | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
mysql_db_1 |
mysql_db_1 | [Entrypoint] running /docker-entrypoint-initdb.d/init_db.sh
mysql_db_1 | mysql: [Warning] Using a password on the command line interface can be insecure.
mysql_db_1 | ERROR 1046 (3D000) at line 22 in file: '/usr/local/init_db.sql': No database selected
mysql_db_1 | [Entrypoint] Starting MySQL 8.0.32-1.2.11-server
mysql_db_1 | 2023-03-29T05:11:40.431294Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
mysql_db_1 | 2023-03-29T05:11:40.433961Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.32) starting as process 1
mysql_db_1 | 2023-03-29T05:11:40.443031Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
mysql_db_1 | 2023-03-29T05:11:41.798794Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql_db_1 | 2023-03-29T05:11:41.939345Z 0 [System] [MY-010229] [Server] Starting XA crash recovery...
mysql_db_1 | 2023-03-29T05:11:41.958108Z 0 [System] [MY-010232] [Server] XA crash recovery finished.
mysql_db_1 | 2023-03-29T05:11:42.002608Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
mysql_db_1 | 2023-03-29T05:11:42.002949Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
mysql_db_1 | 2023-03-29T05:11:42.016603Z 0 [ERROR] [MY-010259] [Server] Another process with pid 60 is using unix socket file.
mysql_db_1 | 2023-03-29T05:11:42.016825Z 0 [ERROR] [MY-010268] [Server] Unable to setup unix socket lock file.
mysql_db_1 | 2023-03-29T05:11:42.016932Z 0 [ERROR] [MY-010119] [Server] Aborting
mysql_db_1 | 2023-03-29T05:11:43.579880Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.32) MySQL Community Server - GPL.
autopark_docker_mysql_db_1 exited with code 1
mysql_db_1 | [Entrypoint] Starting MySQL 8.0.32-1.2.11-server
mysql_db_1 | 2023-03-29T05:11:45.384210Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
mysql_db_1 | 2023-03-29T05:11:45.386889Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.32) starting as process 1
mysql_db_1 | 2023-03-29T05:11:45.398475Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
mysql_db_1 | 2023-03-29T05:11:45.602149Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql_db_1 | 2023-03-29T05:11:45.832458Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
mysql_db_1 | 2023-03-29T05:11:45.833092Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
mysql_db_1 | 2023-03-29T05:11:45.834110Z 0 [ERROR] [MY-010259] [Server] Another process with pid 60 is using unix socket file.
mysql_db_1 | 2023-03-29T05:11:45.834490Z 0 [ERROR] [MY-010268] [Server] Unable to setup unix socket lock file.
mysql_db_1 | 2023-03-29T05:11:45.834832Z 0 [ERROR] [MY-010119] [Server] Aborting
mysql_db_1 | 2023-03-29T05:11:47.380031Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.32) MySQL Community Server - GPL.
And the last part goes on repeat.
I think I failed with initializing mysql after installation but I don't know where. Spend two days already and all ideas are mixed in my head now.