우분트 에서 도커 만들어 보자
우분트 생성
도커 설치하자~
sudo su -
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update
apt-get install docker-ce
// ce는 community edtion)
docker info
docker -v
root@ip-10-10-10-134:~# docker -v
Docker version 20.10.7, build f0df350
<2> 도커 이미지와 컨테이너
1
이미지 이름?
xxxx/ubuntu:14.04
저장소 이름 / 이미지 이름 / 이미지 버전 이다.
ubuntu::lastest
이미지 이름 : 이미지 버전이다.
2
도커 이미지로 여러개의 컨테이너를 만든다!
3
컨테이너를 만들어보자.
컨테이너 생성
docker run -i -t ubuntu:14.04
root@ip-10-10-10-186:~# docker run -i -t ubuntu:14.04
Unable to find image 'ubuntu:14.04' locally
14.04: Pulling from library/ubuntu
2e6e20c8e2e6: Pull complete
0551a797c01d: Pull complete
512123a864da: Pull complete
Digest: sha256:5c01e896fa6eeaa41f3509c64af668d71d06e318cfe373dabab9d61b9eaf6441
Status: Downloaded newer image for ubuntu:14.04
컨테이너 생성되고 컨테이너 내부로 로그인 되었다.
사용자와 호스트이름으로 표시되면 컨테이너라는 것이다.
root@be3714c54a7d:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
// 호스트의 도커 환경으로 돌아오자.
root@be3714c54a7d:/# exit
exit
root@ip-10-10-10-186:~# ls
get-docker.sh index.html snap
4
docker images
root@ip-10-10-10-186:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 14.04 13b66b487594 2 months ago 197MB
정지 되지 않는 컨테이너만 보는 명령어 ?
docker ps
root@ip-10-10-10-186:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
정지 된 컨테이너도 보는 명령어 ?
docker ps -a
root@ip-10-10-10-186:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
be3714c54a7d ubuntu:14.04 "/bin/bash" 5 minutes ago Exited (0) 4 minutes ago eloquent_hopper
5
컨테이너 name 변경하기 ?
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
be3714c54a7d ubuntu:14.04 "/bin/bash" 14 minutes ago Exited (0) 13 minutes ago eloquent_hopper
docker rename eloquent_hopper sss
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
be3714c54a7d ubuntu:14.04 "/bin/bash" 16 minutes ago Exited (0) 14 minutes ago sss
Exited (0 ) 정상 죵료 상태 = 삭제가 가능하다.
6
컨테이너 삭제하기 ?
docker rm sss
sss
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
root@ip-10-10-10-186:~#
컨테이너 모두 삭제 ?
docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B
7
이미지 내려 받기, 도커 실행 ?
docker pull centos:7
docker run -i -t centos
exit
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b79656c05136 centos "/bin/bash" 45 seconds ago Exited (0) 14 seconds ago nervous_keller
[root@a16303253417 /]# exit
root@ip-10-10-10-186:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b79656c05136 centos "/bin/bash" About a minute ago Up 3 seconds nervous_keller
작동중인 컨테이너는 삭제 못한다. ?
docker rm nervous_keller
Error response from daemon: You cannot remove a running container b79656c05136ef82426325565a418a4383fdac6309e0a786823f96040476e8aa. Stop the container before attempting removal or force remove
root@ip-10-10-
중지후 삭제 가능하다. ?
docker stop b7
b7
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b79656c05136 centos "/bin/bash" 4 minutes ago Exited (0) 3 seconds ago nervous_keller
docker rm b7
b7
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8
모든 컨테이너 중지후 삭제 시키기
docker stop $(docker ps -a -q)
f70477614c15
docker rm $(docker ps -a -q)
f70477614c15
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
root@ip-10-10-10-134:~#
AWS에 ubuntu를 설치해 컨테이너를 만들어 보자.
확인을 위해 windows 서버도 1대 만들자.
<3> 도커 실행
sudo su -
root@ip-10-10-10-134:~# docker run -i -t --name network_test ubuntu:14.04
root@f41a0d7858c1:/# ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:02
inet addr:172.17.0.2 Bcast:172.17.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:9 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:806 (806.0 B) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
<4> Apache 설치
root@ip-10-10-10-134:~# docker run -i -t --name web01 -p 80:80 ubuntu:14.04
apt-get update
apt-get install apache2 -y
service apache2 start
root@39946c9cbf90:/# ps -ef |grep apache
root 698 1 0 01:19 ? 00:00:00 /usr/sbin/apache2 -k start
www-data 700 698 0 01:19 ? 00:00:00 /usr/sbin/apache2 -k start
www-data 701 698 0 01:19 ? 00:00:00 /usr/sbin/apache2 -k start
root 763 1 0 01:20 pts/0 00:00:00 grep --color=auto apache
웹 브라우저로 접속 확인
<5> mysql 이미지 이용해 db 설치
docker run -d --name wordpressdb -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=wordpress mysql:5.7
root@ip-10-10-10-134:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
378354f7ef32 mysql:5.7 "docker-entrypoint.s…" 10 seconds ago Up 9 seconds 3306/tcp, 33060/tcp wordpressdb
<6> wordpress 이미지 이용해 web설치
포트를 보면 80으로 접속
root@ip-10-10-10-134:~# docker run -d --name wordpressdb2 -e MYSQL_ROOT_PASSWORD=password --link wordpressdb:mysql -p 80 wordpress
89c4ea649cd6e74246a53567c7acb773e6a611b6b3399ea13c50e169d9f4956a
root@ip-10-10-10-134:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
89c4ea649cd6 wordpress "docker-entrypoint.s…" 8 seconds ago Up 6 seconds 0.0.0.0:49153->80/tcp, :::49153->80/tcp wordpressdb2
378354f7ef32 mysql:5.7 "docker-entrypoint.s…" 4 minutes ago Up 4 minutes 3306/tcp, 33060/tcp wordpressdb
root@ip-10-10-10-134:~#
5
사용 포트 확인
root@ip-10-10-10-134:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
89c4ea649cd6 wordpress "docker-entrypoint.s…" 6 minutes ago Up 6 minutes 0.0.0.0:49153->80/tcp, :::49153->80/tcp wordpressdb2
378354f7ef32 mysql:5.7 "docker-entrypoint.s…" 10 minutes ago Up 10 minutes 3306/tcp, 33060/tcp wordpressdb
39946c9cbf90 ubuntu:14.04 "/bin/bash" 26 minutes ago Exited (127) 10 minutes ago web01
f41a0d7858c1 ubuntu:14.04 "/bin/bash" 28 minutes ago Exited (127) 27 minutes ago network_test
docker port 컨테이너 id
root@ip-10-10-10-134:~# docker port 89c4ea649cd6
80/tcp -> 0.0.0.0:49153
80/tcp -> :::49153
<7> Windows 서버에 로그온해 웹브라우저로 ip:49153 포트 접속해보자.
https://brunch.co.kr/@topasvga/1649
<20> (정리) 도커,쿠버네티스 실습 - 2021
https://brunch.co.kr/@topasvga/1817
https://brunch.co.kr/@topasvga/1656
<30> 다음 공부
https://brunch.co.kr/@topasvga/1649
감사합니다.