Hello World

시작하려면 Cloud Shell을 열고 다음 명령어를 입력하여 hello world 컨테이너를 실행합니다.

docker run hello-world

(명령어 결과)

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9db2ca6ccae0: Pull complete
Digest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
...

이 간단한 컨테이너는 화면에 Hello from Docker! 를 반환합니다. 명령어는 간단하지만 출력된 결과에서 실행된 단계 개수에 주목하세요. Docker 데몬이 hello-world 이미지를 검색했으나 로컬에서 이미지를 찾지 못했고, Docker Hub라는 공개 레지스트리에서 이미지를 가져오고, 가져온 이미지에서 컨테이너를 생성하고, 컨테이너를 실행했습니다.

다음 명령어를 실행하여 Docker Hub에서 가져온 컨테이너 이미지를 확인하세요.

docker images

(명령어 결과)

REPOSITORY     TAG      IMAGE ID       CREATED       SIZE
hello-world    latest   1815c82652c0   6 days ago    1.84 kBcontent_copy

이미지를 Docker Hub 공개 레지스트리에서 가져왔습니다. 이미지 ID는 SHA256 해시 형식입니다. 이 필드에서는 프로비저닝된 Docker 이미지를 지정합니다. Docker 데몬이 로컬에서 이미지를 찾을 수 없으면 기본적으로 공개 레지스트리에서 이미지를 검색합니다. 컨테이너를 다시 실행해 보겠습니다.

docker run hello-world
content_copy

(명령어 결과)

Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
...

두 번째 실행했을 때 Docker 데몬이 로컬 레지스트리에서 이미지를 찾은 뒤 이 이미지에서 컨테이너를 실행하였음을 확인할 수 있습니다. Docker 데몬이 반드시 Docker Hub에서 이미지를 가져올 필요는 없습니다.

마지막으로 다음 명령어를 실행하여 실행 중인 컨테이너를 확인합니다.

docker ps

(명령어 결과)

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAME

실행 중인 컨테이너가 없습니다. 앞서 실행한 hello-world 컨테이너는 이미 종료되었습니다. 실행이 완료된 컨테이너를 포함하여 모든 컨테이너를 보려면 docker ps -a를 실행하세요.