ローカル開発ではphpMyAdmin使います。
phpMyAdmin
- http://{ipアドレス}:18080
- http://{ipアドレス}:28080
リモートへのDB接続はMySQL WorkBenchでつなぎます。
もくじ
docker-compose.yaml
version: "3" services: app: build: context: ./docker/php args: - TZ=${TZ} ports: - ${APP_PORT}:8000 volumes: - ${PROJECT_PATH}:/work:cached - ./docker/ash:/etc/profile.d - ./logs:/var/log/php - ./docker/php/php.ini:/usr/local/etc/php/php.ini working_dir: /work environment: - DB_CONNECTION=mysql - DB_HOST=db - DB_DATABASE=${DB_NAME} - DB_USERNAME=${DB_USER} - DB_PASSWORD=${DB_PASS} - TZ=${TZ} - CACHE_DRIVER=redis - SESSION_DRIVER=redis - QUEUE_DRIVER=redis - REDIS_HOST=redis web: image: nginx:1.17.3 depends_on: - app ports: - ${WEB_PORT}:80 volumes: - ${PROJECT_PATH}:/work:cached - ./logs:/var/log/nginx - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf environment: - TZ=${TZ} - ROOT_DIR=${ROOT_DIR} - PUBLIC_DOMAIN=${PUBLIC_DOMAIN} db: build: context: ./docker/mysql volumes: - db-store:/var/lib/mysql - ./logs:/var/log/mysql - ./docker/mysql/my.cnf:/etc/mysql/conf.d/my.cnf environment: - MYSQL_DATABASE=${DB_NAME} - MYSQL_USER=${DB_USER} - MYSQL_PASSWORD=${DB_PASS} - MYSQL_ROOT_PASSWORD=${DB_PASS} - TZ=${TZ} ports: - ${DB_PORT}:3306 log_db: container_name: log_db build: context: ./docker/mysql volumes: - ./logs:/var/log/mysql - ./docker/mysql/my.cnf:/etc/mysql/conf.d/my.cnf - ./docker/mysql/sql:/docker-entrypoint-initdb.d environment: - MYSQL_DATABASE=${LOG_DB_NAME} - MYSQL_USER=${LOG_DB_USER} - MYSQL_PASSWORD=${LOG_DB_PASS} - MYSQL_ROOT_PASSWORD=${LOG_DB_PASS} - TZ=${TZ} ports: - ${LOG_DB_PORT}:3306 cap_add: - SYS_ADMIN redis: image: redis:5.0-alpine volumes: - redis-store:/data phpmyadmin: container_name: phpmyadmin image: phpmyadmin/phpmyadmin environment: - PMA_ARBITRARY=1 - PMA_HOSTS=db - PMA_USER=root - PMA_PASSWORD=secret ports: - 18080:80 links: - db phpmyadmin_log: container_name: phpmyadmin_log image: phpmyadmin/phpmyadmin environment: - PMA_ARBITRARY=1 - PMA_HOSTS=log_db - PMA_USER=root - PMA_PASSWORD=secret ports: - 28080:80 links: - log_db volumes: db-store: redis-store:
.env
COMPOSE_PROJECT_NAME=app PROJECT_PATH=./src ROOT_DIR=/work PUBLIC_DOMAIN=auth.app-local TZ=Asia/Tokyo WEB_PORT=10080 APP_PORT=18000 DB_PORT=13306 DB_NAME=homestead DB_USER=homestead DB_PASS=secret # Log DB LOG_DB_PORT=23306 LOG_DB_NAME=log_db LOG_DB_USER=homestead LOG_DB_PASS=secret
初期にsqlを発行したい
初期に実行したいsqlのファイルを「./docker/mysql/sql/sample.sql」においておくと、
$ docker-compose down $ docker-compose up -d
コマンド実行時に実行されます。