How to create dockerfile & docker compose for django mysql with .env file?

dockerfile

FROM python:3.10

WORKDIR /django_app

ENV PYTHONUNBUFFERED 1

ADD . /django_app

RUN pip install --upgrade pip

RUN pip install -r requirements.txt

COPY . /django_app

docker-compose.yml

version: '3.8'

services:
  db:
    image: mysql:latest
    hostname: mysql
    restart: always
    ports:
      - '3308:3306'
    environment:
       MYSQL_DATABASE: 'test'
       MYSQL_USER : 'mysqluser'
       MYSQL_PASSWORD: 'root123'
       MYSQL_ROOT_PASSWORD: 'root123'
    # volumes:
    #   - D:\django_project\db1:/var/run/mysqld
    #   - D:\django_project\db:/var/lib/mysql
  web:
    build: .
    restart: on-failure  
    command: sh -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
    ports:
      - "8000:8000"
    depends_on:
      - db

[error 1.](https://i.stack.imgur.com/ni4t7.png) error 2

First time create docker build but agine build docker getting errors. Database not connect docker image mysql.

Back to Top