3
2

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のMySQLのパスワードなどを変えたくなったとき

Posted at

表題の通り、こんな感じでmysqlのパスワードを設定しているときの設定値の変え方です。

docker-compose.yml
  mysql:
    image: mysql:5.7.32
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root_pass
      MYSQL_DATABASE: db_name
      MYSQL_USER: user1
      MYSQL_PASSWORD: user1_pass

volumes:
  mysql_data:

普通にdocker-compose.ymlを変更したのち、次のコマンドを実行すると設定値が反映されます。

docker-compose down --volumes
docker-compose up -d

普通にdownしてupしただけだと、パスワードが設定済みのMySQLのデータが使われてしまうのでうまくいきません。
そこで前述のコマンドのようにボリュームを削除させる必要があります。

3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?