3.1 Docker 설치와 작동 확인#

Docker 의 클라이언트 툴#

Docker for MAC#

  • macOS 10.10 Yosemite에서 이용가능한 하이퍼바이저 프레임워크인 'xhyve'를 사용

Docker for Windows#

  • MS가 제공하는 하이퍼바이저인 x64용 가상화 시스템인 'Hyper-V'를 사용
  • Hyper-V 는 윈도우 10 Pro / Enterprise 버전등에서 사용가능
  • Hyper-V 를 사용하도록 설정하면 VirtualBox 와 같은 다른 가상화 툴은 사용불가

Docker for MAC 설치하기#

  • https://hub.docker.com/editions/community/docker-ce-desktop-mac

Docker for Windows 설치하기#

  • https://hub.docker.com/editions/community/docker-ce-desktop-windows

Linux 에 설치하기#

  • https://docs.docker.com/install/linux/docker-ce/ubuntu/
  • https://docs.docker.com/install/linux/docker-ce/centos/

CentOS에 설치하기#

  • 기존 docker 제거
$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
  • docker설치에 필요한 다른 패키지 설치
$ sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  • 저장소 추가
$ sudo yum-config-manager \
    --add-repo \
  • docker 설치
$ sudo yum install docker-ce docker-ce-cli containerd.io
  • docker 서비스 시작
$ sudo systemctl start docker

Docker 에서 'Hello World'#

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock 에러 발생시
# $USER에는 docker를 실행시킬 일반 유저 아이디를 넣는다. 
$ sudo /usr/sbin/usermod -a -G docker $USER
$ sudo systemctl restart docker
$ docker container run ubuntu:latest /bin/echo 'Hello World'

Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
5b7339215d1d: Pull complete 
14ca88e9f672: Pull complete 
a31c3b1caad4: Pull complete 
b054a26005b7: Pull complete 
Digest: sha256:9b1702dcfe32c873a770a32cfd306dd7fc1c4fd134adfb783db68defc8894b3c
Status: Downloaded newer image for ubuntu:latest
Hello World

Docker 버전확인 (docker version)#

$ docker version

 Version:           18.09.8
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        0dd43dd87f
 Built:             Wed Jul 17 17:40:31 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
  Version:          18.09.8
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.8
  Git commit:       0dd43dd
  Built:            Wed Jul 17 17:10:42 2019
  OS/Arch:          linux/amd64
  Experimental:     false

Docker 실행 환경 확인 (docker system info)#

$ docker system info

Containers: 1
 Running: 0
 Paused: 0
 Stopped: 1
Images: 1
Server Version: 18.09.8
Storage Driver: devicemapper
 Pool Name: docker-202:1-298884-pool
 Pool Blocksize: 65.54kB
 Base Device Size: 10.74GB
 Backing Filesystem: xfs
 Udev Sync Supported: true
 Data file: /dev/loop0
 Metadata file: /dev/loop1
 Data loop file: /var/lib/docker/devicemapper/devicemapper/data
 Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
 Data Space Used: 101.5MB
 Data Space Total: 107.4GB
 Data Space Available: 4.806GB
 Metadata Space Used: 737.3kB
 Metadata Space Total: 2.147GB
 Metadata Space Available: 2.147GB
 Thin Pool Minimum Free Space: 10.74GB
 Deferred Removal Enabled: true
 Deferred Deletion Enabled: true
 Deferred Deleted Device Count: 0
 Library Version: 1.02.149-RHEL7 (2018-07-20)
Logging Driver: json-file
Cgroup Driver: cgroupfs
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
runc version: 425e105d5a03fabd737a126ad93d62a9eeede87f
init version: fec3683
Security Options:
  Profile: default
Kernel Version: 3.10.0-693.2.2.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.63GiB
Name: 서버명
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
Live Restore Enabled: false
Product License: Community Engine

WARNING: the devicemapper storage-driver is deprecated, and will be removed in a future release.
WARNING: devicemapper: usage of loopback devices is strongly discouraged for production use.
         Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.

Docker 디스크 이용 상황 (docker system df)#

$ docker system df

TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
Images              1                   1                   64.18MB             0B (0%)
Containers          1                   0                   0B                  0B
Local Volumes       0                   0                   0B                  0B
Build Cache         0                   0                   0B                  0B

3.2 웹서버를 작동시켜 보자#

Docker 이미지 다운로드하기#

$ docker pull nginx

Using default tag: latest
latest: Pulling from library/nginx
0a4690c5d889: Pull complete 
9719afee3eb7: Pull complete 
44446b456159: Pull complete 
Digest: sha256:b4b9b3eee194703fc2fa8afa5b7510c77ae70cfba567af1376a573a967c03dbb
Status: Downloaded newer image for nginx:latest
$ docker image ls

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              98ebf73aba75        4 days ago          109MB
ubuntu              latest              4c108a37151f        4 weeks ago         64.2MB

Nginx 를 작동시켜 보자#

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


Nginx 작동 확인#

$ curl http://localhost:80

<!DOCTYPE html>
<title>Welcome to nginx!</title>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
<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>
$ docker container ps

CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                NAMES
5f58a7f235ae        nginx               "nginx -g 'daemon of…"   About a minute ago   Up About a minute>80/tcp   webserver

$ docker container stats webserver

CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT    MEM %               NET I/O             BLOCK I/O           PIDS
5f58a7f235ae        webserver           0.00%               1.379MiB / 7.63GiB   0.02%               627B / 1.27kB       6.9MB / 0B          2

Nginx의 기동및 정지#

$ docker stop webserver

$ docker start webserver


Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-8) was last changed on 24-Jul-2019 09:29 by DongGukLee