docker ps -a 명령어로 컨테이너 생성 및 실행 후 정상적으로 실행되고 있는지 확인할 수 있다.
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
70c1ef9b8e8c 772571a08c67 "docker-entrypoint.s…" 56 minutes ago Up 50 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp mysql-container
실행중인 MySQL 도커 컨테이너 시작/중지/재시작 하려면 다음과 같은 명령어를 사용해야 한다.
# MySQL 도커 컨테이너 중지
$ docker stop mysql-container
# MySQL Docker 컨테이너 시작
$ docker start mysql-container
# MySQL 도커 컨테이너 재시작
$ docker restart mysql-container
5. 실행중인 MySQL 도커 컨테이너 접속
docker exec 명령어를 사용하여 도커 Docker 컨테이너를 정상적으로 실행했으면 컨테이너에 접속한다.
컨테이너에 접속해 MySQL 에도 접속하여 원하는 작업을 수행할 수 있다.
$ docker exec -it mysql-container bash
bash-4.4# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 20
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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| library |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.01 sec)
mysql>