DockerをDjangoで使用しようとしていますが、エラーdb_1 | error: database is uninitialized and password option is not specified db_1 | You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' (111)")
が発生します。私がDockerなしで私のアプリを使用しているとき、それは動作します。助言がありますか?DockerでDjangoを使用する際にエラーが発生しました - 「127.0.0.1(111)」のMySQLサーバーに接続できません)
マイDockerfile:
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
マイドッキングウィンドウ-compose.yml:
version: '3'
services:
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: ""
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
web:
build: .
command: python3 virtualPRI/PRI/backend/pri/manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
が、この瞬間のプロセスへの:
version: '3'
services:
db:
image: mysql
web:
build: .
command: python3 Project/myVirtual/backend/pri/manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
私が変更されているドッキングウィンドウ-compose.yamlへブロックしました
db_1 | 2017-06-13T05:16:16.457122Z 0 [Note] End of list of non-natively partitioned tables
または時々私はまだweb_1 | django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' (111)")
manage:py
を得る:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pri.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
execute_from_command_line(sys.argv)
ドッカーのコマンド/ドッカーの作成ファイル –
@AzatIbrakov私は自分の投稿を更新しました。 –
コンテナ/イメージを強制的に削除してもう一度試してみてください –