Docker에서는 이미 주어진 Image들을 다운로드 받아서 사용하고 있다.

그러면, 이러한 Image들은 어디에 있는 것일까?!

 

"Docker Hub"라는 공식적으로 운영하고 있는 Image Server가 바로 그 곳이다.

 

이름에서 떠오르는 것과 같이.... GitHub와 같은 역할을 하는 아이다.

소스코드가 아닌 Docker Image를 저장하는 그 곳!

명령어도 유사하다~

 

 

 

 

 

그런데, 우리는 (나 혼자만?) 공식적인 것 말고.... 사적인 것, 나만의 것을 갖고 싶은 욕구가 있다.

즉, 나만의 Docker Hub를 운영하고 싶으면 어떻게 해야할까?

 

 

 

이럴 때 필요한 구글신께 외치는 주문~!!!

   - Docker Registry Server Install

 

그러면, 게시를 내려주시는 우리의 구글신님~!!!

   - https://docs.docker.com/registry/deploying/

 

 

 

 

우리가 지금부터 해야할 것은 "Docker Registry Server"를 구축하는 것이다.

 

 

 

 

 

Docker와 관련이 있는 것이니만큼, Docker Registry Server 역시 Docker 이미지로 배포가 된다.

즉, 별도의 설치과정 없이 이미지를 다운로드 받아서 실행하면 된다는...

 

하지만, 언제나처럼 제대로 사용하기 위해서는 공부를 해야하고, 시행착오를 겪어야 한다는... ^^

 

 

 

 

 

일단, Docker를 설치해야한다.

   - [ Docker Install (Ubuntu 14.04 - 64bit) - using Download ] : http://www.whatwant.com/863

 

 

 

이제 우리가 필요한 Registry Server의 이미지를 땡겨오자.

 

$ sudo docker pull registry
Using default tag: latest
latest: Pulling from library/registry
90f4dba627d6: Pull complete
3a754cdc94a5: Pull complete
0756a217635f: Pull complete
f82b9495c796: Pull complete
154ef19ddee6: Pull complete
Digest: sha256:5eaafa2318aa0c4c52f95077c2a68bed0b13f6d2b464835723d4de1484052299
Status: Downloaded newer image for registry:latest

 

$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
registry              latest              c2a449c9f834         3 days ago          33.2 MB
hello-world         latest              1815c82652c0        2 weeks ago         1.84 kB

 

 

 

 

실행은 간단하다.

 

$ sudo docker run --name my-registry -d --restart=always -p 5000:5000 registry
0af462462b05ea13191470dff48ab52edf2206b65c885d2d82fd5c319daca63a

 

$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
0af462462b05        registry            "/entrypoint.sh /e..."   9 seconds ago       Up 8 seconds        0.0.0.0:5000->5000/tcp   my-registry

 

"--name" 옵션 뒤에 앞으로 사용할 Container 이름을 임의로 지어주면 되고...

"-d" 옵션을 통해서 Daemon으로 실행하고 싶다고 알려주고~

"--restart=always" 옵션을 통해서 Container 안에서 프로세스가 죽더라도 항상 재시작을 하도록 하고~

"-p" 옵션으로 포트 매핑을 해주면 된다.

 

제일 뒤에는 원본(?)으로 사용할 이미지를 지정해준다.

 

ps를 통해서 실행되고 있는 모습을 확인해볼 수 있다.

 

 

 

 

 

지금 실행해 놓은 Registry를 실험해보기 위해서, 등록해볼 마루타를 하나 만들어보자.

 

 

 

Dockerfile을 하나 만들어보자.

 

$ nano ./Dockerfile

 

FROM busybox
MAINTAINER whatwant <whatwant@gmail.com>
CMD /bin/echo "hi-world!!"

 

방금 만든 마루타의 Dockerfile을 빌드해서 이미지로 만들어보자.

 

$ sudo docker build -t hi-world .
Sending build context to Docker daemon 2.048 kB
Step 1/3 : FROM busybox
 ---> c30178c5239f
