1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ローカル開発環境でDBが必要なときに使う手法(私的)

Last updated at Posted at 2021-10-15
docker-compose.yml
services:
  api:
    image: python:3.11
    ports:
      - "8001:8000"
    volumes:
      - ./backend/app:/app
      - ./backend/static:/app/static
    environment:
      - DATABASE_URL=mysql+pymysql://root:password@mysql:3306/database
    depends_on:
      mysql:
        condition: service_healthy
    working_dir: /app
    command: >
      bash -c "pip install -r requirements.txt &&
      python -m alembic upgrade head &&
      python main.py"

  mysql:
    image: mysql:5.7
    environment:
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_USER=user
      - MYSQL_PASSWORD=password
      - MYSQL_DATABASE=database
      - TZ=Asia/Tokyo
    volumes:
      - ./database/data:/var/lib/mysql
    ports:
      - 3306
    command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-ppassword"]
      start_period: 10s
      interval: 10s
      timeout: 5s
      retries: 10

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:5.1.1
    depends_on:
      mysql:
        condition: service_healthy
    ports:
    - 8081:80
    environment:
      - PMA_ARBITRARY=1
      - PMA_HOST=mysql
      - PMA_USER=root
      - PMA_PASSWORD=password
      - PMA_PORT=3306

2021-10-16_06h28_30.jpg

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?