달력

3

« 2024/3 »

  • 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
2018. 12. 11. 23:30

Docker 설치하기 - Docker Desktop MacOS (2) Tip & Tips2018. 12. 11. 23:30

지난번에는 MacOS에 도커(Docker Desktop)을 설치하고, 컨테이너에 nginx도 올리는 것도 해보았는데, 밤도 늦고 해서 컨테이너를 정리하지 않고 그냥 내버려두었다.


컨테이너 이미지를 실행하는 것을 복습할겸해서 다시 정리한다. 

사실 설치와 리소스를 정리하는 내용은 "docker.com"에 있는 Getting started를 참조하면 바로 알수 있다.

  

    Getting Started : "https://docs.docker.com/docker-for-mac/#explore-the-application"



지난번에 했던 내용을 복습하는 측면에서 정리를 해보면, 먼저 버전을 확인한다.

"docker", "docker-compose", "docker-machine"의 버전을 아래과 같이 Terminal에서 확인할 수 있다.

mymac$ docker --version

Docker version 18.09.0, build 4d60db4

mymac$ docker-compose --version

docker-compose version 1.23.2, build 1110ad01

mymac$ docker-machine --version

docker-machine version 0.16.0, build 702c267f


또는 상단에 떠 있는 "Docker Dasktop" 의 고래 아이콘을 클릭하면 뜨는 메뉴창중에 "About Docker Desktop" 메뉴를 클릭하면 

다음과 같은 화면이 나타난다. 

설치되어 있는 시스템 모듈의 버전들이 보인다.


 지난번에 설치해서 실행한 컨테이너는 "hello-world"와 "eginx" 였다.

mymac$ docker run hello-world

mymac$ docker run -d -p 80:80 --name webserver nginx


Local Repository에 설치되어 있는 이미지가 있다면, 그대로 사용하고, 없다면 공용 Repository에서 최신버전을 다운받아서 실행을 하게 된다. 여기까지가 지난번에 수행했던 작업이다.


"docker run"을 실행할때 옵션 정보를 알려면 "docker run --help"를 터미널창에서 실행하면 된다.

여기서 "-d" 옵션은 background에서 실행하라는 옵션이다 (컨테이너 ID를 화면에 찍고).

그리고, "-p" 옵션은 컨테이너의 port와 호스트의 port를 매핑해 주는 옵션이다. 위에서는 80포트를 80 포트로 매핑하는 역할을 한다. 

-d, --detach                   Run container in background and print container ID

-p, --publish list             Publish a container's port(s) to the host


실행되고 있는 컨테이너의 리스트는 "docker container ls" 명령으로 아래가 같이 가져올수 있다.

mymac$ docker container ls

CONTAINER ID   IMAGE  COMMAND                  CREATED            STATUS           PORTS                         NAMES

5301571351c7      nginx  "nginx -g 'daemon …"   9 minutes ago   Up 9 minutes   0.0.0.0:80->80/tcp   webserver


세부적인 명령에 대한 도움말은 "docker container --help" 를 이용해서 볼 수 있다.

도움말을 보년 "a"옵션은 전체를 보여주라는 옵션인데, 실행하면 아래와 같은 내용을 볼수 있다.

mymac$ docker container ls -a

CONTAINER ID   IMAGE         COMMAND               CREATED          STATUS              PORTS                NAMES

5301571351c7    nginx     "nginx -g 'daemon…"   17 minutes ago   Up 17 minutes       0.0.0.0:80->80/tcp   webserver

29094fd263cf   hello-world   "/hello"                20 minutes ago   Exited (0) 20 ...                                  quirky_ptolem


 

위 실행 결과를 보면 삭제하려는 컨테이너와 이미지는 "nginx"와 '"hello-world"인데, "nginx"는 지금 백그라운드에서 실행중이라는 것을 알수 있다.


Terminal에서 "docker container stop webserver"를 입력하여 실행되는 컨테이너을 중단시키고, 그 결과를 조금전에 수행했던 "docker container ls -a"명령을 이용해서 확인해 보면 다음과 같이 나타난다.

mymac$ docker container stop webserver

webserver


mymac$ docker container ls -a

CONTAINER ID        IMAGE               COMMAND                  CREATED                STATUS                      

5301571351c7        nginx               "nginx -g 'daemon of…"   28 minutes ago      Exited (0) 4 minutes ago 

29094fd263cf      hello-world      "/hello"                 31 minutes ago              Exited (0) 31 minutes ago 


이어서 컨네이너와 이미지를 삭제한다.


먼저 컨테이너를 삭제한다. 컨테이너 리스트에서 보았던 "NAMES" 필드값을 이용하면 된다.

