๐ŸŒฑ Infra/Container_Docker

[Docker-Basic (2)] ์ปจํ…Œ์ด๋„ˆ ์‚ด์ง ๋ง›๋ณด๊ธฐ :)

mini_world 2020. 9. 28. 11:35
๋ชฉ์ฐจ ์ ‘๊ธฐ


์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” ๋„์ปค ๋ง›๋ณด๊ธฐ ์ž…๋‹ˆ๋‹ค.
์ „์ฒด์ ์œผ๋กœ ์ญ‰~ ๋”ฐ๋ผ๊ฐ€๊ธฐ๋งŒ ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค :)

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
728x90