Docker & K8S - 우분투(Ubuntu)
각자 Docker 위에서 우분투를 컨테이너로 실행해보자
리눅스 커널과 배포판
리눅스 커널: 리눅스의 핵심부분. (자동차의 엔진)
Linus B. Torvalds가 1992년에 처음 공개

이미지에서 음영칠된 커널은 똑같지만 커널을 감싸는 쉘, 응용 프로그램 등의 패키징 요소가 다른 것을 배포판이라고 부릅니다.
어떤 리눅스 배포판이 있는가?
우분투: 가장 많이 사용되며 데비안에 기반해서 만들어진 리눅스 배포판
데비안
알파인: 임베드 시스템에서 사용할 용도로 만들어진 경량화 리눅스 배포판
페도라
센트OS
기타 …
우분투 설치 후 다양한 명령 실행해보기
보통은 docker image를 pull하고 run을 해야함! 바로 run을 하면?
바로 run을 해도 괜찮습니다. 만일 로컬에 다운로드 받은 이미지가 없다면 docker hub에서 pull을 알아서 수행합니다. 단 Docker Hub와 연결되어 있어야 합니다.
docker run ubuntu
Official IMAGE이므로 어카운트 ID와 네임스페이스
콜론이 없으므로 태그는 자동으로 latest(최신 버전) 다운
docker ps
컨테이너 ID 확인
docker ps -a
-a를 붙이면 실행이 끝난 컨테이너들의 ID들도 확인
docker run -it ubuntu
-it는 interactive 옵션입니다.
ubuntu로 로그인 한뒤 다양한 명령 사용
nano
apt list
apt install nano
apt update
apt install nano
nano
apt remove nano
실습

