본문 바로가기

Data Engineering

[Docker] Docker 설치 및 환경설정

sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
sudo dnf install docker-ce docker-ce-cli containerd.io
[root@localhost rocky]# usermod -aG docker rocky

설치된 docker version 확인

systemctl start docker
systemctl enable docker
newgrp docker
docker run hello-world

[root@localhost ~]# docker run --rm -it ubuntu:16.04 /bin/bash
Unable to find image 'ubuntu:16.04' locally
16.04: Pulling from library/ubuntu
58690f9b18fc: Pull complete 
b51569e7c507: Pull complete 
da8ef40b9eca: Pull complete 
fb15d46c38dc: Pull complete 
Digest: sha256:1f1a2d56de1d604801a9671f301190704c25d604a416f59e03c04f5c6ffee0d6
Status: Downloaded newer image for ubuntu:16.04

Docker 컨테이너 안으로 들어옴

root@30299c12b6d9:/# cat /etc/issue
Ubuntu 16.04.7 LTS \n \l
[root@localhost ~]# docker run -d -p 1234:6379 redis
Unable to find image 'redis:latest' locally
latest: Pulling from library/redis
09f376ebb190: Pull complete 
9ae6a7172b01: Pull complete 
2c310454138b: Pull complete 
3eba9ec960aa: Pull complete 
3d36c165ff0a: Pull complete 
493d196d734f: Pull complete 
4f4fb700ef54: Pull complete 
484e0560ae90: Pull complete 
Digest: sha256:01afb31d6d633451d84475ff3eb95f8c48bf0ee59ec9c948b161adb4da882053
Status: Downloaded newer image for redis:latest
3352e7153db3d2644e469e594be11e2b865a568b22d9a5689f47c50239f941e1
[root@localhost ~]# docker run -d -p 1235:6379 redis
8b34ead13a40a599bbf7ac4d19fc547035ee2434b2e7e9ef58126198d8cc7a6c
[root@localhost ~]# telnet localhost 1235
Trying ::1...
Connected to localhost.
Escape character is '^]'.


set mykey hello //명령
+OK

get mykey  //명령
$5
hello
set age 30 //명령
+OK
get age //명령
$2
30

Docker MySQL 접속

[root@localhost ~]# docker run -d -p 3307:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=true --name mysql mysql:5.7
[root@localhost ~]# mysql -h127.0.0.1 -uroot -p
Enter password:

다시 MySQL 접속

[root@localhost ~]# docker stop mysql
docker mysql
[root@localhost ~]# docker rm mysql
mysql
[root@localhost ~]# docker ms
docker: 'ms' is not a docker command.
See 'docker --help'
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@localhost ~]# docker run -d -p 3307:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=true --name mysql mysql:5.7
3049458773e110946afb91bba26e9511293bb65b2958f535e7e7507561bd7814
^[[A[root@localhost mysql -h127.0.0.1 -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.30 Source distribution

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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>