Docker is a new virtualization solution based on any kernel 3.10 Linux machine.
Start from a CentOS virtual machine :
- CentOS 7.2 :
[root@docker ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core)
- Built on kernel 3.10 :
[root@docker ~]# uname -sr Linux 3.10.0-327.3.1.el7.x86_64
Install “docker” :
[root@docker ~]# yum -y install docker docker-registry
Here is the “docker” version :
[root@docker ~]# docker --version Docker version 1.8.2-el7.centos, build a01dc02/1.8.2
Start “docker” service :
[root@docker ~]# systemctl start docker
And across reboot :
[root@docker ~]# systemctl enable docker Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
See the status :
[root@docker ~]# systemctl status -l docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled) Active: active (running) since Thu 2016-01-14 17:39:23 CET; 1min 3s ago Docs: http://docs.docker.com Main PID: 10456 (docker) CGroup: /system.slice/docker.service └─10456 /usr/bin/docker daemon --selinux-enabled Jan 14 17:39:21 docker docker[10456]: time="2016-01-14T17:39:21.972418994+01:00" level=info msg="[graphdriver] using prior storage driver \"devicemapper\"" Jan 14 17:39:22 docker docker[10456]: time="2016-01-14T17:39:22.158229708+01:00" level=info msg="Option DefaultDriver: bridge" Jan 14 17:39:22 docker docker[10456]: time="2016-01-14T17:39:22.158290877+01:00" level=info msg="Option DefaultNetwork: bridge" Jan 14 17:39:22 docker docker[10456]: time="2016-01-14T17:39:22.859228257+01:00" level=warning msg="Running modprobe bridge nf_nat br_netfilter failed with message: modprobe: WARNING: Module br_netfilter not found.\n, error: exit status 1" Jan 14 17:39:22 docker docker[10456]: time="2016-01-14T17:39:22.939999470+01:00" level=info msg="Firewalld running: true" Jan 14 17:39:23 docker docker[10456]: time="2016-01-14T17:39:23.893386078+01:00" level=info msg="Loading containers: start." Jan 14 17:39:23 docker docker[10456]: time="2016-01-14T17:39:23.893721869+01:00" level=info msg="Loading containers: done." Jan 14 17:39:23 docker docker[10456]: time="2016-01-14T17:39:23.893752472+01:00" level=info msg="Daemon has completed initialization" Jan 14 17:39:23 docker docker[10456]: time="2016-01-14T17:39:23.893780510+01:00" level=info msg="Docker daemon" commit="a01dc02/1.8.2" execdriver=native-0.2 graphdriver=devicemapper version=1.8.2-el7.centos Jan 14 17:39:23 docker systemd[1]: Started Docker Application Container Engine.
Docker images
Currently, we have no images installed :
[root@docker ~]# docker images -a REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
Looking for existing image (Ubuntu for example) we can download (only 25 results are displayed) ?
[root@docker ~]# docker search ubuntu INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED docker.io docker.io/ubuntu Ubuntu is a Debian-based Linux operating s... 2915 [OK] docker.io docker.io/ubuntu-upstart Upstart is an event-based replacement for ... 57 [OK] docker.io docker.io/dorowu/ubuntu-desktop-lxde-vnc Ubuntu with openssh-server and NoVNC on po... 30 [OK] docker.io docker.io/torusware/speedus-ubuntu Always updated official Ubuntu docker imag... 25 [OK] docker.io docker.io/ubuntu-debootstrap debootstrap --variant=minbase --components... 21 [OK] docker.io docker.io/tleyden5iwx/ubuntu-cuda Ubuntu 14.04 with CUDA drivers pre-installed 18 [OK] docker.io docker.io/neurodebian NeuroDebian provides neuroscience research... 15 [OK] docker.io docker.io/rastasheep/ubuntu-sshd Dockerized SSH service, built on top of of... 15 [OK] docker.io docker.io/sameersbn/ubuntu 5 [OK] docker.io docker.io/nuagebec/ubuntu Simple always updated Ubuntu docker images... 4 [OK] docker.io docker.io/nimmis/ubuntu This is a docker images different LTS vers... 3 [OK] docker.io docker.io/maxexcloo/ubuntu Docker base image built on Ubuntu with Sup... 2 [OK] docker.io docker.io/nickistre/ubuntu-lamp-wordpress LAMP on Ubuntu with wp-cli installed 2 [OK] docker.io docker.io/densuke/ubuntu-jp-remix Ubuntu Linuxの日本語remix風味です 1 [OK] docker.io docker.io/isuper/base-ubuntu This is just a small and clean base Ubuntu... 1 [OK] docker.io docker.io/nickistre/ubuntu-lamp LAMP server on Ubuntu 1 [OK] docker.io docker.io/seetheprogress/ubuntu Ubuntu image provided by seetheprogress us... 1 [OK] docker.io docker.io/sylvainlasnier/ubuntu Ubuntu 15.10 root docker images with commo... 1 [OK] docker.io docker.io/birkof/ubuntu Ubuntu 14.04 LTS (Trusty Tahr) 0 [OK] docker.io docker.io/esycat/ubuntu Ubuntu LTS 0 [OK] docker.io docker.io/konstruktoid/ubuntu Ubuntu base image 0 [OK] docker.io docker.io/rallias/ubuntu Ubuntu with the needful 0 [OK] docker.io docker.io/teamrock/ubuntu TeamRock's Ubuntu image configured with AW... 0 [OK] docker.io docker.io/webhippie/ubuntu Docker images for ubuntu 0 [OK] docker.io docker.io/zoni/ubuntu 0 [OK]
Open a web browser on Docker Hub, then search “Ubuntu” :
Download Ubuntu “official” image :
[root@docker ~]# docker pull ubuntu Using default tag: latest Trying to pull repository docker.io/library/ubuntu ... latest: Pulling from library/ubuntu 895b070402bd: Pull complete 02e5bca4149b: Pull complete b2ae0a712b39: Pull complete af88597ec24b: Pull complete library/ubuntu:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security. Digest: sha256:b53bb7b0d18842214ac7472c2a8801e8682c247d30f1ba4bab0083a2e2e091ea Status: Downloaded newer image for docker.io/ubuntu:latest
So, now we have those images :
[root@docker ~]# docker images -a REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE docker.io/ubuntu latest af88597ec24b 10 days ago 187.9 MB <none> <none> b2ae0a712b39 10 days ago 187.9 MB <none> <none> 02e5bca4149b 10 days ago 187.9 MB <none> <none> 895b070402bd 10 days ago 187.7 MB
My first container
Create your first container :
[root@docker ~]# docker run -t -i -d ubuntu ba33baf11d62470265d8995b41e4ceb1ec68708d100f6b4c4c9f90c132deb0d0
Where :
- -t : Allocate a pseudo-TTY
- -i : Keep STDIN open even if not attached
- -d : Run container in background and print container ID
This container is now running :
[root@docker ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ba33baf11d62 ubuntu "/bin/bash" 4 minutes ago Up 4 minutes furious_cori
To logon to this container :
[root@docker ~]# docker exec -t -i furious_cori bash
root@ba33baf11d62:/# id uid=0(root) gid=0(root) groups=0(root)
root@ba33baf11d62:/# lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 14.04.3 LTS Release: 14.04 Codename: trusty
root@ba33baf11d62:/# exit exit
Stop this container :
[root@docker ~]# docker stop furious_cori furious_cori
This container is still there, but not running anymore :
[root@docker ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ba33baf11d62 ubuntu "/bin/bash" 24 minutes ago Exited (0) About a minute ago furious_cori
To remove it :
[root@docker ~]# docker rm furious_cori furious_cori
How to run several Linux containers on the same docker machine ?
We saw on Docker Hub :
Supported tags and respective Dockerfile links 12.04.5, 12.04, precise-20151208, precise (precise/Dockerfile) 14.04.3, 14.04, trusty-20151218, trusty, latest (trusty/Dockerfile) 15.04, vivid-20151208, vivid (vivid/Dockerfile) 15.10, wily-20151208, wily (wily/Dockerfile) 16.04, xenial-20151218.1, xenial (xenial/Dockerfile)
Install fedora ;
[root@docker ~]# docker pull fedora
[root@docker ~]# docker pull centos
We have now those images :
[root@docker ~]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE docker.io/fedora latest 0721f2b3cb16 10 days ago 206.3 MB docker.io/ubuntu latest af88597ec24b 10 days ago 187.9 MB docker.io/centos latest 60e65a8e4030 3 weeks ago 196.6 MB
Create and run a fedora container :
[root@docker ~]# docker run -t -i -d --name fedora fedora /bin/bash 3182473dc136356415957ea0c4cb59bbfe990cb70454f4f54c9cd7e581edd6e1
Create and run a CentOS container :
[root@docker ~]# docker run -t -i -d --name CentOS centos /bin/bash ebae479717acfcbfa71e80224aac6bd8b41cf1e5a10e7e7dc0eba4879bdc7961
We have now 2 containers running :
[root@docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ebae479717ac centos "/bin/bash" 31 seconds ago Up 30 seconds CentOS 3182473dc136 fedora "/bin/bash" 2 minutes ago Up 2 minutes fedora
Logon to the “CentOS” container :
[root@docker ~]# docker exec -t -i CentOS bash [root@ebae479717ac /]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@ebae479717ac /]# exit
Logon to the “fedora container” :
[root@docker ~]# docker exec -t -i fedora bash [root@3182473dc136 /]# cat /etc/redhat-release Fedora release 23 (Twenty Three) [root@3182473dc136 /]# exit exit

No comments:
Post a Comment