Hello-world

  1. 이미지는 기본적으로 Docker Hub를 통해 다운로드 받고, CLI를 통해 Docker Hub의 이미지 정보 확인할 수 있다.

    docker search hello-world
    
    NAME                                       DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
    hello-world                                Hello World! (an example of minimal Dockeriz…   802                 [OK]
    kitematic/hello-world-nginx                A light-weight nginx container that demonstr…   119
    tutum/hello-world                          Image to test docker deployments. Has Apache…   59                                      [OK]
    dockercloud/hello-world                    Hello World!                                    14                                      [OK]
    hypriot/armhf-hello-world                  Hello World! (an example of minimal Dockeriz…   6
    crccheck/hello-world                       Hello World web server in under 2.5 MB          6                                       [OK]
    
  2. hello-world Official 이미지를 사용하여 첫 번째 컨테이너 생성

    docker run hello-world
    
    latest: Pulling from library/hello-world
    1b930d010525: Pull complete
    Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
    Status: Downloaded newer image for hello-world:latest
    
    Hello from Docker!
    This message shows that your installation appears to be working correctly.
    
    To generate this message, Docker took the following steps:
     1. The Docker client contacted the Docker daemon.
     2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
        (amd64)
     3. The Docker daemon created a new container from that image which runs the
        executable that produces the output you are currently reading.
     4. The Docker daemon streamed that output to the Docker client, which sent it
        to your terminal.
    
    To try something more ambitious, you can run an Ubuntu container with:
     $ docker run -it ubuntu bash
    
    Share images, automate workflows, and more with a free Docker ID:
     <https://hub.docker.com/>
    
    For more examples and ideas, visit:
     <https://docs.docker.com/get-started/>
    
  3. 이미지 리스트 확인

    docker images
    
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    hello-world         latest              fce289e99eb9        2 weeks ago         1.84kB
    
  4. 현재 구동 중인 컨테이너 리스트 확인

    docker ps
    
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
    
  5. 종료된 컨테이너까지 표시하도록 -a 옵션 추가

    docker ps -a
    
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                               NAMES
    ca3f2ad0e71d        hello-world         "/hello"                 11 minutes ago      Exited (0) 11 minutes ago                                       nostal
    
  6. Docker hub에서 컨테이너 내용 확인 가능

    https://hub.docker.com/

  7. hello-world 컨테이너 제거

    1. 제거를 위해 CONTAINER ID 확인

      docker ps -a hello-world
      
      CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                               NAMES
      ca3f2ad0e71d        hello-world         "/hello"                 22 minutes ago      Exited (0) 22 minutes ago                                       nostalgic_einstein
      
    2. CONTAINER ID를 사용하여 제거 (CONTAINER ID의 일부만 사용해도 인지)

      docker rm [컨테이너ID 또는 이름]
      
      • 컨테이너를 제거하기 위해서는 반드시 컨테이너가 Stop 상태이어야 함
      • Running 상태의 컨테이너를 제거하기 위해서는 docker rm 명령에 -f 옵션 사용
      • hello-world 컨테이너는 이미 Stop 상태이기 때문에 곧바로 제거 가능
  8. Docker 이미지 제거

    1. REPOSITORY 또는 IMAGE ID 확인

      docker images
      
      REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
      hello-world         latest              fce289e99eb9        2 weeks ago         1.84kB
      
    2. REPOSITORY 또는 IMAGE ID로 이미지 제거

      docker rmi hello-world
      
      Untagged: hello-world:latest
      Untagged: hello-world@sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
      Deleted: sha256:fce289e99eb9bca977dae136fbe2a82b6b7d4c372474c9235adc1741675f587e
      Deleted: sha256:af0b15c8625bb1938f1d7b17081031f649fd14e6b233688eea3c5483994a66a3
      
      • hello-world 이미지의 TAG가 latest이기 때문에 별도의 태그 입력 없이 제거 가능
      • TAG가 존재하는 경우에는 hello-world:태그명 과 같은 형식으로 이미지 제거