Showing posts with label container. Show all posts
Showing posts with label container. Show all posts

2015-02-26

Docker: The Software Container

Docker is operating system-level virtualization, software container that enables sysadmin or software developer to deploy an isolated distributed Linux application almost anywhere without any hypervisor (but both can be combined). Docker is more resource friendly (efficient) than any hardware virtualization solutions, faster startup-shutdown time, and lower hardware requirement (it works as long as you have Linux kernel that support LXC). Docker can run on Mac OS X and Windows via boot2docker (or with Vagrant or any virtualization software). To install it on ArchLinux, type:

# install stable version
$ yaourt --needed --noconfirm -S --force docker

# or latest git version
$ yaourt --needed --noconfirm -S --force docker-git

# start and enable the service
$ sudo systemctl enable docker
$ sudo systemctl start docker

# allow your user to access docker, refresh session
$ sudo gpasswd -a `whoami` docker
$ newgrp docker

# show information
$ docker info
Containers: 0
Images: 0
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 0
Execution Driver: native-0.2
Kernel Version: 3.18.7-1-ARCH
Operating System: ArchLinux
CPUs: 4
Total Memory: 15.49 GiB
Name: zzz
ID: 5SDJ:LPNU:UAR4:ULRJ:REZF:4V3W:6ES6:KJTW:DETH:765Y:XP4I:IZZZ

WARNING: No swap limit support

The docker service will create a network bridge interface (mostly docker0). You can use your own base image or download pre-built one. Make sure you have a lot disk space on your /var/lib/docker directory since docker store the images there. To create an ArchLinux base image, use any of these repositories, for example:

$ docker pull l3iggs/archlinux
$ docker pull kampka/archlinux
$ docker pull codekoala/arch

$ docker pull logankoester/archlinux 
Pulling repository logankoester/archlinux
88d601db3077: Download complete 
511136ea3c5a: Download complete 
9b0516337e5a: Download complete 
dce0559daa1b: Download complete 
ff4d9d90bf08: Download complete 
7207641fe7f8: Download complete 
Status: Downloaded newer image for logankoester/archlinux:latest

To list all docker images, type docker images, find the image's REPOSITORY or IMAGE ID, then you can run any command on that docker using docker run for example:

$ docker run 88d601db3077 ls -al
...

docker run -t -i logankoester/archlinux /bin/bash
exit

$ docker run logankoester/archlinux pacman -Rdd --noconfirm dirmngr

Packages (1): dirmngr-1.1.1-2

Total Removed Size:   0.49 MiB

:: Do you want to remove these packages? [Y/n] 

removing dirmngr...

$ docker run logankoester/archlinux pacman -Syu --noconfirm
:: Synchronizing package databases...
downloading core.db...
downloading extra.db...
downloading community.db...
:: Starting full system upgrade...
:: Replace dirmngr with core/gnupg? [Y/n] 
:: Replace lzo2 with core/lzo? [Y/n] 
resolving dependencies...
looking for inter-conflicts...

Packages (77): archlinux-keyring-20150212-1  bash-4.3.033-1  ca-certificates-20140923-9  ca-certificates-cacert-20140824-2  ca-certificates-mozilla-3.17.4-1  ca-certificates-utils-20140923-9  coreutils-8.23-1  cracklib-2.9.1-1  curl-7.40.0-1  db-5.3.28-2  dbus-1.8.16-2  device-mapper-2.02.116-1  dhcpcd-6.7.1-1  dirmngr-1.1.1-2 [removal]  e2fsprogs-1.42.12-1  expat-2.1.0-4  file-5.22-1  filesystem-2015.02-1  gcc-libs-4.9.2-3  gettext-0.19.4-1  glib2-2.42.1-1  glibc-2.21-2  gmp-6.0.0-2  gnupg-2.1.2-1  gnutls-3.3.12-1  gpgme-1.5.3-1  grep-2.21-1  hwids-20150129-1  inetutils-1.9.2-2  iproute2-3.18.0-1  kbd-2.0.2-1  kmod-19-1  krb5-1.13.1-1  less-471-1  libarchive-3.1.2-8  libassuan-2.1.3-1  libcap-2.24-2  libdbus-1.8.16-2  libffi-3.2.1-1  libgcrypt-1.6.2-1  libgpg-error-1.18-1  libidn-1.29-1  libksba-1.3.2-1  libldap-2.4.40-2  libsystemd-218-2  libtasn1-4.2-1  libtirpc-0.2.5-1  libunistring-0.9.4-1  libutil-linux-2.25.2-1  linux-api-headers-3.18.5-1  logrotate-3.8.8-2  lz4-127-1  lzo-2.09-1  lzo2-2.08-1 [removal]  mpfr-3.1.2.p11-1  ncurses-5.9-7  netctl-1.10-1  nettle-2.7.1-1  npth-1.1-1  openresolv-3.6.1-1  openssl-1.0.2-1  p11-kit-0.22.1-3  pacman-4.2.1-1  pacman-mirrorlist-20150205-1  pcre-8.36-2  perl-5.20.2-1  pinentry-0.9.0-1  procps-ng-3.3.10-1  shadow-4.2.1-2  systemd-218-2  systemd-sysvcompat-218-2  tar-1.28-1  texinfo-5.2-3  tzdata-2015a-1  usbutils-008-1  util-linux-2.25.2-1  xz-5.2.0-1

Total Download Size:    62.40 MiB
Total Installed Size:   264.78 MiB
Net Upgrade Size:       26.52 MiB


:: Proceed with installation? [Y/n] 

:: Retrieving packages ...
...

The previous changes of each run is not saved until you call docker commit, find out the last run ID first before committing:

$ docker ps -l 
CONTAINER ID        IMAGE                           COMMAND                CREATED             STATUS                     PORTS               NAMES
6d67ee44e7f5        logankoester/archlinux:latest   "pacman -Syu --nocon   11 minutes ago      Exited (0) 2 minutes ago                       stoic_meitner 

# docker commit ID your_username/your_repository
$ docker commit 6d67ee44e7f5 kokizzu/archlinux
5ab1562ea89959c54b8da4462abf086c91434524ae741769dab869b8263d7c1b

To check more information about current dock, use docker inspect followed by image ID:

$ docker images 
REPOSITORY               TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
kokizzu/archlinux        latest              5ab1562ea899        28 seconds ago      640.6 MB
logankoester/archlinux   latest              88d601db3077        24 hours ago        282.9 MB
...

# docker inspect ID
$ docker inspect 5ab1562ea899


After you verify that your image is working, you can share it to others (create a repository first on your dashboard), for example:

# docker push ID your_username/your_repository

You can find more information on the cheatsheet and the documentation, and if you're tempted to install sshd read this first.