์ด๋ฒ ํฌ์คํ
์์๋ ๋์ปค ๋ง๋ณด๊ธฐ ์
๋๋ค.
์ ์ฒด์ ์ผ๋ก ์ญ~ ๋ฐ๋ผ๊ฐ๊ธฐ๋ง ํ๋ฉด ๋ฉ๋๋ค :)
1. ์ปจํ ์ด๋ ์์ฑํ๊ธฐ
๋์ปค ์ด๋ฏธ์ง๋ฅผ ์๊ฒฉ ๋ ํฌ์งํ ๋ฆฌ์์๋ถํฐ ๊ฐ์ ธ์ต๋๋ค.
[root@docker /]# docker pull mariadb
Using default tag: latest
latest: Pulling from library/mariadb
d72e567cc804: Pull complete
0f3630e5ff08: Pull complete
b6a83d81d1f4: Pull complete
4bf2111ecf0e: Pull complete
9572d64978a0: Pull complete
bcc9953bffb3: Pull complete
de429570dda5: Pull complete
3652bc6ea9f9: Pull complete
6e4bf87041c8: Pull complete
9cb9bba22391: Pull complete
9de10906fc5c: Pull complete
2c3a798c7a1f: Pull complete
Digest: sha256:9d27dd15564ba13a8ffa93beee20b39b7c14218c47ea296c6e11878a77962d12
Status: Downloaded newer image for mariadb:latest
docker.io/library/mariadb:latest
์ด๋ฏธ์ง๊ฐ ์ ๊ฐ์ ธ์์ก๋์ง ํ์ธํฉ๋๋ค.
[root@docker /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mariadb latest 41fa9265d4df 2 days ago 406MB
์ด์ ์ด ์ด๋ฏธ์ง๋ก ์ปจํ ์ด๋๋ฅผ ๋ง๋ค์ด ์คํํด๋ณด๊ฒ ์ต๋๋ค.
[root@docker /]# docker run --name mariadb-basic -e MYSQL_USER=user -e MYSQL_PASSWORD=P@ssw0rd -e MYSQL_DATABASE=testdb -e MYSQL_ROOT_PASSWORD=P@ssw0rd -d mariadb:latest
8a935d9f0125bbae7f6ca173b72e52bac3b82e71d2cb18ba420df7e68b8d1287
ํ์ฌ ์คํ์ค์ธ ์ปจํ ์ด๋๋ฅผ ํ์ธํฉ๋๋ค.
[root@docker /]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8a935d9f0125 mariadb:latest "docker-entrypoint.s…" 26 minutes ago Up 26 minutes 3306/tcp mariadb-basic
์คํ์ค์ธ ์ปจํ ์ด๋์ Bash ์๋ก ์ ์ํฉ๋๋ค
[root@docker /]# docker exec -it mariadb-basic /bin/bash
์, ์ด์ BashShell์ด ๋ฐ๋์์ฃ ? ์ ์์ ์ผ๋ก ์ ์๋๊ฒ์ ๋๋ค!
์ด์ ์ปจํ ์ด๋๋ก ์ด์๋๊ณ ์๋ Mysql ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์ ์ํด๋ณด๊ณ ์ฌ์ฉํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.
root@8a935d9f0125:/# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.5.5-MariaDB-1:10.5.5+maria~focal mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| testdb |
+--------------------+
4 rows in set (0.000 sec)
MariaDB [(none)]> use testdb
Database changed
MariaDB [testdb]> show tables;
Empty set (0.000 sec)
MariaDB [testdb]> create table Project(id int(11) not null, name varchar(255) default null, code varchar(255) default null, primary key(id));
Query OK, 0 rows affected (0.005 sec)
MariaDB [testdb]> show tables;
+------------------+
| Tables_in_testdb |
+------------------+
| Project |
+------------------+
1 row in set (0.000 sec)
MariaDB [testdb]> insert into Project (id,name,code) values(1,'test','test_code');
Query OK, 1 row affected (0.002 sec)
MariaDB [testdb]> select * from Project;
+----+------+-----------+
| id | name | code |
+----+------+-----------+
| 1 | test | test_code |
+----+------+-----------+
1 row in set (0.000 sec)
2. ์ปจํ ์ด๋ ์ญ์ ํ๊ธฐ
๋จผ์ ์ญ์ ํ๊ธฐ ์ ์ปจํ
์ด๋์ ์ํ๋ฅผ ํ์ธํด๋ด
์๋ค.
ID๊ฐ 8a935d9f0125 ์ธ ์ปจํ
์ด๋๊ฐ ํ๋ ์คํ์ค์ด๋ค์ :)
[root@docker /]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8a935d9f0125 mariadb:latest "docker-entrypoint.s…" About an hour ago Up About an hour 3306/tcp mariadb-basic
์ด ์ปจํ ์ด๋๋ฅผ ์ค์งํ๊ณ ์ํ๋ฅผ ํ์ธํฉ๋๋ค.
[root@docker /]# docker stop mariadb-basic
mariadb-basic
[root@docker /]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8a935d9f0125 mariadb:latest "docker-entrypoint.s…" About an hour ago Exited (0) 6 seconds ago mariadb-basic
์ด์ ์ด ์ปจํ
์ด๋๋ฅผ ์ญ์ ํ๊ณ ์ํ๋ฅผ ํ์ธํฉ๋๋ค.
์ด์์ค์ธ ์ปจํ
์ด๋๊ฐ ๋์ด์ ์กด์ฌํ์ง ์์ต๋๋ค.
[root@docker /]# docker rm mariadb-basic
mariadb-basic
[root@docker /]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
์ด์์ค์ธ ์ปจํ
์ด๋๋ ๋ชจ๋ ์ญ์ ๋์์ผ๋, ์ด๋ฏธ์ง๋ ๋จ์์์ต๋๋ค.
์๋ ๋ช
๋ น์ด๋ก ์ด๋ฏธ์ง ๋ชฉ๋ก์ ํ์ธํ ์ ์์ต๋๋ค.
[root@docker /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mariadb latest 41fa9265d4df 2 days ago 406MB
์ด๋ฏธ์ง๋ฅผ ์ญ์ ํฉ๋๋ค :)
[root@docker /]# docker rmi 41fa9265d4df
Untagged: mariadb:latest
Untagged: mariadb@sha256:9d27dd15564ba13a8ffa93beee20b39b7c14218c47ea296c6e11878a77962d12
Deleted: sha256:41fa9265d4dfb214f0a79ee919392687d09babc3522df21fce946292f9c8149c
Deleted: sha256:fda5c4c21a6b9140242f0d3cfab08c000562528e7569c17ea7688ef1ff66ddcc
Deleted: sha256:d02f487d8a494b36feb2be89182f36f0767fd9343ff2d4f1864813f38e8c2156
Deleted: sha256:9d10f0ce816160514f9382ef9f6065cc5065b3927361337f51e7088931d63930
Deleted: sha256:11ba4bb93a17a1202790f36ec8258a757e2c7fb84f4d307b7e566490f3833d5e
Deleted: sha256:66bd5c2284fb975e1fabc129017f1f7bcd20431d60422fcc21c1d0bfb8e3cf90
Deleted: sha256:717ead24598322b0e93cda5ea93c23f11908949d1520c50af1a77b92a305f9ab
Deleted: sha256:7a377427410270184528b5d75c9fd4d77236f97b2cb7eeecb44215173709b019
Deleted: sha256:e63a805a006f84a5df49f3f458218df6c45b56dbd02fe0c4188d86d1cf4e85ce
Deleted: sha256:5d5e44eeff1c04f804a965d24ac1fbedcb6f33a9df7a57f48f4d4ffd8be80caa
Deleted: sha256:69ea0ba6086b4837bc259353a9dec7e6f7bcc9b8297b0f722387a114697e5691
Deleted: sha256:923b52e8276c042a8602849149a284ae77cccf4c688cc4284bf01ec9669a6e6c
Deleted: sha256:d42a4fdf4b2ae8662ff2ca1b695eae571c652a62973c1beb81a296a4f4263d92
์ด์ ์ด๋ฏธ์ง๊น์ง ๊น๋ํ๊ฒ ์ง์์ก์ต๋๋ค :)
[root@docker /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE