Docker je open-source projekt, který umožňuje izolovat aplikace do kontejnerů. Kontejnery sdílejí jádro operačního systému. Spuštění kontejneru pro operační systém znamená spuštění procesu, nikoliv kompletní virtualizace operačního systému. Tím pádem je spuštění kontejneru(ů) méně náročné na zdroje a je jich možno spustit více než virtuálních strojů.
Instalace pro Ubuntu je dobře popsána na stránkách dockeru (viz. zde). Zde ji ukážu krok za krokem.
vitfo@vitfo-VirtualBox:~$ sudo apt-get update [sudo] password for vitfo: Hit:1 http://security.ubuntu.com/ubuntu xenial-security InRelease Hit:2 http://cz.archive.ubuntu.com/ubuntu xenial InRelease Hit:3 http://cz.archive.ubuntu.com/ubuntu xenial-updates InRelease Hit:4 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial InRelease Hit:5 http://cz.archive.ubuntu.com/ubuntu xenial-backports InRelease Reading package lists... Done
vitfo@vitfo-VirtualBox:~$ sudo apt-get install apt-transport-https ca-certificates curl software-properties-common Reading package lists... Done Building dependency tree Reading state information... Done apt-transport-https is already the newest version (1.2.24). ca-certificates is already the newest version (20170717~16.04.1). software-properties-common is already the newest version (0.96.20.7). The following NEW packages will be installed: curl 0 upgraded, 1 newly installed, 0 to remove and 152 not upgraded. Need to get 138 kB of archives. After this operation, 339 kB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://cz.archive.ubuntu.com/ubuntu xenial-updates/main amd64 curl amd64 7.47.0-1ubuntu2.5 [138 kB] Fetched 138 kB in 1s (107 kB/s) Selecting previously unselected package curl. (Reading database ... 211749 files and directories currently installed.) Preparing to unpack .../curl_7.47.0-1ubuntu2.5_amd64.deb ... Unpacking curl (7.47.0-1ubuntu2.5) ... Processing triggers for man-db (2.7.5-1) ... Setting up curl (7.47.0-1ubuntu2.5) ...
vitfo@vitfo-VirtualBox:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - OK
vitfo@vitfo-VirtualBox:~$ sudo apt-key fingerprint 0EBFCD88 pub 4096R/0EBFCD88 2017-02-22 Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 uid Docker Release (CE deb) <docker@docker.com> sub 4096R/F273FCD8 2017-02-22
Přidání repozitáře, ze kterého pak stáhneme docker.
vitfo@vitfo-VirtualBox:~$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Po přidání repozitáře je třeba provést update.
vitfo@vitfo-VirtualBox:~$ sudo apt-get update Hit:1 http://security.ubuntu.com/ubuntu xenial-security InRelease Hit:2 http://cz.archive.ubuntu.com/ubuntu xenial InRelease Hit:3 http://cz.archive.ubuntu.com/ubuntu xenial-updates InRelease Hit:4 http://cz.archive.ubuntu.com/ubuntu xenial-backports InRelease Hit:5 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial InRelease Get:6 https://download.docker.com/linux/ubuntu xenial InRelease [49,8 kB] Get:7 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages [3 150 B] Fetched 53,0 kB in 2s (23,4 kB/s) Reading package lists... Done
Samotná instalace dockeru.
vitfo@vitfo-VirtualBox:~$ sudo apt-get install docker-ce Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: aufs-tools cgroupfs-mount git git-man liberror-perl Suggested packages: git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-arch git-cvs git-mediawiki git-svn The following NEW packages will be installed: aufs-tools cgroupfs-mount docker-ce git git-man liberror-perl 0 upgraded, 6 newly installed, 0 to remove and 152 not upgraded. Need to get 34,1 MB of archives. After this operation, 175 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://cz.archive.ubuntu.com/ubuntu xenial/universe amd64 aufs-tools amd64 1:3.2+20130722-1.1ubuntu1 [92,9 kB] Get:2 http://cz.archive.ubuntu.com/ubuntu xenial/universe amd64 cgroupfs-mount all 1.2 [4 970 B] Get:3 http://cz.archive.ubuntu.com/ubuntu xenial/main amd64 liberror-perl all 0.17-1.2 [19,6 kB] Get:4 http://cz.archive.ubuntu.com/ubuntu xenial-updates/main amd64 git-man all 1:2.7.4-0ubuntu1.3 [736 kB] Get:5 http://cz.archive.ubuntu.com/ubuntu xenial-updates/main amd64 git amd64 1:2.7.4-0ubuntu1.3 [3 102 kB] Get:6 https://download.docker.com/linux/ubuntu xenial/stable amd64 docker-ce amd64 17.12.0~ce-0~ubuntu [30,2 MB] Fetched 34,1 MB in 1s (23,7 MB/s) Selecting previously unselected package aufs-tools. (Reading database ... 211756 files and directories currently installed.) Preparing to unpack .../aufs-tools_1%3a3.2+20130722-1.1ubuntu1_amd64.deb ... Unpacking aufs-tools (1:3.2+20130722-1.1ubuntu1) ... Selecting previously unselected package cgroupfs-mount. Preparing to unpack .../cgroupfs-mount_1.2_all.deb ... Unpacking cgroupfs-mount (1.2) ... Selecting previously unselected package docker-ce. Preparing to unpack .../docker-ce_17.12.0~ce-0~ubuntu_amd64.deb ... Unpacking docker-ce (17.12.0~ce-0~ubuntu) ... Selecting previously unselected package liberror-perl. Preparing to unpack .../liberror-perl_0.17-1.2_all.deb ... Unpacking liberror-perl (0.17-1.2) ... Selecting previously unselected package git-man. Preparing to unpack .../git-man_1%3a2.7.4-0ubuntu1.3_all.deb ... Unpacking git-man (1:2.7.4-0ubuntu1.3) ... Selecting previously unselected package git. Preparing to unpack .../git_1%3a2.7.4-0ubuntu1.3_amd64.deb ... Unpacking git (1:2.7.4-0ubuntu1.3) ... Processing triggers for libc-bin (2.23-0ubuntu10) ... Processing triggers for man-db (2.7.5-1) ... Processing triggers for ureadahead (0.100.0-19) ... Processing triggers for systemd (229-4ubuntu19) ... Setting up aufs-tools (1:3.2+20130722-1.1ubuntu1) ... Setting up cgroupfs-mount (1.2) ... Setting up docker-ce (17.12.0~ce-0~ubuntu) ... Setting up liberror-perl (0.17-1.2) ... Setting up git-man (1:2.7.4-0ubuntu1.3) ... Setting up git (1:2.7.4-0ubuntu1.3) ... Processing triggers for libc-bin (2.23-0ubuntu10) ... Processing triggers for systemd (229-4ubuntu19) ... Processing triggers for ureadahead (0.100.0-19) ...
Zkušební spuštění.
vitfo@vitfo-VirtualBox:~$ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world ca4f61b1923c: Pull complete Digest: sha256:66ef312bbac49c39a89aa9bcc3cb4f3c9e7de3788c944158df3ee0176d32b751 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://cloud.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/
Příkazem docker run hello-world říkáme, že chceme vytvořit a spustit kontejner z image hello-world. Docker lokálně žádný image hello-world nemá a proto se připojí na Docker hub (veřejné úložiště images). Image stáhne, vytvoří kontejner a spustí ho. Z kontejneru se vypíše zpráva a kontejner se vypne.
Zdroje: