IT 한길

Docker 이미지 다운로드

[root@localhost]# docker pull mysql:8.0.21
8.0.21: Pulling from library/mysql
bf5952930446: Pull complete 
8254623a9871: Pull complete 
938e3e06dac4: Pull complete 
ea28ebf28884: Pull complete 
f3cef38785c2: Pull complete 
894f9792565a: Pull complete 
1d8a57523420: Pull complete 
6c676912929f: Pull complete 
ff39fdb566b4: Pull complete 
fff872988aba: Pull complete 
4d34e365ae68: Pull complete 
7886ee20621e: Pull complete 
Digest: sha256:c358e72e100ab493a0304bda35e6f239db2ec8c9bb836d8a427ac34307d074ed
Status: Downloaded newer image for mysql:8.0.21
[root@localhost ]# docker images
REPOSITORY                              TAG                 IMAGE ID            CREATED             SIZE
mysql                                   8.0.21              0d64f46acfd1        2 weeks ago         544MB

 

Start a mysql server instance

  • docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
  • docker run --name some-mysql -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
  • docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
  • docker run -v "$PWD/data":/var/lib/mysql --user 1000:1000 --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
[root@localhost ~]# docker run -v "$PWD/mysqldata":/var/lib/mysql --name portal-mysql -e MYSQL_ROOT_PASSWORD=password -p 3306:3306 -d mysql:8.0.21 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

ad278df3e1af9dc50649027516dd186bae914083021a692d240f9c5fa5c913aa
[root@localhost ~]# 
[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE                                          COMMAND                  CREATED             STATUS                           PORTS                                              NAMES
ad278df3e1af        mysql:8.0.21                                   "docker-entrypoint.s   6 seconds ago       Up 5 seconds                     0.0.0.0:3306->3306/tcp, 33060/tcp                  portal-mysql

Mysql 접속

[root@localhost ~]# docker exec -it portal-mysql bash
root@ad278df3e1af:/#

root@ad278df3e1af:/# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.21 MySQL Community Server - GPL

Copyright (c) 2000, 2020, 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>