Step 2/3 : MAINTAINER whatwant <whatwant@gmail.com>
 ---> Running in 6115aa49c789
 ---> efaf526395ee
Removing intermediate container 6115aa49c789
Step 3/3 : CMD /bin/echo "hi-world!!"
 ---> Running in b57e417ec463
 ---> 0983858cdd37
Removing intermediate container b57e417ec463
Successfully built 0983858cdd37

 

$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hi-world            latest              0983858cdd37     14 seconds ago       1.11 MB
registry             latest              c2a449c9f834        3 days ago           33.2 MB
busybox            latest              c30178c5239f        2 weeks ago         1.11 MB
hello-world       <none>           1815c82652c0        2 weeks ago         1.84 kB

 

 

 

이미지를 만들었으면, 이제는 우리의 Registry Server에 등록을 해보자.

 

$ sudo docker tag hi-world localhost:5000/hi-world


$ sudo docker push localhost:5000/hi-world
The push refers to a repository [localhost:5000/hi-world]
3a1dff9afffd: Pushed
latest: digest: sha256:b182254942f5ffeb903b7125c4693e12c2330db6c16a75681e76c633535edade size: 527

 

잘 등록되었는지 확인도 해보자.

 

$ curl -X GET http://localhost:5000/v2/_catalog
{"repositories":["hi-world"]}

 

$ curl -X GET http://localhost:5000/v2/hi-world/tags/list
{"name":"hi-world","tags":["latest"]}

 

 

 

 

이번에는 Registry Server를 제대로 사용할 수 있는지 확인해보자.

그런데, 이미 가지고 있는 이미지들이 있으니 테스트를 위해서 확인하고 지워놓자.

 

$ sudo docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
hi-world                  latest              81d1537591cc        32 minutes ago      1.11 MB
localhost:5000/hi-world   latest              81d1537591cc        32 minutes ago      1.11 MB
registry                  latest              c2a449c9f834        3 days ago          33.2 MB
busybox                   latest              c30178c5239f        2 weeks ago         1.11 MB
hello-world               latest              1815c82652c0        2 weeks ago         1.84 kB

 

hi-world, localhost:5000/hi-world 2개의 이미지가 있다. 지우자!

 

$ sudo docker rmi hi-world
Untagged: hi-world:latest


$ sudo docker rmi localhost:5000/hi-world
Untagged: localhost:5000/hi-world:latest
Untagged: localhost:5000/hi-world@sha256:410ad4c96024f632bde893190d71a3c10457419c50375ab1d878f2ad67d76775
Deleted: sha256:81d1537591cc43e879aeed3e0556788f9b6b75ab6377fd1db6c9266472f27f09
Deleted: sha256:358acd2e8b9f52adffcdd2870487bdc36d7842677d602ffdf533776ac55a7574

 

$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
registry            latest              c2a449c9f834        3 days ago          33.2 MB
busybox             latest              c30178c5239f        2 weeks ago         1.11 MB
hello-world         latest              1815c82652c0        2 weeks ago         1.84 kB

 

hi-world 이미지가 없는 것을 확인했다.

이제 땡겨오자.

 

 

$ sudo docker pull localhost:5000/hi-world
Using default tag: latest
latest: Pulling from hi-world
27144aa8f1b9: Already exists
Digest: sha256:410ad4c96024f632bde893190d71a3c10457419c50375ab1d878f2ad67d76775
Status: Downloaded newer image for localhost:5000/hi-world:latest

 

$ sudo docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
localhost:5000/hi-world   latest              81d1537591cc        33 minutes ago      1.11 MB
registry                  latest              c2a449c9f834        3 days ago          33.2 MB
busybox                   latest              c30178c5239f        2 weeks ago         1.11 MB
hello-world               latest              1815c82652c0        2 weeks ago         1.84 kB

 

잘 받아온 것을 확인했다.

 

 

동작이 잘되는지도 확인해보자.

 