ubuntu라는 폴더를 만들었고 터미널상에서 그곳으로 이동합니다.
D:\Dev_KDT\ubuntu>docker run ubuntu
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
a48641193673: Pull complete
Digest: sha256:6042500cf4b44023ea1894effe7890666b0c5c7871ed83a97c36c76ae560bb9b
Status: Downloaded newer image for ubuntu:latest
docker run ubuntu를 실행합니다.
처음에는 로컬상에서 ubuntu:latest를 찾을 수 없다고 했지만 곧 알아서 다운을 받습니다.
ubuntu는 Official Image를 제공하기 때문에 어카운트 ID 네임스페이스 없이 다운받을 수 있었습니다.
또한 :(버전)을 주지 않았기 때문에 default로 latest 버전을 다운 받습니다.
눈치채기 힘들지만 사실 이미 컨테이너도 실행이 되었지만 별도의 명령을 주지 않았기 때문에 끝난 상황입니다.
D:\Dev_KDT\ubuntu>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
docker ps로 Container ID를 조회해보니 실행 중인 컨테이너가 없어 어떤 컨테이너도 조회되지 않습니다.
이 때 docker ps에 옵션으로 -a를 주면
D:\Dev_KDT\ubuntu>docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
12345678910a ubuntu "/bin/bash" 4 minutes ago Exited (0) 4 minutes ago agitated_ptolemy
12345678910a apache/airflow:2.5.1 "/usr/bin/dumb-init …" 4 days ago Exited (0) 5 minutes ago airflow-setup-airflow-webserver-1
12345678910a apache/airflow:2.5.1 "/usr/bin/dumb-init …" 4 days ago Exited (0) 5 minutes ago airflow-setup-airflow-triggerer-1
12345678910a apache/airflow:2.5.1 "/usr/bin/dumb-init …" 4 days ago Exited (0) 5 minutes ago airflow-setup-airflow-worker-1
12345678910a apache/airflow:2.5.1 "/usr/bin/dumb-init …" 4 days ago Exited (0) 5 minutes ago airflow-setup-airflow-scheduler-1
12345678910a apache/airflow:2.5.1 "/bin/bash -c 'funct…" 6 days ago Exited (0) 3 days ago airflow-setup-airflow-init-1
12345678910a postgres:13 "docker-entrypoint.s…" 6 days ago Exited (0) 5 minutes ago airflow-setup-postgres-1
12345678910a redis:latest "docker-entrypoint.s…" 6 days ago Exited (0) 5 minutes ago airflow-setup-redis-1
12345678910a apachesuperset.docker.scarf.sh/apache/superset:latest-dev "/app/docker/docker-…" 2 weeks ago Exited (137) 9 days ago superset_app
12345678910a apachesuperset.docker.scarf.sh/apache/superset:latest-dev "/app/docker/docker-…" 2 weeks ago Exited (0) 10 days ago superset_init
12345678910a apachesuperset.docker.scarf.sh/apache/superset:latest-dev "/app/docker/docker-…" 2 weeks ago Exited (137) 9 days ago superset_worker
12345678910a apachesuperset.docker.scarf.sh/apache/superset:latest-dev "/app/docker/docker-…" 2 weeks ago Exited (137) 9 days ago superset_worker_beat
12345678910a postgres:15 "docker-entrypoint.s…" 2 weeks ago Exited (0) 9 days ago superset_db
12345678910a redis:7 "docker-entrypoint.s…" 2 weeks ago Exited (0) 9 days ago superset_cache
실행 여부와 상관없이 모든 컨테이너들이 조회됩니다. 우리가 방금 설치한 ubuntu의 컨테이너도 조회됩니다.
D:\Dev_KDT\ubuntu>docker run -it ubuntu
root@~~:/#
docker run -it ubuntu
-it는 interactive 옵션입니다. ubuntu로 로그인 한뒤 다양한 명령 사용할 수 있습니다.
root@~~:/# nano
bash: nano: command not found
nano를 실행했는데 찾을 수 없다고 뜹니다. 현재 root 유저로 로그인 중이니 여러 어플리케이션 설치가 가능합니다.
apt는 우분투나 데비안 기반 리눅스에서 패키지를 다루는 명령어 입니다.
root@~~:/# apt install nano
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package nano is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'nano' has no installation candidate
apt install nano 명령에도 에러가 나는데 그 이유는 apt가 outdated 상태라 nano가 무엇인지 파악하지 못하는 상황이기 때문입니다. apt를 업데이트 해야합니다.
root@~~:/# apt update
Get:1 http://archive.ubuntu.com/ubuntu jammy InRelease [270 kB]
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:3 http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages [1326 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
Get:5 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [109 kB]
Get:6 http://archive.ubuntu.com/ubuntu jammy/multiverse amd64 Packages [266 kB]
Get:7 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages [1792 kB]
Get:8 http://security.ubuntu.com/ubuntu jammy-security/universe amd64 Packages [1046 kB]
Get:9 http://security.ubuntu.com/ubuntu jammy-security/multiverse amd64 Packages [44.0 kB]
Get:10 http://security.ubuntu.com/ubuntu jammy-security/restricted amd64 Packages [1572 kB]
Get:11 http://archive.ubuntu.com/ubuntu jammy/restricted amd64 Packages [164 kB]
Get:12 http://archive.ubuntu.com/ubuntu jammy/universe amd64 Packages [17.5 MB]
Get:13 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages [1599 kB]
Get:14 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 Packages [1305 kB]
Get:15 http://archive.ubuntu.com/ubuntu jammy-updates/multiverse amd64 Packages [49.8 kB]
Get:16 http://archive.ubuntu.com/ubuntu jammy-updates/restricted amd64 Packages [1602 kB]
Get:17 http://archive.ubuntu.com/ubuntu jammy-backports/universe amd64 Packages [28.1 kB]
Get:18 http://archive.ubuntu.com/ubuntu jammy-backports/main amd64 Packages [50.4 kB]
Fetched 28.9 MB in 24s (1228 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
apt update가 끝났습니다.
root@~~:/# apt install nano
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
hunspell
The following NEW packages will be installed:
nano
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 280 kB of archives.
After this operation, 881 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 nano amd64 6.2-1 [280 kB]
Fetched 280 kB in 2s (185 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package nano.
(Reading database ... 4393 files and directories currently installed.)
Preparing to unpack .../archives/nano_6.2-1_amd64.deb ...
Unpacking nano (6.2-1) ...
Setting up nano (6.2-1) ...
update-alternatives: using /bin/nano to provide /usr/bin/editor (editor) in auto mode
update-alternatives: warning: skip creation of /usr/share/man/man1/editor.1.gz because associated file /usr/share/man/man1/nano.1.gz (of link group editor) doesn't exist
update-alternatives: using /bin/nano to provide /usr/bin/pico (pico) in auto mode
update-alternatives: warning: skip creation of /usr/share/man/man1/pico.1.gz because associated file /usr/share/man/man1/nano.1.gz (of link group pico) doesn't exist
이제 nano의 설치가 정상적으로 수행됩니다.
nano는 텍스트 에디터 입니다. nano를 타이핑해 켜고 필요에 따라 텍스트를 작성 및 저장할 수 있습니다.
root@148c96b69697:/# apt remove nano
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
nano
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 881 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 4466 files and directories currently installed.)
Removing nano (6.2-1) ...
root@148c96b69697:/# nano
bash: /usr/bin/nano: No such file or directory
nano가 더 이상 필요 없다면 apt remove nano를 실행하고 중간에 삭제 여부를 재확인할 때 y로 yes를 선택하면 됩니다. 삭제 이후에 nano를 입력하면 더 이상 nano가 존재하지 않는다고 합니다.
간단한 ubuntu를 Docker Container로 실행하고 root 유저로 로그인해 nano를 설치하고 삭제하는 실습을 해보았습니다.