티스토리 뷰

Development

Docker 실습하기 01편

sungtae 2019. 4. 25. 00:37

여기서는 Docker에 대한 개념이나 설명은 인터넷에 잘 설명이 되어 있어서, 굳이 따로 정리하지는 않으려고 한다.

나는 하나씩 실습을 해야 이해하는 스타일이라 쉬운 것부터 Docker를 사용해보려고 한다.


1. 우선 Docker를 설치해보자.

docker 설치는 홈페이지에서 다운로드하여서 설치하거나

https://www.docker.com/get-started

Mac의 경우 다음 명령어로 설치할 수 있다.

brew cask install docker


설치가 완료 되었다면 터미널에서 아래 명령어를 실행하여 Version이 정상적으로 확인되는지 체크해보자

docker --version
docker-compose --version
docker-machine --version


우선 다음 명령어로 간단하게 docker를 실행해보자(Docker 홈페이지에 나와 있는 예제이다.)

docker run hello-world


무언가 다운로드를 받으면서, 다음과 같은 메시지가 출력되는 것을 확인할 수 있을 것이다.

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:92695bc579f31df7a63da6922075d0666e565ceccad16b59c3374d2cf4e8e50e
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/

 

처음에 docker container를 실행하기 위한 image를 local에 다운로드하게 된다.

다음 명령어를 통해서 image list를 확인할 수 있다.

docker image ls

REPOSITORY                                          TAG                 IMAGE ID            CREATED             SIZE
hello-world                                         latest              fce289e99eb9        3 months ago        1.84kB

그렇다면 실제 container list는 어떤지 확인을 해보자

docker container ls --all

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                          PORTS               NAMES
aee05dfefecc          hello-world         "/hello"                  4 hours ago         Exited (0) 4 hours ago                             trusting_banach


docker container ls

docker container ls 로 확인하는 경우는 아무런 리스트를 볼 수가 없고, --all 옵션을 사용해야 실행시킨 hello-world를 확인할 수 있다.

ls는 현재 실행되고 있는 container의 리스트를 보여주고, -all을 사용해야 모든 container의 리스트를 확인할 수 있다.

 

위에서 image와 container가 나오는데, Java에 비유해서 설명을 하면 image는 Object, container는 Instance라고 생각하면 편할 것 같다.

image를 기반으로 해서 실제 docker 에서 container가 동작을 하게 되는 것이다.

 

지금까지의 내용은 docker 홈페이지에 나와 있는 Get Started의 Part1 부분이다.

Part2에서는 실제 docker image를 빌드해보고, 실행하는 예제가 나오는데 해당 예제는 python으로 되어 있어서

익숙하게 사용하고 있는 node를 기반으로 공부하고 2편에서 정리를 하려고 한다.

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함