16
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Docker-Composeで3306以外のポートでmysqlを起動

Posted at

複数のMySQLコンテナを建てる時に、一方のポート番号を変更

  • ポートを3307で起動。

version: '3'

services:
  mysql_srv:
    image: mysql:8.0
    volumes:
      - ./docker/mysql/data:/var/lib/mysql
      - ./docker/mysql/conf/my.cnf:/etc/mysql/conf.d/my.cnf
    ports:
      - 3307:3306
    expose:
      - 3307
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=test
      - MYSQL_USER=test
      - MYSQL_PASSWORD=test
      - MYSQL_TCP_PORT=3307
  phpmyadmin_srv:
    image: phpmyadmin/phpmyadmin
    environment:
      - PMA_ARBITRARY=1
      - PMA_HOST=mysql_srv:3307
      - PMA_USER=root
      - PMA_PASSWORD=root
    links:
      - mysql_srv
    ports:
      - 4001:80
    volumes:
      - ./docker/phpmyadmin/sessions:/sessions

  • ポイントは以下。

# フォワードポート部分を変更
    ports:
      - 3307:3306
    expose:
      - 3307

# MYSQLのport設定変更
    environment:
      - MYSQL_TCP_PORT=3307
  • phpMyAdminも変更
  # port番号を設定
  phpmyadmin_srv:
    environment:
      - PMA_HOST=mysql_srv:3307

16
9
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
16
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?