$ sudo docker run localhost:5000/hi-world
hi-world!!

 

물론 잘된다.

 





혹시 아래와 같은 에러가 발생할 경우에는...


$ sudo docker pull xxx.xxx.xx.xx:5000/asdf

Using default tag: latest

Error response from daemon: Get https://xxx.xxx.xxx.xxx:5000/v1/_ping: http: server gave HTTP response to HTTPS client



아래와 같이 환경설정을 해주면 된다.


$ sudo nano /etc/default/docker

 

...

# Use DOCKER_OPTS to modify the daemon startup options.

#DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"

DOCKER_OPTS="--insecure-registry xxx.xxx.xxx.xxx:5000"

...


$ sudo service docker restart

 



 

기본적인 사항은 여기까지 해서 살펴보았지만...

아직 사용하기에는 문제가 많이 있는 상태이다.

 

당장 인증 관련한 부분에 있어서 문제가 있다. 아무나 쓸 수 있도록 한다면 뭐 무방하지만.... ^^

LDAP과 같은 계정서버와의 연계라던지 아니면 로드밸런싱이라던지... 등 알아봐야할게 아직 많다.

 

뭐 일단, 이번 포스트는 여기까지~

 

반응형


Ansible은 장점이 많은 도구인 것 같다.

첫번째로 Master에만 설치하면 된다는 점에서 좋고, 두번째로는 SSH 기반으로 일을 한다는 것이 좋다!



 

 

지난 포스팅을 통해서 Master 역할을 할 아이에게 Ansible을 설치했다는 전제 하에 설명을 진행하겠다.

    - [ Ansible Source Install (Ubuntu 14.04) ] : http://www.whatwant.com/865

 

 

 

 

그 다음 해야할 첫번째 일은... Master에서 Slave로 SSH로 접근할 수 있는 길을 만드는 것이다.

    - [ SSH Public Key - SSH 공개키 ] : http://www.whatwant.com/395

 

Master에서 ssh 키를 생성하고나서 Slave들에게 public-key를 넣어주면 된다.

 

 

 

 

 

이제 해야할 일은 Ansible에게 Slave가 누군지를 알려줘야 한다.

hosts 파일을 만들자. 꼭 이름을 "hosts"라고 해야하는 것은 아니다.

 

$ nano ./hosts

 

Slave IP 정보를 적어주면 된다. 꼭 "[Staging]"이라고 이름을 지어야 하는 것은 아니다.

 

[staging]
192.168.100.105

 

 

 

주인의 명령을 듣는 노예(Slave)들에게는 내가 주인인 것을 알려주는 열쇠가 필요하다. SSH Public-Key

    - http://www.whatwant.com/395


주인의 키를 노예에게 넣어놓자!


 

 

Slave와 잘 통하는지 알아보자.

 

$ ansible all -m ping -i ./hosts -u u14
192.168.100.105 | SUCCESS => {
    "changed": false,
    "failed": false,
    "ping": "pong"
}

 

"-i" 옵션 뒤에는 앞에서 만든 hosts 파일을 지정해주면 되고.

"-u" 옵션 뒤에는 Slave에 접근할 계정을 지정해주면 된다.

 

 

 

 

그럼 간단한 명령어를 원격으로 날려보자.

 

