목표 : docker 컨테이너에 ubuntu를 받고 이것 저것 만져본다.
어디서 : 우분투, cmd 등 프로그램에서
어떻게: 리눅스 명령어를 입력해서

리눅스 커널과 배포판

  • 배포판의 종류 
    우분투, 데비안, 알파인, 페도라, 센트os 등등
  • 배포판에 따른 패키지 매니저
    파이썬 : 우분투(apt, pip) , 데비안 (apt, pip), 알파인리눅스 (apt, pip), 페도라(dnf,pip), 센트os(yum,pip), 
    JavaScript(Node.js)  : npm, yarn
    C# 등의 언어 : NuGut

실습(진한글씨만 입력하는것)

  • 우분투를 실행 (로컬에 없기 때문에 알아서 다운받는다)
    weare@DESKTOP-BE1I4GE:~$ 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
    unable to upgrade to tcp, received 404

  • 도커컨테이너 목록중에 우분투가 실행되는지 확인
    weare@DESKTOP-BE1I4GE:~$ docker ps
    CONTAINER ID   IMAGE                  COMMAND                  CREATED        STATUS                      PORTS                    NAMES
    실행 안된다. 그 이유는 동작완료하고 동작을 유지하지 않았기 때문

  •  -a를 추가해 완료된 도커 컨테이너도 확인
    weare@DESKTOP-BE1I4GE:~$ docker ps -a
    CONTAINER ID   IMAGE                  COMMAND                  CREATED         STATUS                             PORTS                    NAMES
    d70342287a9a   ubuntu                 "/bin/bash"              2 minutes ago   Exited (0) 2 minutes ago                                    stoic_lamarr

  • ubuntu 컨테이너 실행 및 nano 에디터 접속 시도
    weare@DESKTOP-BE1I4GE:~$ docker run -it ubuntu
    root@8334f78ad747:/# nano
    bash: nano: command not found

    root@8334f78ad747:/# 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
    root@8334f78ad747:/# apt update
    Get:1 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
    Get:2 http://archive.ubuntu.com/ubuntu jammy InRelease [270 kB]
    Get:3 http://security.ubuntu.com/ubuntu jammy-security/multiverse amd64 Packages [44.0 kB]
    Get:4 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
    Get:5 http://security.ubuntu.com/ubuntu jammy-security/universe amd64 Packages [1046 kB]
    Get:6 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [109 kB]
    Get:7 http://archive.ubuntu.com/ubuntu jammy/universe amd64 Packages [17.5 MB]
    Get:8 http://security.ubuntu.com/ubuntu jammy-security/restricted amd64 Packages [1572 kB]
    Get:9 http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages [1326 kB]
    Get:10 http://archive.ubuntu.com/ubuntu jammy/multiverse amd64 Packages [266 kB]
    Get:11 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages [1792 kB]
    Get:12 http://archive.ubuntu.com/ubuntu jammy/restricted amd64 Packages [164 kB]
    Get:13 http://archive.ubuntu.com/ubuntu jammy-updates/restricted amd64 Packages [1602 kB]
    Get:14 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 Packages [1305 kB]
    Get:15 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages [1599 kB]
    Get:16 http://archive.ubuntu.com/ubuntu jammy-updates/multiverse amd64 Packages [49.8 kB]
    Get:17 http://archive.ubuntu.com/ubuntu jammy-backports/main amd64 Packages [50.4 kB]
    Get:18 http://archive.ubuntu.com/ubuntu jammy-backports/universe amd64 Packages [28.1 kB]
    Fetched 28.9 MB in 1min 37s (300 kB/s)
    Reading package lists... Done
    Building dependency tree... Done
    Reading state information... Done
    All packages are up to date.

  • ubuntu에 nano를 설치해봄
    root@8334f78ad747:/# 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 1s (198 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 에디터 접속 해봄
    root@8334f78ad747:/# nano

  • nano 삭제
    root@8334f78ad747:/# 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) ...

실습 내용 : hello world 실행하기

1. 회원 등록 : https://hub.docker.com/

(id, pw 기억해놓것! 나중에 쓰임)

 

Docker Hub Container Image Library | App Containerization

Build and Ship any Application Anywhere Docker Hub is the world's easiest way to create, manage, and deliver your team's container applications. Create your account Signing up for Docker is fast and free. Continue with GoogleContinue with GitHubContinue wi

hub.docker.com

 

2. 레포 작성 : create repository -> hello-world-docker(레포이름) -> create

 

3. 무료 서버에서 도커 이미지 받는 실습 해보기
https://labs.play-with-docker.com/   login(도커허브 연동해 로그인) ->  ADD NEW INSTANCE 클릭

  • 아래 명령어 순서대로 입력
  • docker pull legoking/hello-world-docker
    이미지 받아옴
  • docker image ls
    이미지 받아졌는지 확인
  • docker run legoking/hello-world-docker
    실행해봄 (꼭 pull 안하고 이거만 써도 한번에 됨)

 

4. docker registry에 등록(로컬에 있을때)

  • docker tag A B : 레포의 이름을 A에서 B로 변경
    + tag는 기본값은 latest , ' : ' 뒤에 나타냄  
  • docker login~ : 도커에 id pw로 로그인 (로그인은 최초 1번만 필요)


5.결과 확인

6.docker 명령 정리

  • docker version
  • docker build -t 이미지이름:태그 . -> 현재 티렉토리(.)에 dockerfile을 사용해서 도커 이미지 빌드, -t 태그지정
  • docker push 이미지이름:태그
  • docker tag 소스이미지:태그 새이미지:새태그
  • docker pull 이미지이름:태그
  • docker run 옵션 이미지이름:태그
    옵션(p) 호스트 머신과 컨테이너 간의 포트를 매핑
    옵션(v)  호스트 머신의 디렉토리나 파일을 컨테이너에 매핑

5. docker run , docker exec

  • docker run은 새로운 컨테이너를 생성하고 실행하는 데 사용됨
  • docker exec는 이미 실행 중인 컨테이너 내에서 명령을 실행하는 데 사용됨
  • 두 명령 모두 --user root or -u root를 통해 루트 유저로 연결가능

+ Recent posts