mymac$ docker image rm webserver

mymac$ docker image rm quirky_ptolemy


실행된 결과의 확인은 다시 "docker container ls -a"명령을 확인하면 된다.


다음으로는 이미지를 삭제하는 방법인데, 먼저 "docker image ls" 명령을 사용해서 리스트를 가져온다.

mymac$ docker image ls

REPOSITORY      TAG        IMAGE ID         CREATED          SIZE

nginx           latest     568c4670fa80     13 days ago      109MB

hello-world     latest     4ab4c602aa5e     3 months ago     1.84kB


이미지를 삭제하기 위해서는 옵션으로 "IMAGE ID"가 필요하기 때문이다.

"hello-world" 와 'nginx'의 이미지는 다음과 같이 " docker image rm" 명령을 이용하여 삭제할 수 있다. 

mymac$ docker image rm 4ab4c602aa5e

Untagged: hello-world:latest

Untagged: hello-world@sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788

Deleted: sha256:4ab4c602aa5eed5528a6620ff18a1dc4faef0e1ab3a5eddeddb410714478c67f

Deleted: sha256:428c97da766c4c13b19088a471de6b622b038f3ae8efa10ec5a37d6d31a2df0b


mymac$ docker image rm 568c4670fa80

Untagged: nginx:latest

Untagged: nginx@sha256:5d32f60db294b5deb55d078cd4feb410ad88e6fe77500c87d3970eca97f54dba

Deleted: sha256:568c4670fa800978e08e4a51132b995a54f8d5ae83ca133ef5546d092b864acf

Deleted: sha256:ac0442c0fafd48e24a96fa3099ea7ad20012c8759e1dd03dd387dbfbe382984c

Deleted: sha256:6b9d35d8d75115937cd78da275f527cccef672cbd71f34062dffe2e930fd7e13

Deleted: sha256:ef68f6734aa485edf13a8509fe60e4272428deaf63f446a441b79d47fc5d17d3


이에 대한 실행 결과는 "docker image ls"를 이용해서 확인하면 된다.


:
Posted by 행복상자
2018. 12. 9. 23:00

Docker 설치하기 - Docker Desktop MacOS (1) Tip & Tips2018. 12. 9. 23:00

새로운 과제를 위해서 Docker의 사용을 검토하고 있는 와중에, 얼마전에는 Google Cloud 기반의 "Kubernates" 사용을 위한 교육도 참여하였다. 몇년전에 Docker에 대해서 검토할때도 각 Cloud 서비스를 제공하는 업체에서, 지금처럼 지원이 가능한 솔루션들이 많이 없었는데, 현재는 "Kubernates"를 기본 Docker관리 플랫폼으로 사용하려고 듯하다. "AWS", "MS" 그리고 "Google Cloud"에서 "Kubernates"를 지원한다.

구글에서는 컨테이너 기반으로 서비스를 운영하고 있다고 한다.


오늘은 며칠전부터 마음 먹었던 일을 하려고 한다. 개인용 PC에 도커를 설치해 보려고 한다. 집에서 사용하고 있는 MacOS에 설치하려고 한다.


Docker에 대해서는 며칠전부터 책을 보고 있는데, 나무위키에서는 다음과 같이 간단하게 잘 설명해 주고 있다.

도커는 LXC(리눅스 컨테이너)라는 커널 컨테이너 기술을 이용하여 만든 컨테이너 기술 중에 하나이다.


가상화와 관련된 여러 기술들이 있지만, 도커는 리눅스 기반의 기술에서 비롯되었다고 이해하면 된다.


Docker는 "https://www.docker.com"에 접속하면 자세한 정보들을 볼수 있는데, 나는 여기서 오늘은 MacOS에서 구동이 가능한 "Docker Desktop"을 설치하려고 한다.


Docker 웹사이트의 "Products" 메뉴에서 "Docker Desktop"을 찾아가거나 다음의 URL로 직접 접속해서 다운을 받아도 된다. 


Docker Desktop : https://www.docker.com/products/docker-desktop


아래와 같은 화면을 볼수 있을 것인데, 여기서 Mac용 설치 파일을 받으면 된다.





그런데, 바로 다운을 할수가 없다. ^^;;  

로그인을 위한 회원가입이 선행이 되어야 한다.

가입은 로그인 계정에 사용할 id와 인증을 위한 email 계정을 넣으면 쉽게 할수 있다. 인증 email을 받아서 내용을 보면, 아래와 같이 "Confirm Your Email" 버튼이 보이는데, 이를 클릭하면, 인증은 끝나고, 바로 다운로드를 받을 수 있다. 