$ ansible -i ./hosts staging -u u14 -m command -a "ls -ahl"
192.168.100.105 | SUCCESS | rc=0 >>
합계 140K
drwxr-xr-x 18 u14  u14  4.0K  7월  2 03:38 .
drwxr-xr-x  3 root root 4.0K  8월  9  2015 ..
-rw-------  1 u14  u14  7.4K  7월  2 03:37 .ICEauthority
-rw-------  1 u14  u14    53  7월  2 03:37 .Xauthority
drwx------  3 u14  u14  4.0K  6월 25 19:07 .ansible
-rw-------  1 u14  u14  2.0K  6월 26 00:35 .bash_history
-rw-r--r--  1 u14  u14   220  8월  9  2015 .bash_logout
-rw-r--r--  1 u14  u14  3.6K  8월  9  2015 .bashrc
drwx------ 14 u14  u14  4.0K  6월 25 14:58 .cache
drwx------  3 u14  u14  4.0K  8월  9  2015 .compiz
drwx------ 14 u14  u14  4.0K  8월  9  2015 .config
drwx------  3 u14  u14  4.0K 12월 12  2016 .dbus
drwx------  3 u14  u14  4.0K  7월  2 03:37 .gconf
drwx------  3 u14  u14  4.0K  8월  9  2015 .local
-rw-r--r--  1 u14  u14   675  8월  9  2015 .profile
drwxrwxr-x  2 u14  u14  4.0K  6월 25 18:59 .ssh
-rw-r-----  1 u14  u14     5  7월  2 03:37 .vboxclient-clipboard.pid
-rw-r-----  1 u14  u14     5  7월  2 03:37 .vboxclient-display.pid
-rw-r-----  1 u14  u14     5  7월  2 03:37 .vboxclient-draganddrop.pid
-rw-r-----  1 u14  u14     5  7월  2 03:37 .vboxclient-seamless.pid
-rw-rw-r--  1 u14  u14   131  8월  9  2015 .xinputrc
-rw-------  1 u14  u14    54  7월  2 03:37 .xsession-errors
-rw-------  1 u14  u14   833  7월  2 03:11 .xsession-errors.old
-rw-r--r--  1 u14  u14  8.8K  8월  9  2015 examples.desktop
drwxr-xr-x  2 u14  u14  4.0K  8월  9  2015 공개
drwxr-xr-x  2 u14  u14  4.0K  8월  9  2015 다운로드
drwxr-xr-x  2 u14  u14  4.0K  8월  9  2015 문서
drwxr-xr-x  2 u14  u14  4.0K  8월  9  2015 바탕화면
drwxr-xr-x  2 u14  u14  4.0K  8월  9  2015 비디오
drwxr-xr-x  2 u14  u14  4.0K  8월  9  2015 사진
drwxr-xr-x  2 u14  u14  4.0K  8월  9  2015 음악
drwxr-xr-x  2 u14  u14  4.0K  8월  9  2015 템플릿

 

 

"$ sudo apt-get -y upgrade" 명령어 등을 이용하면...^^

 

 

 

 

Ansible을 이용해서 Slave에 접근하는 것에 대해서 살짝 맛만 봤다.

제대로 이용하기 위해서는 playbook 등을 이용해야하지만, 지금은 맛만 살짝~




다음에 기회가 되면 계속 이어가보겠다~



 

반응형

2019.07.07


간만에 해보려고 했더니, 에러가 발생한다.

공식 가이드에도 14.04 버전에 대한 가이드 내용이 사라졌다.

아래 내용은 그냥 참고만 하시길...


============================================================================================


공식 홈페이지에 너무나 잘 나와있다.

- https://docs.docker.com/engine/installation/linux/ubuntu/



공식 홈페이지 내용 참고해서 직접 해보면서 진행했던 내용의 기록이다.

하나씩 따라가보자.


※ 이 블로그를 계속 봐오신 분들은 아시겠지만... 아래 내용은 직접 실행해보면서 작성한 것입니다.

※ VirtualBox를 이용하여 해당 OS를 설치하고 update까지만 마친 상태에서 진행하였습니다.




1. Ubuntu version

    - Docker에 대한 환상을 갖고 있었다. OS에 의존하지 않고 자유로운.... 하지만 꽝!

    - Ubuntu 14.04, 16.04, 16.10 만 지원하고 있다.

    - 특히, 64bit 만 지원한다! 32bit 안된다!



2. 필요 패키지 설치 (Ubuntu 14.04)

    - Ubuntu 14.04 버전에서만 하면 된다고 한다.


sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual



3. Binary 확인

    - 웹으로 다운로드 받을 버전을 확인하자.




4. Download 받기


