Jeśłi ktoś nie korzysta z szablonu maszyny udostępnionej przeze mnie, to warto się upewnić, że pakiety docker i lxc zostaną usunięte;
1 2 |
$ apt-get purge lxc-docker* $ apt-get purge docker.io* |
Dodanie paczek potrzebnych do zarządzania kluczami repozytoriów apt:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
root@debian-template:~# apt-get install apt-transport-https ca-certificates Reading package lists... Done Building dependency tree Reading state information... Done ca-certificates is already the newest version. ca-certificates set to manually installed. The following NEW packages will be installed: apt-transport-https 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 138 kB of archives. After this operation, 195 kB of additional disk space will be used. Do you want to continue? [Y/n] Get:1 http://ftp.pl.debian.org/debian/ jessie/main apt-transport-https amd64 1.0.9.8.3 [138 kB] Fetched 138 kB in 0s (297 kB/s) Selecting previously unselected package apt-transport-https. (Reading database ... 42038 files and directories currently installed.) Preparing to unpack .../apt-transport-https_1.0.9.8.3_amd64.deb ... Unpacking apt-transport-https (1.0.9.8.3) ... Setting up apt-transport-https (1.0.9.8.3) ... root@debian-template:~# |
Dodanie klucza do repozytoriów docker:
1 2 3 4 5 6 7 |
root@debian-template:~# apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.kSIGmj8NNx --no-auto-check-trustdb --trust-model always --primary-keyring /etc/apt/trusted.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-jessie-automatic.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-jessie-security-automatic.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-jessie-stable.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-squeeze-automatic.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-squeeze-stable.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-wheezy-automatic.gpg --keyring /etc/apt/trusted.gpg.d/debian-archive-wheezy-stable.gpg --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D gpg: requesting key 2C52609D from hkp server p80.pool.sks-keyservers.net gpg: key 2C52609D: public key "Docker Release Tool (releasedocker) <docker@docker.com>" imported gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1) root@debian-template:~# |
Dodanie źródeł do rezpotorium apt:
1 |
root@debian-template:~# echo "deb https://apt.dockerproject.org/repo debian-jessie main" >> /etc/apt/sources.list.d/docker.list |
Aktualizacja źródeł dostępnych pakietów:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
root@debian-template:~# apt-get update Ign http://ftp.pl.debian.org jessie InRelease Hit http://ftp.pl.debian.org jessie-updates InRelease Hit http://security.debian.org jessie/updates InRelease Get:1 https://apt.dockerproject.org debian-jessie InRelease [20.6 kB] Hit http://ftp.pl.debian.org jessie Release.gpg (...) Get:12 https://apt.dockerproject.org debian-jessie/main Translation-en [454 B] Get:13 https://apt.dockerproject.org debian-jessie/main Translation-en_US [454 B] Ign https://apt.dockerproject.org debian-jessie/main Translation-en_US Get:14 https://apt.dockerproject.org debian-jessie/main Translation-en [454 B] Ign https://apt.dockerproject.org debian-jessie/main Translation-en Fetched 32.6 kB in 2s (11.7 kB/s) Reading package lists... Done root@debian-template:~# |
Installing docker:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
root@debian-template:~# apt-get install docker-engine Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: aufs-tools cgroupfs-mount git git-man libdrm2 liberror-perl libnih-dbus1 libnih1 makedev mountall plymouth rsync 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 desktop-base plymouth-themes The following NEW packages will be installed: aufs-tools cgroupfs-mount docker-engine git git-man libdrm2 liberror-perl libnih-dbus1 libnih1 makedev mountall plymouth rsync 0 upgraded, 13 newly installed, 0 to remove and 0 not upgraded. Need to get 19.9 MB of archives. After this operation, 98.7 MB of additional disk space will be used. Do you want to continue? [Y/n] Get:1 http://ftp.pl.debian.org/debian/ jessie/main libdrm2 amd64 2.4.58-2 [29.9 kB] Get:2 http://ftp.pl.debian.org/debian/ jessie/main makedev all 2.3.1-93 [42.6 kB] Get:3 https://apt.dockerproject.org/repo/ debian-jessie/main docker-engine amd64 1.11.2-0~jessie [14.3 MB] (...) Setting up libnih-dbus1 (1.0.3-4.3) ... Setting up mountall (2.54) ... Setting up aufs-tools (1:3.2+20130722-1.1) ... Setting up cgroupfs-mount (1.1) ... Setting up docker-engine (1.11.2-0~jessie) ... Setting up liberror-perl (0.17-1.1) ... Setting up git-man (1:2.1.4-2.1+deb8u2) ... Setting up git (1:2.1.4-2.1+deb8u2) ... Setting up rsync (3.1.1-3) ... Processing triggers for libc-bin (2.19-18+deb8u4) ... Processing triggers for systemd (215-17+deb8u4) ... Processing triggers for initramfs-tools (0.120+deb8u2) ... update-initramfs: Generating /boot/initrd.img-3.16.0-4-amd64 Processing triggers for dbus (1.8.20-0+deb8u1) ... root@debian-template:~# |
Uruchomienie docker:
1 |
root@debian-template:~# service docker start |
Testowe uruchomienie:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
root@debian-template:~# docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world a9d36faac0fe: Pull complete Digest: sha256:e52be8ffeeb1f374f440893189cd32f44cb166650e7ab185fa7735b7dc48d619 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. 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 Hub account: https://hub.docker.com For more examples and ideas, visit: https://docs.docker.com/engine/userguide/ root@debian-template:~# |
Uruchomienie kontenera z obrazem ubuntu:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
root@debian-template:~# docker run -t -i ubuntu /bin/bash Unable to find image 'ubuntu:latest' locally latest: Pulling from library/ubuntu 5ba4f30e5bea: Pull complete 9d7d19c9dc56: Pull complete ac6ad7efd0f9: Pull complete e7491a747824: Pull complete a3ed95caeb02: Pull complete Digest: sha256:46fb5d001b88ad904c5c732b086b596b92cfb4a4840a3abd0e35dbb6870585e4 Status: Downloaded newer image for ubuntu:latest root@28835ad68acb:/# |
Uruchomienie procesu w tle:
1 2 3 4 5 |
root@debian-template:~# docker run -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done" 02e481d32f16632bb04f923aeca23d23534adef72db1316436885f73d686ba14 root@debian-template:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 02e481d32f16 ubuntu "/bin/sh -c 'while tr" 2 seconds ago Up 2 seconds backstabbing_newton |
Sprawdzenie logów:
1 2 3 4 5 6 7 8 9 10 11 |
root@debian-template:~# docker logs 02e481d32f16 (....) hello world hello world hello world hello world hello world root@debian-template:~# |
Wyłączenie kontenera (uwaga – sprawdź czy identyfikator różni się po ponownym uruchomieniu tego samego procesu w tle):
1 2 3 4 5 |
root@debian-template:~# docker kill 02e481d32f16 02e481d32f16 root@debian-template:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES root@debian-template:~# |
Sprawdzenie kontenera i otrzymanie JSONa:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
root@debian-template:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3c9fc9fefbab ubuntu "/bin/sh -c 'while tr" 1 seconds ago Up 1 seconds mad_franklin root@debian-template:~# docker inspect mad_franklin [ { "Id": "3c9fc9fefbab3d7c6ec6f99e394f4c5540e0143ab8098a701d592af8edfca26a", "Created": "2016-06-20T22:19:07.334146191Z", "Path": "/bin/sh", "Args": [ "-c", "while true; do echo hello world; sleep 1; done" ], "State": { "Status": "running", "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 20188, "ExitCode": 0, "Error": "", "StartedAt": "2016-06-20T22:19:07.672991524Z", "FinishedAt": "0001-01-01T00:00:00Z" }, "Image": "sha256:2fa927b5cdd31cdec0027ff4f45ef4343795c7a2d19a9af4f32425132a222330", "ResolvConfPath": "/var/lib/docker/containers/3c9fc9fefbab3d7c6ec6f99e394f4c5540e0143ab8098a701d592af8edfca26a/resolv.conf", "HostnamePath": "/var/lib/docker/containers/3c9fc9fefbab3d7c6ec6f99e394f4c5540e0143ab8098a701d592af8edfca26a/hostname", "HostsPath": "/var/lib/docker/containers/3c9fc9fefbab3d7c6ec6f99e394f4c5540e0143ab8098a701d592af8edfca26a/hosts", "LogPath": "/var/lib/docker/containers/3c9fc9fefbab3d7c6ec6f99e394f4c5540e0143ab8098a701d592af8edfca26a/3c9fc9fefbab3d7c6ec6f99e394f4c5540e0143ab8098a701d592af8edfca26a-json.log", "Name": "/mad_franklin", "RestartCount": 0, "Driver": "aufs", "MountLabel": "", "ProcessLabel": "", "AppArmorProfile": "", "ExecIDs": null, "HostConfig": { "Binds": null, "ContainerIDFile": "", "LogConfig": { "Type": "json-file", "Config": {} }, "NetworkMode": "default", "PortBindings": {}, "RestartPolicy": { "Name": "no", "MaximumRetryCount": 0 }, "AutoRemove": false, "VolumeDriver": "", "VolumesFrom": null, "CapAdd": null, "CapDrop": null, "Dns": [], "DnsOptions": [], "DnsSearch": [], "ExtraHosts": null, "GroupAdd": null, "IpcMode": "", "Cgroup": "", "Links": null, "OomScoreAdj": 0, "PidMode": "", "Privileged": false, "PublishAllPorts": false, "ReadonlyRootfs": false, "SecurityOpt": null, "StorageOpt": null, "UTSMode": "", "UsernsMode": "", "ShmSize": 67108864, "ConsoleSize": [ 0, 0 ], (....) "NetworkSettings": { "Bridge": "", "SandboxID": "4243476b334e47ffb57685977b2c3b5a3e687fec601a32d6aede5fd006bc2960", "HairpinMode": false, "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "Ports": {}, "SandboxKey": "/var/run/docker/netns/4243476b334e", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "EndpointID": "a6fdc2ad719f81607664050f9695eb3a33825da3380466d85e7b2ec096538eb5", "Gateway": "172.17.0.1", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "IPAddress": "172.17.0.2", "IPPrefixLen": 16, "IPv6Gateway": "", "MacAddress": "02:42:ac:11:00:02", "Networks": { "bridge": { "IPAMConfig": null, "Links": null, "Aliases": null, "NetworkID": "b3b7633fba60b1e5f5f25d6e81532255ddf565169aea8ac0c07b04509eddbac0", "EndpointID": "a6fdc2ad719f81607664050f9695eb3a33825da3380466d85e7b2ec096538eb5", "Gateway": "172.17.0.1", "IPAddress": "172.17.0.2", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:ac:11:00:02" } } } } ] root@debian-template:~# |
Wyciągnięcie konkretnej wartości z JSON:
1 2 3 |
root@debian-template:~# docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mad_franklin 172.17.0.2 root@debian-template:~# |
Pobranie nowego obrazu:
1 2 3 4 5 6 7 8 9 10 11 |
root@debian-template:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest 693bce725149 12 days ago 967 B ubuntu latest 2fa927b5cdd3 3 weeks ago 122 MB root@debian-template:~# docker pull debian Using default tag: latest latest: Pulling from library/debian 5c90d4a2d1a8: Pull complete Digest: sha256:8b1fc3a7a55c42e3445155b2f8f40c55de5f8bc8012992b26b570530c4bded9e Status: Downloaded newer image for debian:latest root@debian-template:~# |
Automatyzacja tworzenia nowego obrazu:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
root@debian-template:~/netris# cat <<EOF > Dockerfile # Komentarz FROM debian MAINTAINER Maciej Kalkowski <maciej@kalkowski.name> RUN apt-get update && apt-get install -y netris RUN apt-get install -y iptraf EOF root@debian-template:~/netris# root@debian-template:~/netris# docker build -t debian . Sending build context to Docker daemon 2.048 kB Step 1 : FROM debian ---> 1b088884749b Step 2 : MAINTAINER Maciej Kalkowski <maciej@kalkowski.name> ---> Running in 0772042b779d ---> 48c000a08a32 Removing intermediate container 0772042b779d Step 3 : RUN apt-get update && apt-get install -y netris ---> Running in 12f2fe96461b Get:1 http://security.debian.org jessie/updates InRelease [63.1 kB] Ign http://httpredir.debian.org jessie InRelease Get:2 http://httpredir.debian.org jessie-updates InRelease [142 kB] Get:3 http://security.debian.org jessie/updates/main amd64 Packages [359 kB] Get:4 http://httpredir.debian.org jessie Release.gpg [2373 B] Get:5 http://httpredir.debian.org jessie Release [148 kB] Get:6 http://httpredir.debian.org jessie-updates/main amd64 Packages [17.6 kB] Get:7 http://httpredir.debian.org jessie/main amd64 Packages [9032 kB] Fetched 9765 kB in 8s (1172 kB/s) Reading package lists... Reading package lists... Building dependency tree... The following NEW packages will be installed: netris 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 42.0 kB of archives. After this operation, 98.3 kB of additional disk space will be used. Get:1 http://httpredir.debian.org/debian/ jessie/main netris amd64 0.52-9 [42.0 kB] debconf: delaying package configuration, since apt-utils is not installed Fetched 42.0 kB in 1s (40.5 kB/s) Selecting previously unselected package netris. (Reading database ... 7548 files and directories currently installed.) Preparing to unpack .../netris_0.52-9_amd64.deb ... Unpacking netris (0.52-9) ... Setting up netris (0.52-9) ... ---> 11e7cf6eca20 Removing intermediate container 12f2fe96461b Step 4 : RUN apt-get install -y iptraf ---> Running in 152cbe3a3b2a Reading package lists... Building dependency tree... Reading state information... The following NEW packages will be installed: iptraf 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 175 kB of archives. After this operation, 609 kB of additional disk space will be used. Get:1 http://httpredir.debian.org/debian/ jessie/main iptraf amd64 3.0.0-8.1 [175 kB] debconf: delaying package configuration, since apt-utils is not installed Fetched 175 kB in 1s (127 kB/s) Selecting previously unselected package iptraf. (Reading database ... 7562 files and directories currently installed.) Preparing to unpack .../iptraf_3.0.0-8.1_amd64.deb ... Unpacking iptraf (3.0.0-8.1) ... Setting up iptraf (3.0.0-8.1) ... ---> a8794fd3a0e3 Removing intermediate container 152cbe3a3b2a Successfully built a8794fd3a0e3 root@debian-template:~/netris# |
Uruchomienie netris:
1 2 |
root@debian-template:~/netris# docker run -it debian /bin/bash root@43f43309030d:/# /usr/games/netris |
Miłej zabawy!