0

docker-compose.yml

version: "3.7" services: db: platform: linux/x86_64 image: mysql:5.7 volumes: - ./db_data1:/var/lib/mysql environment: MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}" MYSQL_DATABASE: "${DB_DATABASE}" MYSQL_USER: "${DB_USER}" MYSQL_PASSWORD: "${DB_ROOT_PASSWORD}" ports: - 3306:3306 command: - --character-set-server=utf8mb4 - --collation-server=utf8mb4_unicode_ci web: build: dockerfile: ./Dockerfile command: python3 manage.py runserver 0.0.0.0:8000 volumes: - ./web_data1:/app ports: - 8000:8000 environment: DJANGO_DB_HOST: db:3306 DJANGO_DB_NAME: "${DB_DATABASE}" DJANGO_DB_USER: "${DB_USER}" DJANGO_DB_PASSWORD: "${DB_ROOT_PASSWORD}" 

my_setting.py

DATABASES = { 'default' : { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'test', 'USER': 'root', 'PASSWORD': "${DB_ROOT_PASSWORD}", 'HOST': 'db', 'PORT': '3306', } } SECRET = 'django-insecure-#kb%p45em8hdhja^+2jal#(*mzw1c3jk5gvsx(_cn@q^u@u&b0' ALGORITHM = 'HS256' 

Dockerfile

FROM python:3 ENV PYTHONUNBUFFERED=1 WORKDIR /usr/src/app COPY requirements.txt ./ RUN pip install -r requirements.txt COPY . . EXPOSE 8000 CMD ["gunicorn", "--bind", "0.0.0.0:8000", "docker_train.wsgi:application"]

.env

DB_ROOT_PASSWORD=password DB_DATABASE=test DB_USER=root 

I run docker-compose up but got this error. How can I approach it to solve the problem?

error

docker-training11-db-1 | 2021-11-09 05:14:47+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started. docker-training11-web-1 | Watching for file changes with StatReloader docker-training11-web-1 | Performing system checks... 
1
  • 1
    What you have posted is no error. Commented Nov 9, 2021 at 5:27

1 Answer 1

0

As I am able to identify, you are facing some issue with your DATABASE details. Kindly verify them first.

django is not able to resolve db host name. instead of 'db' try passing private ip of base machine.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.