$ wget https://download.docker.com/linux/ubuntu/dists/trusty/pool/stable/amd64/docker-ce_17.03.1~ce-0~ubuntu-trusty_amd64.deb



5. Docker 설치하기


sudo dpkg --install ./docker-ce_17.03.1~ce-0~ubuntu-trusty_amd64.deb



6. Hello World


$ sudo docker run hello-world

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

latest: Pulling from library/hello-world

78445dd45222: Pull complete 

Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7

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.

 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://cloud.docker.com/


For more examples and ideas, visit:

 https://docs.docker.com/engine/userguide/



끝~

반응형

 


공식 홈페이지에 너무나 잘 나와있다.

- https://docs.docker.com/engine/installation/linux/ubuntu/



공식 홈페이지 내용 참고해서 직접 해보면서 진행했던 내용의 기록이다.

하나씩 따라가보자.


※ 이 블로그를 계속 봐오신 분들은 아시겠지만... 아래 내용은 직접 실행해보면서 작성한 것입니다.

※ VirtualBox를 이용하여 해당 OS를 설치하고 update까지만 마친 상태에서 진행하였습니다.




1. Ubuntu version

    - Docker에 대한 환상을 갖고 있었다. OS에 의존하지 않고 자유로운.... 하지만 꽝!

    - Ubuntu 14.04, 16.04, 16.10 만 지원하고 있다.

    - 특히, 64bit 만 지원한다! 32bit 안된다!



2. 필요 패키지 설치 (Ubuntu 14.04)

    - Ubuntu 14.04 버전에서만 하면 된다고 한다.


sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual



3. GPG Key 등록 준비


sudo apt-get install apt-transport-https ca-certificates curl software-properties-common



4. GPG Key 등록하기


curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo apt-key fingerprint 0EBFCD88



5. apt 소스 리스트 추가하기


sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

$ sudo apt-get update



6. Docker 설치하기


sudo apt-get install docker-ce



7. Hello World


$ sudo docker run hello-world

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

latest: Pulling from library/hello-world

78445dd45222: Pull complete 

Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7

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.

 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://cloud.docker.com/


For more examples and ideas, visit:

 https://docs.docker.com/engine/userguide/



끝~

반응형

 

Docker를 처음 접했을 때에 필자는 VirtualBox의 대용품으로만 생각했다.

 

온전한 가상환경이 아닌

부분적인 가상환경을 제공함으로써 성능저하 없이 사용할 수 있게 해주는 놈이라고만 생각했던 것이다.

 

하지만, Docker를 알아가면 알아갈 수록

Docker의 가치는 솔루션의 훌륭한 배포 플랫폼이라는 것에 있는 것 같다.

 

 

일단, 지금 여기에서 알아보고자 하는 것을 보면,,,

Dockerfile이라는 것은 이미지를 어떻게 생성하면 되는지를 적어놓은 파일이다.

 

아래는 MySQL 을 배포하기 위한 Dockerfile 내용이다. 내용을 살펴보면 Dockerfile이라는 것이 뭔지 보일 것이다.

   - https://hub.docker.com/_/mysql/

 

FROM debian:jessie

# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
RUN groupadd -r mysql && useradd -r -g mysql mysql

RUN mkdir /docker-entrypoint-initdb.d

