1. 개요


2. Docker 설치와 시작

2.1. Ubuntu

$ sudo apt-get update
$ sudo apt install docker.io
$ sudo systemctl start docker
$ sudo systemctl enable docker

2.2. 레드햇 (CentOS, Amazon Linux..)

$ sudo yum install docker
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 0:18.06.1ce-10.amzn2 will be installed
--> Processing Dependency: pigz for package: docker-18.06.1ce-10.amzn2.x86_64
--> Processing Dependency: libcgroup for package: docker-18.06.1ce-10.amzn2.x86_64
--> Processing Dependency: libltdl.so.7()(64bit) for package: docker-18.06.1ce-10.amzn2.x86_64
--> Running transaction check
---> Package libcgroup.x86_64 0:0.41-21.amzn2 will be installed
---> Package libtool-ltdl.x86_64 0:2.4.2-22.2.amzn2.0.2 will be installed
---> Package pigz.x86_64 0:2.3.4-1.amzn2.0.1 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
=============================================================================================================================
 Package                    Arch                 Version                               Repository                       Size
=============================================================================================================================
Installing:
 docker                     x86_64               18.06.1ce-10.amzn2                    amzn2extra-docker                37 M
Installing for dependencies:
 libcgroup                  x86_64               0.41-21.amzn2                         amzn2-core                       66 k
 libtool-ltdl               x86_64               2.4.2-22.2.amzn2.0.2                  amzn2-core                       49 k
 pigz                       x86_64               2.3.4-1.amzn2.0.1                     amzn2-core                       81 k
 
Transaction Summary
=============================================================================================================================
Install  1 Package (+3 Dependent packages)
 
Total download size: 37 M
Installed size: 151 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): libcgroup-0.41-21.amzn2.x86_64.rpm                                                             |  66 kB  00:00:00
(2/4): libtool-ltdl-2.4.2-22.2.amzn2.0.2.x86_64.rpm                                                   |  49 kB  00:00:00
(3/4): pigz-2.3.4-1.amzn2.0.1.x86_64.rpm                                                              |  81 kB  00:00:00
(4/4): docker-18.06.1ce-10.amzn2.x86_64.rpm                                                           |  37 MB  00:00:00
-----------------------------------------------------------------------------------------------------------------------------
Total                                                                                         66 MB/s |  37 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libcgroup-0.41-21.amzn2.x86_64                                                                            1/4
  Installing : libtool-ltdl-2.4.2-22.2.amzn2.0.2.x86_64                                                                  2/4
  Installing : pigz-2.3.4-1.amzn2.0.1.x86_64                                                                             3/4
  Installing : docker-18.06.1ce-10.amzn2.x86_64                                                                          4/4
  Verifying  : docker-18.06.1ce-10.amzn2.x86_64                                                                          1/4
  Verifying  : pigz-2.3.4-1.amzn2.0.1.x86_64                                                                             2/4
  Verifying  : libtool-ltdl-2.4.2-22.2.amzn2.0.2.x86_64                                                                  3/4
  Verifying  : libcgroup-0.41-21.amzn2.x86_64                                                                            4/4
 
Installed:
  docker.x86_64 0:18.06.1ce-10.amzn2
 
Dependency Installed:
  libcgroup.x86_64 0:0.41-21.amzn2      libtool-ltdl.x86_64 0:2.4.2-22.2.amzn2.0.2      pigz.x86_64 0:2.3.4-1.amzn2.0.1
 
Complete!

3. Docker 프로세스 확인

$ ps -eaf|grep docker
root      3931     1  0 04:46 ?        00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ubuntu    4247  2033  0 04:48 pts/0    00:00:00 grep --color=auto docker

4. hello-world pull과 시작

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

5. Docker 컨테이너 확인

$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
e4bfbbeb1510        hello-world         "/hello"

6. Docker 이미지 확인

$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              fce289e99eb9        9 months ago        1.84kB

7. Docker 컨테이너 삭제

$ sudo docker rm e4bfbbeb1510
e4bfbbeb1510

8. Docker 이미지 삭제

$ sudo docker rmi fce289e99eb9
Untagged: hello-world:latest
Untagged: hello-world@sha256:b8ba256769a0ac28dd126d584e0a2011cd2877f3f76e093a7ae560f2a5301c00
Deleted: sha256:fce289e99eb9bca977dae136fbe2a82b6b7d4c372474c9235adc1741675f587e
Deleted: sha256:af0b15c8625bb1938f1d7b17081031f649fd14e6b233688eea3c5483994a66a3
$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE