Docker 로 mysql을 사용해보자

도커에서 mysql을 탐색

$docker search mysql

도커에서 pull을 사용하여 이미지를 다운받는다. 최신버전으로 다운받아야지 !

daeyunkim@kdy:~$docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
fc7181108d40: Pull complete
787a24c80112: Pull complete
a08cb039d3cd: Pull complete
4f7d35eb5394: Pull complete
5aa21f895d95: Pull complete
a742e211b7a2: Pull complete
0163805ad937: Pull complete
87f18876c3ff: Pull complete
78082f25f167: Pull complete
0a510f055c17: Pull complete
312b0999e433: Pull complete
f864cfdc0264: Pull complete
Digest: sha256:415ac63da0ae6725d5aefc9669a1c02f39a00c574fdbc478dfd08db1e97c8f1b
Status: Downloaded newer image for mysql:latest

도커 이미지 확인

daeyunkim@kdy:~$docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               latest              c7109f74d339        12 days ago         443MB

mysql 도커 실행하기

daeyunkim@kdy:~$docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password --name mysql_dev mysql

-p 3306:3306에서 처음의 3306은 호스트의 포트, 뒤에 3306은 컨테이너의 3306포트를 말한다.

호스트에 3306 포트 접근이 발생하면, 해당 컨테이너에 접속이 된다.

-e MYSQL_ROOT_PASSWORD=password 는 컨테이너를 생성하면서 환경변수를 지정

—name 은 컨테이너의 이름

실행되고 있는지 확인 하기

daeyunkim@kdy:~$docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
78f643c1569b        mysql               "docker-entrypoint.s…"   4 seconds ago       Up 2 seconds        0.0.0.0:3306->3306/tcp, 33060/tcp   mysql_dev

Mysql 컨테이너에 접속을 해보자

daeyunkim@kdy:~$docker exec -i -t mysql_dev bash
root@78f643c1569b:/#

최신의 버전의 mysql의 버전을 확인해보자

root@78f643c1569b:/# mysql --version
mysql  Ver 8.0.16 for Linux on x86_64 (MySQL Community Server - GPL)

Mysql 접속하기

root@78f643c1569b:/# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.16 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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>

참고 사이트 :

https://subicura.com/2017/01/19/docker-guide-for-beginners-1.html

https://jayden-lee.github.io/post/docker/mysql-install/

https://blog.hanumoka.net/2018/04/29/docker-20180429-docker-install-mysql/

+ Recent posts