# FATAL ERROR: please install the following Perl modules before executing /usr/local/mysql/scripts/mysql_install_db:
# File::Basename
# File::Copy
# Sys::Hostname
# Data::Dumper
RUN apt-get update && apt-get install -y perl pwgen --no-install-recommends && rm -rf /var/lib/apt/lists/*

# gpg: key 5072E1F5: public key "MySQL Release Engineering <mysql-build@oss.oracle.com>" imported
RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys A4A9406876FCBD3C456770C88C718D3B5072E1F5

ENV MYSQL_MAJOR 5.7
ENV MYSQL_VERSION 5.7.10-1debian8

RUN echo "deb http://repo.mysql.com/apt/debian/ jessie mysql-${MYSQL_MAJOR}" > /etc/apt/sources.list.d/mysql.list

# the "/var/lib/mysql" stuff here is because the mysql-server postinst doesn't have an explicit way to disable the mysql_install_db codepath besides having a database already "configured" (ie, stuff in /var/lib/mysql/mysql)
# also, we set debconf keys to make APT a little quieter
RUN { \
echo mysql-community-server mysql-community-server/data-dir select ''; \
echo mysql-community-server mysql-community-server/root-pass password ''; \
echo mysql-community-server mysql-community-server/re-root-pass password ''; \
echo mysql-community-server mysql-community-server/remove-test-db select false; \
} | debconf-set-selections \
&& apt-get update && apt-get install -y mysql-server="${MYSQL_VERSION}" && rm -rf /var/lib/apt/lists/* \
&& rm -rf /var/lib/mysql && mkdir -p /var/lib/mysql

# comment out a few problematic configuration values
# don't reverse lookup hostnames, they are usually another container
RUN sed -Ei 's/^(bind-address|log)/#&/' /etc/mysql/my.cnf \
&& echo 'skip-host-cache\nskip-name-resolve' | awk '{ print } $1 == "[mysqld]" && c == 0 { c = 1; system("cat") }' /etc/mysql/my.cnf > /tmp/my.cnf \
&& mv /tmp/my.cnf /etc/mysql/my.cnf

VOLUME /var/lib/mysql

COPY docker-entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

EXPOSE 3306
CMD ["mysqld"]

 

여기에서 Dockerfile의 문법에 대해서 설명을 하지는 않겠다.

하지만, 이 포스팅을 보시는 분이라면 대강 어떤 내용인지 알 수 있을 것이다.

 

 

이걸 잘 이용하면 재미있는 작품이 많이 나올 것만 같은 느낌인데.... 오홋~ ^^

 

 

반응형


Docker의 인기에 비해서 아직 내 주위의 사람들이 많이 사용하지 않는 이유는...?!

설치 과정이 편하지 않기 때문이라고 생각한다! 어려운게 아니라 귀찮다!


물론 공식 홈페이지에 너무나 잘 나와있다.

- https://docs.docker.com/engine/installation/ubuntulinux/



공식 홈페이지 내용 참고해서 직접 해보면서 진행했던 내용의 기록이다.

하나씩 따라가보자.



1. GPG Key 등록하기


$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D




2. apt 소스 리스트 추가하기


$ sudo nano /etc/apt/sources.list.d/docker.list


deb https://apt.dockerproject.org/repo ubuntu-precise main


$ sudo apt-get update




3. 이전에 설치한 것이 있다면 지워버리기


$ sudo apt-get purge lxc-docker

$ sudo apt-cache policy docker-engine




4. 필요한 패키지 설치하기 (필자는 이미 설치되어 있던데)


$ sudo apt-get install linux-image-generic-lts-trusty




5. Docker 설치하기


$ sudo apt-get install docker-engine





6. Hello World


$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b901d36b6f2f: Pull complete
0a6ba66e537a: Pull complete
Digest: sha256:8be990ef2aeb16dbcb9271ddfe2610fa6658d13f6dfb8bc72074cc1ca36966a7
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.
 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 Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/userguide/




7. 실행 그룹에 포함되기


    - sudo 없이그냥 실행할 수 있게 되기 위해서는 docker 그룹에 포함이 되면 된다.


$ sudo usermod -aG docker {사용하는 계정}


   - 완전히 로그아웃을 하고 다시 해당 계정으로 로그인을 한 뒤에 터미널을 열면... sudo 없이...


$ docker run hello-world





반응형


빌드 환경을 테스트하는데,

Ubuntu 12.04 환경과 Ubuntu 14.04 환경 모두 필요해서 고민하던 중에 문득 떠오른 Docker.


설치까지만 해보고 가지고 놀지를 못하다보니 docker의 개별 image를 어떻게 다루어야 할지,

image와 container를 어떻게 구분을 해야 하는지,

각 container가 어느 정도의 독립성을 갖고 있는지 아무것도 확신이 없다.


하나씩 정복해보도록 하겠다.




1. Image 다운로드 받기


- Ubuntu 이미지를 다운로드 받으려면 다음과 같이 했었다.


$ docker pull ubuntu

latest: Pulling from ubuntu


83e4dde6b9cf: Pull complete 

b670fb0c7ecd: Pull complete 

29460ac93442: Pull complete 

d2a0ecffe6fa: Already exists


$ docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

ubuntu              latest               d2a0ecffe6fa         2 days ago            188.4 MB

ubuntu              14.04              5ba9dab47459        5 months ago        188.3 MB

ubuntu              14.04.1            5ba9dab47459        5 months ago        188.3 MB

ubuntu              trusty               5ba9dab47459        5 months ago        188.3 MB


- 그런데, 우리가 필요한 12.04 버전이 없다.




2. 특정 버전의 Ubuntu 다운로드 받기


- 우리가 필요한 12.04를 다운로드 받기 위해서는 다음과 같이 하면 된다.


$ docker pull ubuntu:12.04

12.04: Pulling from ubuntu


093e01545ca5: Pull complete 

639d60300768: Pull complete 

50e9f95f98f1: Pull complete 

6d021018145f: Already exists 

ubuntu:12.04: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.


Digest: sha256:ac1fcd76d94daa6ee3e832b540812d42a0095bfdc7c2837e2fc6cee2ec9809d7

Status: Downloaded newer image for ubuntu:12.04



$ docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

ubuntu              latest               d2a0ecffe6fa          2 days ago           188.4 MB

ubuntu              12.04               6d021018145f        2 days ago           134 MB

ubuntu              14.04               5ba9dab47459       5 months ago        188.3 MB

ubuntu              14.04.1             5ba9dab47459       5 months ago        188.3 MB

ubuntu              trusty               5ba9dab47459        5 months ago        188.3 MB



 

다음 링크 참조하면 도움이 많이 될 것이다.

https://github.com/docker/docker/wiki/Public-docker-images



반응형


예전에 타이젠(Tizen)의 빌드 환경을 통해 어설프게 접하게 된 컨테이너 기반의 가상환경.
최근에 IT 관련 뉴스를 통해서 docker라는 오픈소스 소프트웨어를 알게 되었고 관심을 갖게 되었다.

VMWare, VirtualBox와 같은 Host OS와 분리되어 거의 완벽히 가상의 Destop을 활용하는 것이 장점이 많기는 하지만,
치명적인 약점이 하나 있는데, Host OS에서 프로세스를 실행하는 것과 비교하여 현저히 떨어지는 성능이 이슈이다.

그런데, 이러한 성능 문제를 해결하면서 독립적인 환경을 구축할 수 있도록 도와주는 기술이 있으니,
Linux Container에 기반한 컴패니언(companion) 소프트웨어인 "docker"가 바로 그러한 기술이다!
 

docker 설치 방법은 다음 경로를 통해서 확인할 수 있다.
   - http://docs.docker.com/installation/ubuntulinux



1. 현재 서버 상태 확인
    - docker를 설치하고자 하는 서버의 상태를 먼저 확인하자.

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.1 LTS
Release: 14.04
Codename: trusty

$ uname -a
Linux chani-VBox 3.13.0-39-generic #66-Ubuntu SMP Tue Oct 28 13:30:27 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux



2. docker 설치
   - 패키지로 설치하면 된다.

$ sudo apt-get install docker.io

$ docker -v
Docker version 1.0.1, build 990021a


   - 이걸로 설치는 끝이다.



3. 사용자 설정
   - 별도의 root 권한 (sudo) 없이 그냥 사용하기 위해서 docker 그룹에 포함이 되자.

$ sudo gpasswd -a [현재사용자] docker
사용자 [현재사용자]을(를) docker 그룹에 등록 중

$ sudo service docker.io restart


   - docker 그룹에 포함된 것이 적용되기 위해서는 다시 로그인을 하면 된다.



4. 현재 Image 확인
   - 명령어들을 하나씩 확인해보자.

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE


   - 3번의 설정을 하지 않았으면 위와 같이 명령어를 했을 때, 권한 에러가 난다.
   - 아직은 아무런 이미지가 없는 상태다.



5. 이미지 다운로드 받기
   - docker에서는 미리 이미지를 만들어놓은 것을 제공해준다.
   - 제공해주는 image를 다운로드 받자.

$ docker pull ubuntu
Pulling repository ubuntu
195eb90b5349: Download complete
277eb4304907: Download complete
463ff6be4238: Download complete
c5881f11ded9: Download complete
3db9c44f4520: Download complete
0b310e6bf058: Download complete
5506de2b643b: Download complete
511136ea3c5a: Download complete
6cfa4d1f33fb: Download complete
3af9d794ad07: Download complete
bac448df371d: Download complete
5f18d94c3eca: Download complete
e12c576ad8a1: Download complete
f127542f0b61: Download complete
d497ad3926c8: Download complete
53db23c604fd: Download complete
b7c6da90134e: Download complete
fae16849ebe2: Download complete
dfaad36d8984: Download complete
9f045ea36057: Download complete
47dd6d11a49f: Download complete
0f4aac48388f: Download complete
5796a7edb16b: Download complete
d03a1a9d7555: Download complete
209ea56fda6d: Download complete
30868777f275: Download complete
102eb2a101b8: Download complete
ccb62158e970: Download complete
530dbbae98a0: Download complete
e791be0477f2: Download complete
37dde56c3a42: Download complete
3680052c0f5c: Download complete
8f118367086c: Download complete
22093c35d77b: Download complete


   - 다운로드 받은 것을 확인해 보자.

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              14.10               277eb4304907        3 weeks ago         228.5 MB
ubuntu              utopic              277eb4304907        3 weeks ago         228.5 MB
ubuntu              trusty              5506de2b643b        3 weeks ago         199.3 MB
ubuntu              14.04               5506de2b643b        3 weeks ago         199.3 MB
ubuntu              latest              5506de2b643b        3 weeks ago         199.3 MB
ubuntu              14.04.1             5506de2b643b        3 weeks ago         199.3 MB
ubuntu              12.04               0b310e6bf058        3 weeks ago         126.7 MB
ubuntu              12.04.5             0b310e6bf058        3 weeks ago         126.7 MB
ubuntu              precise             0b310e6bf058        3 weeks ago         126.7 MB
ubuntu              12.10               c5881f11ded9        5 months ago        172.2 MB
ubuntu              quantal             c5881f11ded9        5 months ago        172.2 MB
ubuntu              13.04               463ff6be4238        5 months ago        169.4 MB
ubuntu              raring              463ff6be4238        5 months ago        169.4 MB
ubuntu              13.10               195eb90b5349        5 months ago        184.7 MB
ubuntu              saucy               195eb90b5349        5 months ago        184.7 MB
ubuntu              10.04               3db9c44f4520        6 months ago        183 MB
ubuntu              lucid               3db9c44f4520        6 months ago        183 MB



6. 실행해 보기
   - 다운로드 받은 이미지 중 하나를 실행해보자.

$ cat /etc/issue
Ubuntu 14.04.1 LTS \n \l

$ docker run -i -t ubuntu:12.04 /bin/bash

root@9463f87188ac:/# cat /etc/issue
Ubuntu 12.04.5 LTS \n \l


   - 14.04 버전의 Ubuntu에 docker를 설치하고, 이미지를 다운로드 받은 후
   - 12.04 버전의 Ubuntu를 docker를 통해서 실행을 한 것이다.

   - 마치 telnet이나 ssh를 통해서 접속한 것과 같은 모습이다.


일단 여기에서 한 꼭지 마무리하겠다.

반응형

+ Recent posts