docker db 활용
1. docker 설치
2. db 이미지 다운로드
docker pull postgres
docker pull mariadb
docker pull mysql
docker pull sath89/oracle-xe-11g
3. 다운 받은 이미지 확인
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
postgres latest 45e33d1af449 7 days ago 228MB
mariadb latest 520fc647a087 8 weeks ago 403MB
ubuntu latest c9d990395902 4 months ago 113MB
mysql latest 5195076672a7 5 months ago 371MB
sath89/oracle-xe-11g latest 04851454491b 13 months ago 792MB
$
4. mysql 접속환경 구성
# 컨테이너 생성
$ docker run -d –name MYSQL_DB -p 3306:3306 -e MYSQL_ROOT_PASSWORD=1234 mysql
305bd69c592ef5e2e0ca9e3e704cdb5b72e7b673e25760576101348afe4efe08
# 컨테이너 쉘접속
$ docker exec -it MYSQL_DB /bin/bash
root@305bd69c592e:/#
# 접속
root@305bd69c592e:/# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.21 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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>
5. mariaDB 접속환경 구성
# 컨테이너 생성
$ docker run -d –name MARIADB_DB -p 3306:3306 -e MYSQL_ROOT_PASSWORD=1234 mariadb
3a31714f6f7322c665a78dedf3c20f9b58971bd0a3512411f151876eab5b326c
# 컨테이너 쉘접속
$ docker exec -it MARIADB_DB /bin/bash
root@3a31714f6f73:/#
# 접속
root@3a31714f6f73:/# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.8-MariaDB-1:10.3.8+maria~jessie 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)]>
6. postgres
# 컨테이너 생성
$ docker run –name POSTGRES_DB -e POSTGRES_PASSWORD=1234 -p 5432:5432 -d postgres
62ffaaa4fee3ac639f7e9a6eb3058aa2034959ae2d8b609063645f4a1f116cac
# 컨테이너 쉘접속
$ docker exec -it POSTGRES_DB /bin/bash
root@62ffaaa4fee3:/#
# 접속
root@62ffaaa4fee3:/# psql –host=127.0.0.1 –port=5432 –username=postgres
psql (10.5 (Debian 10.5-1.pgdg90+1))
Type “help” for help.
postgres=#
7. oracle
# 컨테이너 생성
$ docker run –name ORACLE_XE_11G_DB -e ORACLE_ALLOW_REMOTE=true -p 8080:8080 -p 1521:1521 -d sath89/oracle-xe-11g
ba9d640beda40ac80742fd143a25c7442f581d711344a80dcb592a798a249644
# 컨테이너 쉘접속
$ docker exec -it ORACLE_XE_11G_DB /bin/bash
root@ba9d640beda4:/#
# 접속
root@ba9d640beda4:/# sqlplus
SQL*Plus: Release 11.2.0.2.0 Production on Thu Aug 30 04:29:27 2018
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Enter user-name: system
Enter password:
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 – 64bit Production
SQL>
8. 설치된 컨테이너 확인
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ba9d640beda4 sath89/oracle-xe-11g “/entrypoint.sh ” 21 minutes ago Up 2 minutes 0.0.0.0:1521->1521/tcp, 0.0.0.0:8080->8080/tcp ORACLE_XE_11G_DB
62ffaaa4fee3 postgres “docker-entrypoint.s…” 2 hours ago Up 5 minutes 0.0.0.0:5432->5432/tcp POSTGRES_DB
3a31714f6f73 mariadb “docker-entrypoint.s…” 2 hours ago Exited (137) 16 minutes ago MARIADB_DB
305bd69c592e mysql “docker-entrypoint.s…” 2 hours ago Up 1 second 0.0.0.0:3306->3306/tcp MYSQL_DB
9. 컨테이너 실행 중지
$ docker kill 305bd69c592e
305bd69c592e
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ba9d640beda4 sath89/oracle-xe-11g “/entrypoint.sh ” 22 minutes ago Up 3 minutes 0.0.0.0:1521->1521/tcp, 0.0.0.0:8080->8080/tcp ORACLE_XE_11G_DB
62ffaaa4fee3 postgres “docker-entrypoint.s…” 2 hours ago Up 7 minutes 0.0.0.0:5432->5432/tcp POSTGRES_DB
3a31714f6f73 mariadb “docker-entrypoint.s…” 2 hours ago Exited (137) 18 minutes ago MARIADB_DB
305bd69c592e mysql “docker-entrypoint.s…” 2 hours ago Exited (137) 34 seconds ago MYSQL_DB
$
10. 컨테이너 다시 시작
$ docker start MARIADB_DB
MARIADB_DB
$ docker ps -a
\CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ba9d640beda4 sath89/oracle-xe-11g “/entrypoint.sh ” 22 minutes ago Up 4 minutes 0.0.0.0:1521->1521/tcp, 0.0.0.0:8080->8080/tcp ORACLE_XE_11G_DB
62ffaaa4fee3 postgres “docker-entrypoint.s…” 2 hours ago Up 7 minutes 0.0.0.0:5432->5432/tcp POSTGRES_DB
3a31714f6f73 mariadb “docker-entrypoint.s…” 2 hours ago Up 14 seconds 0.0.0.0:3306->3306/tcp MARIADB_DB
305bd69c592e mysql “docker-entrypoint.s…” 2 hours ago Exited (137) About a minute ago MYSQL_DB
$
11. 컨테이너 삭제.
$ docker rm 305bd69c592e
305bd69c592e
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ba9d640beda4 sath89/oracle-xe-11g “/entrypoint.sh ” 23 minutes ago Up 4 minutes 0.0.0.0:1521->1521/tcp, 0.0.0.0:8080->8080/tcp ORACLE_XE_11G_DB
62ffaaa4fee3 postgres “docker-entrypoint.s…” 2 hours ago Up 8 minutes 0.0.0.0:5432->5432/tcp POSTGRES_DB
3a31714f6f73 mariadb “docker-entrypoint.s…” 2 hours ago Up About a minute 0.0.0.0:3306->3306/tcp MARIADB_DB
$
12. 이미지 삭제
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
postgres latest 45e33d1af449 7 days ago 228MB
mariadb latest 520fc647a087 8 weeks ago 403MB
ubuntu latest c9d990395902 4 months ago 113MB
node latest aa3e171e4e95 4 months ago 673MB
mysql latest 5195076672a7 5 months ago 371MB
kalilinux/kali-linux-docker latest b8fe82f15421 6 months ago 749MB
sath89/oracle-xe-11g latest 04851454491b 13 months ago 792MB
$
$ docker rmi 5195076672a7
Untagged: mysql:latest
Untagged: mysql@sha256:691c55aabb3c4e3b89b953dd2f022f7ea845e5443954767d321d5f5fa394e28c
Deleted: sha256:5195076672a7e30525705a18f7d352c920bbd07a5ae72b30e374081fe660a011
Deleted: sha256:bc52f6d08bc65c22baab4384ae534d4c5ba8c988197de49975e0a0f78310dd89
Deleted: sha256:b2590548a0917767b420cf20d0cef3aae8912314de216f624c0840f3ad827aa7
Deleted: sha256:756d63a7d5896b52d445ea84ee392cb08a7c119322cfcdfed6303de1ed0d0eab
Deleted: sha256:8e4736576db75536185beba95c5877deeb3915740688cbbc17fe04aed3632282
Deleted: sha256:e6e6e1bb8a16eadbe6628770767615fbc8d67bf11dde69a902116efe847baa7e
Deleted: sha256:080b6c4ec1d55d91a7087e12ae3bd4df252148d94f9911209e0a83d50dc63784
Deleted: sha256:58b97da9f98f75af01ae59c3cb1fdd07a07297015459f3f9f88b140699b29147
Deleted: sha256:3918448e7fe95f36f67a55c938559bab787249b8fa5c7e9914afd46994d045b0
Deleted: sha256:fac8373d1ec4f5bb6c13f12170f558edc3cfbfe8215ae3d1c869940401bc14cf
Deleted: sha256:130f3e567e288fdbbc3ae7cd7aa6c8b3d952bebd3eae58f0a7da93acbb22a258
Deleted: sha256:3358360aedad76edf49d0022818228d959d20a4cccc55d01c32f8b62e226e2c2
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
postgres latest 45e33d1af449 7 days ago 228MB
mariadb latest 520fc647a087 8 weeks ago 403MB
ubuntu latest c9d990395902 4 months ago 113MB
node latest aa3e171e4e95 4 months ago 673MB
kalilinux/kali-linux-docker latest b8fe82f15421 6 months ago 749MB
sath89/oracle-xe-11g latest 04851454491b 13 months ago 792MB
$