1
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 1 year has passed since last update.

【Docker】MySQLをコンテナで起動するまで

Last updated at Posted at 2023-05-01

やりたいこと

Docker上でMySQLのサーバーを立ち上げ、ターミナル上で動作確認をしたい。

Dockerfileを用意する

適当に新規ディレクトリを作成し、Dockerfileを新規作成します。

Dockerfile
# 最新バージョンのMySQLイメージを指定
FROM mysql:latest 

# ルートユーザーのパスワードを"rootpass"として環境変数を定義
ENV MYSQL_ROOT_PASSWORD=rootpass

コンテナを起動する

コンテナイメージを作成

Dockerコンテナを起動するためには、DockerfileからDockerイメージをビルドする必要があります。

docker build -t mysql-test .

コンテナを起動

docker run mysql-test -d

動作確認をする

docker ps

このコマンドで起動中のコンテナを一覧表示させます。

CONTAINER ID   IMAGE        COMMAND                  CREATED          STATUS          PORTS                 NAMES
ffb34b43b73b   mysql-test   "docker-entrypoint.s…"   22 seconds ago   Up 21 seconds   3306/tcp, 33060/tcp   youthful_noyce
docker exec -it ffb34b43b73b /bin/bash
bash-4.4# 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.33 MySQL Community Server - GPL

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)
1
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
1
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?