MacOS 에서는 "Docker.dmg" 파일이 다운로드 받게 되어있다. 

이제 다운로드한 "Docker.dmg"을 Finder를 열고, 더블 클릭을 하게 되면 아래와 같은 화면이 나타나는데, 아래 창에서 보이는 그대로 "Docker" 이미지를 마우스로 드래그 & 드롭해서 "Applications"폴다 이미지에 가져다 놓으면 설치가 진행된다.

설치가 완료되고 실행을 시키면 아래와 같은 화면이 나타난다.

그리고 화면 상단에는 다음과 같이 도커 이미지가 표시가 될 것이다.



위 화면에서 "Next" 버튼을 누르면, 아래와 같이 권한에 대한 요청 메시지를 볼수 있는데, "OK"버튼을 클릭하고, 시스템 관련 Password를 입력하면 된다.

패스워드를 입력하면, 사용할 준비는 끝나게 되는데, 이와 동시에 화면 상단에 로그인 하라는 화면이 아래와 같이 나타날 것이다.

조금 아까 다운로드 받기위해서 만들었던,  id 와 password 를 입력하게 되면, 아래와 같이 사용이 가능하다는 화면이 나타나게 된다.

설치된 Docker Dasktop을 한번 테스트겸 사용해 보자.

간단하게 위의 화면처럼 Terminal을 하나 열고 "docker run hello-world"를 실행해 보자.

그러면 다음과 같이 화면에 표시가 될 것이다.

mymac$ docker run hello-world

Unable to find image 'hello-world:latest' locally

latest: Pulling from library/hello-world

d1725b59e92d: Pull complete 

Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788

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의 버전은 "docker --version"을 이용해서 알수 있다.

mymac$ docker --version

Docker version 18.09.0, build 4d60db4


 이번에는 Webserver를 한번 띄우겠다. "docker run -d -p 80:80 --name webserver nginx" 라고 terminal에 입력한다.

mymac$ docker run -d -p 80:80 --name webserver nginx

Unable to find image 'nginx:latest' locally

latest: Pulling from library/nginx

a5a6f2f73cd8: Pull complete 

1ba02017c4b2: Pull complete 

33b176c904de: Pull complete 

Digest: sha256:5d32f60db294b5deb55d078cd4feb410ad88e6fe77500c87d3970eca97f54dba

Status: Downloaded newer image for nginx:latest

08f27af460e9d6d3521104729fdeda7f4fba9ff7b69187bbf7fb588307c4fc71


이미지가 로컬에 없다면, 다운받아서 설치가 될 것이다. 


설치된 이미지와 컨테이너의 동작을 보기 위해서 아래가 같이 "docker container ls" 명령은 준다. 

결과가 잘 나왔다.

mymac$ docker container ls

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES

08f27af460e9        nginx               "nginx -g 'daemon of…"   38 seconds ago      Up 37 seconds       0.0.0.0:80->80/tcp   webserver


이번에는 정상적으로 동작하는지 확인해 볼거다. Terminal에서 "curl -X GET http://localhost:80"을 입력하고 실행해보면 아래와 같이 출력이 될 것이다. 정상적으로 잘 동작하는 것이다. 물론 브라우저에서도 가능하다. 

mymac$ curl -X GET http://localhost:80

<!DOCTYPE html>

<html>

<head>

<title>Welcome to nginx!</title>

<style>

    body {

        width: 35em;

        margin: 0 auto;

        font-family: Tahoma, Verdana, Arial, sans-serif;

    }

</style>

</head>

<body>

<h1>Welcome to nginx!</h1>

<p>If you see this page, the nginx web server is successfully installed and

working. Further configuration is required.</p>


<p>For online documentation and support please refer to

<a href="http://nginx.org/">nginx.org</a>.<br/>

Commercial support is available at

<a href="http://nginx.com/">nginx.com</a>.</p>


<p><em>Thank you for using nginx.</em></p>

</body>

</html>



웹브라우저에서 "http://localhost" 또는 "http://localhost:80"을 실행해보면 다음과 같은 화면을 볼수 있을 것이다.




처음으로 docker dasktop을 설치해 보았는데, 설치는 별로 어렵지 않았는데, 로그인을 해야 한다라는 사실이 좀 생소하였다. 이후는 수월하게 설치할 수 있었다.


아참, 아까 띄워놓은 컨테이너는 어떻게하지, 아직도 동작하고 있을 텐데...

오늘은 늦었으니, 내일 다시 마무리 해야겠다.

 



:
Posted by 행복상자