1. 개요

아마존 리눅스에 도커를 설치해 봅시다.


2. 시작

sudo yum 한줄로 깔 수 있습니다. 참 쉽죠.

$ sudo yum install docker
Loaded plugins: priorities, update-motd, upgrade-helper
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 0:17.12.0ce-1.129.amzn1 will be installed
--> Processing Dependency: xfsprogs for package: docker-17.12.0ce-1.129.amzn1.x86_64
--> Processing Dependency: libseccomp.so.2()(64bit) for package: docker-17.12.0ce-1.129.amzn1.x86_64
--> Processing Dependency: libltdl.so.7()(64bit) for package: docker-17.12.0ce-1.129.amzn1.x86_64
--> Running transaction check
---> Package libseccomp.x86_64 0:2.3.1-2.4.amzn1 will be installed
---> Package libtool-ltdl.x86_64 0:2.4.2-20.4.8.5.32.amzn1 will be installed
---> Package xfsprogs.x86_64 0:4.5.0-9.21.amzn1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================================
 Package                           Arch                        Version                                       Repository                         Size
=====================================================================================================================================================
Installing:
 docker                            x86_64                      17.12.0ce-1.129.amzn1                         amzn-updates                       34 M
Installing for dependencies:
 libseccomp                        x86_64                      2.3.1-2.4.amzn1                               amzn-main                          79 k
 libtool-ltdl                      x86_64                      2.4.2-20.4.8.5.32.amzn1                       amzn-main                          51 k
 xfsprogs                          x86_64                      4.5.0-9.21.amzn1                              amzn-main                         1.7 M

Transaction Summary
=====================================================================================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 36 M
Installed size: 114 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): xfsprogs-4.5.0-9.21.amzn1.x86_64.rpm                                                                                   | 1.7 MB  00:00:00
(2/4): libtool-ltdl-2.4.2-20.4.8.5.32.amzn1.x86_64.rpm                                                                        |  51 kB  00:00:00
(3/4): libseccomp-2.3.1-2.4.amzn1.x86_64.rpm                                                                                  |  79 kB  00:00:00
(4/4): docker-17.12.0ce-1.129.amzn1.x86_64.rpm                                                                                                  |  34 MB  00:00:08
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                  4.2 MB/s |  36 MB  00:00:08
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libseccomp-2.3.1-2.4.amzn1.x86_64                                                                                                                   1/4
  Installing : libtool-ltdl-2.4.2-20.4.8.5.32.amzn1.x86_64                                                                                                         2/4
  Installing : xfsprogs-4.5.0-9.21.amzn1.x86_64                                                                                                                    3/4
  Installing : docker-17.12.0ce-1.129.amzn1.x86_64                                                                                                                 4/4
  Verifying  : docker-17.12.0ce-1.129.amzn1.x86_64                                                                                                                 1/4
  Verifying  : xfsprogs-4.5.0-9.21.amzn1.x86_64                                                                                                                    2/4
  Verifying  : libtool-ltdl-2.4.2-20.4.8.5.32.amzn1.x86_64                                                                                                         3/4
  Verifying  : libseccomp-2.3.1-2.4.amzn1.x86_64                                                                                                                   4/4

Installed:
  docker.x86_64 0:17.12.0ce-1.129.amzn1

Dependency Installed:
  libseccomp.x86_64 0:2.3.1-2.4.amzn1                 libtool-ltdl.x86_64 0:2.4.2-20.4.8.5.32.amzn1                 xfsprogs.x86_64 0:4.5.0-9.21.amzn1

Complete!

3. 실행

$ docker

Usage:  docker COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default "/home/ec2-user/.docker")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket(s) to connect to
  -l, --log-level string   Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default "/home/ec2-user/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default "/home/ec2-user/.docker/cert.pem")
      --tlskey string      Path to TLS key file (default "/home/ec2-user/.docker/key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit

Management Commands:
  checkpoint  Manage checkpoints
  config      Manage Docker configs
  container   Manage containers
  image       Manage images
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  secret      Manage Docker secrets
  service     Manage services
  stack       Manage Docker stacks
  swarm       Manage Swarm
  system      Manage Docker
  trust       Manage trust on Docker images (experimental)
  volume      Manage volumes

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  build       Build an image from a Dockerfile
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  deploy      Deploy a new stack or update an existing stack
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  images      List images
  import      Import the contents from a tarball to create a filesystem image
  info        Display system-wide information
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  login       Log in to a Docker registry
  logout      Log out from a Docker registry
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  ps          List containers
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  run         Run a command in a new container
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  search      Search the Docker Hub for images
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  version     Show the Docker version information
  wait        Block until one or more containers stop, then print their exit codes

Run 'docker COMMAND --help' for more information on a command.

4. Docker 서비스 실행

$ sudo service docker start
Starting cgconfig service:                                 [  OK  ]
Starting docker:        .                                  [  OK  ]

5. 관련 에러 해결

5-1. Docker 서비스가 안떠있음

$ docker version
Client:
 Version:       17.12.0-ce
 API version:   1.35
 Go version:    go1.9.2
 Git commit:    3dfb8343b139d6342acfd9975d7f1068b5b1c3d3
 Built: Mon Mar  5 20:42:27 2018
 OS/Arch:       linux/amd64
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

5-2. root 권한이 없음

$ docker version
Client:
 Version:       17.12.0-ce
 API version:   1.35
 Go version:    go1.9.2
 Git commit:    3dfb8343b139d6342acfd9975d7f1068b5b1c3d3
 Built: Mon Mar  5 20:42:27 2018
 OS/Arch:       linux/amd64
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.35/version: dial unix /var/run/docker.sock: connect: permission denied
[ec2-user@ip-10-0-30-225 ~]$ sudo docker version