前提・実現したいこと
Docker上で、APP:Django、DB:MySQLの環境を構築したいです。
###【問題】
DockerToolBox上のIPアドレス(192.168.99.100)で確認したときにDjangoのロケットを表示させたいのですが、
サイトにアクセスができない現状です。
http://192.168.99.100:8000/
docker-compose buildし、upをしたときに、WEBアプリの方で下記エラーが出ます。
web_1 | MySQLdb._exceptions.OperationalError: (2002, "Can't connect to MySQL server on 'db' (115)")
【現状】
下記サイトを参照した状態です。
https://qiita.com/cortyuming/items/e587fc045ee7424466b0
下記、Gitの状態です。
- core
-- init.py
-- asgi.py
-- settings.py
-- urls.py
-- wsgi.py
- Dockerfile
- docker-compose.yml
- manage.py
- requirements.txt
- wait-for-it.sh
Dockerfile
1FROM python:3 2ENV PYTHONUNBUFFERED 1 3RUN mkdir -p /var/www/webapp 4WORKDIR /var/www/webapp 5ADD requirements.txt /var/www/webapp/ 6RUN pip install -r requirements.txt 7ADD . /var/www/webapp/
docakr-compose.yml
version: '3' services: db: image: mysql:5.7 command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci volumes: - .:/var/www/webapp restart: always environment: MYSQL_ROOT_PASSWORD: django MYSQL_DATABASE: django MYSQL_USER: django MYSQL_PASSWORD: django web: build: . command: sh -c "./wait-for-it.sh db:3306; python3 manage.py runserver 0.0.0.0:8000" volumes: - .:/var/www/webapp ports: - "8080:8000" depends_on: - db
requirements.txt
Django>=2.0.1 mysqlclient
試したこと
- localhost:8000などにアクセスを行うなどは行いました。
- PostgreSQLで環境を構築することは問題なく行えましたが、MySQLだとエラーが発生してしまう状態です。
エラー(長すぎるため貼らないほうがいいかと思いますが、、)
db_1 | 2020-04-13 11:44:58+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.29-1debian10 started. db_1 | 2020-04-13 11:44:58+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' db_1 | 2020-04-13 11:44:58+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.29-1debian10 started. db_1 | 2020-04-13 11:44:59+00:00 [Note] [Entrypoint]: Initializing database files db_1 | 2020-04-13T11:44:59.073461Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). db_1 | 2020-04-13T11:44:59.346916Z 0 [Warning] InnoDB: New log files created, LSN=45790 db_1 | 2020-04-13T11:44:59.390144Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. db_1 | 2020-04-13T11:44:59.447488Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 34437735-7d7c-11ea-a4a4-0242ac170002. db_1 | 2020-04-13T11:44:59.448534Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. db_1 | 2020-04-13T11:45:00.441638Z 0 [Warning] CA certificate ca.pem is self signed. web_1 | /usr/bin/env: ‘bash\r’: No such file or directory web_1 | Watching for file changes with StatReloader web_1 | Performing system checks... web_1 | web_1 | Exception in thread django-main-thread: web_1 | Traceback (most recent call last): <中略> web_1 | return Database.connect(**conn_params) web_1 | File "/usr/local/lib/python3.8/site-packages/MySQLdb/__init__.py", line 84, in Connect web_1 | return Connection(*args, **kwargs) web_1 | File "/usr/local/lib/python3.8/site-packages/MySQLdb/connections.py", line 179, in __init__ web_1 | super(Connection, self).__init__(*args, **kwargs2) web_1 | MySQLdb._exceptions.OperationalError: (2002, "Can't connect to MySQL server on 'db' (115)") web_1 | web_1 | The above exception was the direct cause of the following exception: web_1 | web_1 | Traceback (most recent call last): <中略> web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/checks/registry.py", line 72, in run_checks web_1 | new_errors = check(app_configs=app_configs) web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/checks/model_checks.py", line 34, in check_all_models web_1 | errors.extend(model.check(**kwargs)) web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/models/base.py", line 1275, in check web_1 | *cls._check_constraints(), web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/models/base.py", line 1841, in _check_constraints web_1 | connection.features.supports_table_check_constraints or web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__ web_1 | res = instance.__dict__[self.name] = self.func(instance) web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/mysql/features.py", line 93, in supports_column_check_constraints web_1 | if self.connection.mysql_is_mariadb: web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__ web_1 | res = instance.__dict__[self.name] = self.func(instance) web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 363, in mysql_is_mariadb web_1 | return 'mariadb' in self.mysql_server_info.lower() web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__ web_1 | res = instance.__dict__[self.name] = self.func(instance) web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 350, in mysql_server_info web_1 | with self.temporary_connection() as cursor: web_1 | File "/usr/local/lib/python3.8/contextlib.py", line 113, in __enter__ web_1 | return next(self.gen) web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 604, in temporary_connection web_1 | with self.cursor() as cursor: web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner web_1 | return func(*args, **kwargs) web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 260, in cursor web_1 | return self._cursor() web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 236, in _cursor web_1 | self.ensure_connection() web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner web_1 | return func(*args, **kwargs) web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection web_1 | self.connect() web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__ web_1 | raise dj_exc_value.with_traceback(traceback) from exc_value web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection web_1 | self.connect() web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner web_1 | return func(*args, **kwargs) web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 197, in connect web_1 | self.connection = self.get_new_connection(conn_params) web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner web_1 | return func(*args, **kwargs) web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 233, in get_new_connection web_1 | return Database.connect(**conn_params) web_1 | File "/usr/local/lib/python3.8/site-packages/MySQLdb/__init__.py", line 84, in Connect web_1 | return Connection(*args, **kwargs) web_1 | File "/usr/local/lib/python3.8/site-packages/MySQLdb/connections.py", line 179, in __init__ web_1 | super(Connection, self).__init__(*args, **kwargs2) db_1 | 2020-04-13T11:45:00.666232Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. db_1 | 2020-04-13 11:45:02+00:00 [Note] [Entrypoint]: Database files initialized db_1 | 2020-04-13 11:45:02+00:00 [Note] [Entrypoint]: Starting temporary server db_1 | 2020-04-13 11:45:02+00:00 [Note] [Entrypoint]: Waiting for server startup db_1 | 2020-04-13T11:45:03.111103Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). db_1 | 2020-04-13T11:45:03.115156Z 0 [Note] mysqld (mysqld 5.7.29) starting as process 75 ... <中略> db_1 | 2020-04-13T11:45:07.887911Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them. db_1 | 2020-04-13T11:45:07.888181Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory. db_1 | 2020-04-13T11:45:07.889414Z 0 [Warning] CA certificate ca.pem is self signed. db_1 | 2020-04-13T11:45:07.889696Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory. db_1 | 2020-04-13T11:45:07.890716Z 0 [Note] Server hostname (bind-address): '*'; port: 3306 db_1 | 2020-04-13T11:45:07.890897Z 0 [Note] IPv6 is available. db_1 | 2020-04-13T11:45:07.891022Z 0 [Note] - '::' resolves to '::'; db_1 | 2020-04-13T11:45:07.891253Z 0 [Note] Server socket created on IP: '::'. db_1 | 2020-04-13T11:45:07.892482Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory. db_1 | 2020-04-13T11:45:07.901810Z 0 [Note] Event Scheduler: Loaded 0 events
あなたの回答
tips
プレビュー