Docker
Overview
Docker is the world’s leading software container platform. Developers use Docker to eliminate “works on my machine” problems when collaborating on code with co-workers. Operators use Docker to run and manage apps side-by-side in isolated containers to get better compute density. Enterprises use Docker to build agile software delivery pipelines to ship new features faster, more securely and with confidence for both Linux and Windows Server apps.
What is a Container?
Using containers, everything required to make a piece of software run is packaged into isolated containers. Unlike VMs, containers do not bundle a full operating system - only libraries and settings required to make the software work are needed. This makes for efficient, lightweight, self-contained systems and guarantees that software will always run the same, regardless of where it’s deployed.
Comparing Containers and Virtual Machines
Containers and virtual machines have similar resource isolation and allocation benefits, but function differently because containers virtualize the operating system instead of hardware, containers are more portable and efficient.
CONTAINERS
Containers are an abstraction at the app layer that packages code and dependencies together. Multiple containers can run on the same machine and share the OS kernel with other containers, each running as isolated processes in user space. Containers take up less space than VMs (container images are typically tens of MBs in size), and start almost instantly.
VIRTUAL MACHINES
Virtual machines (VMs) are an abstraction of physical hardware turning one server into many servers. The hypervisor allows multiple VMs to run on a single machine. Each VM includes a full copy of an operating system, one or more apps, necessary binaries and libraries - taking up tens of GBs. VMs can also be slow to boot.
Containers and Virtual Machines Together
Containers and VMs used together provide a great deal of flexibility in deploying and managing apps.
Install
1. 查看系统版本 & 升级yum源
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@localhost ~]# yum update
2. 安装docker
[root@localhost ~]# yum install docker
3.启动docker deamon并将其设置成开机自启动
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
4.检查安装是否成功
[root@localhost ~]# docker version
Client:
Version: 1.12.6
API version: 1.24
Package version: docker-common-1.12.6-16.el7.centos.x86_64
Go version: go1.7.4
Git commit: 3a094bd/1.12.6
Built: Fri Apr 14 13:46:13 2017
OS/Arch: linux/amd64Server:
Version: 1.12.6
API version: 1.24
Package version: docker-common-1.12.6-16.el7.centos.x86_64
Go version: go1.7.4
Git commit: 3a094bd/1.12.6
Built: Fri Apr 14 13:46:13 2017
OS/Arch: linux/amd64
[root@localhost ~]# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 1.12.6
Storage Driver: devicemapper
Pool Name: docker-8:3-1605302-pool
Pool Blocksize: 65.54 kB
Base Device Size: 10.74 GB
Backing Filesystem: xfs
Data file: /dev/loop0
Metadata file: /dev/loop1
Data Space Used: 10.94 MB
Data Space Total: 107.4 GB
Data Space Available: 14.03 GB
Metadata Space Used: 581.6 kB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.147 GB
Thin Pool Minimum Free Space: 10.74 GB
Udev Sync Supported: true
Deferred Removal Enabled: false
Deferred Deletion Enabled: false
Deferred Deleted Device Count: 0
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
WARNING: Usage of loopback devices is strongly discouraged for production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.135-RHEL7 (2016-11-16)
Logging Driver: journald
Cgroup Driver: systemd
Plugins:
Volume: local
Network: host bridge null overlay
Swarm: inactive
Runtimes: docker-runc runc
Default Runtime: docker-runc
Security Options: seccomp selinux
Kernel Version: 3.10.0-514.16.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
Number of Docker Hooks: 2
CPUs: 1
Total Memory: 976.5 MiB
Name: localhost.localdomain
ID: Z45U:KWKE:UDH2:OYGR:SYHP:IKJK:B2I6:PYMO:4X73:NY7Z:2AQL:K4Z4
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Insecure Registries:
127.0.0.0/8
Registries: docker.io (secure)
5.docker WARNING: bridge-nf-call-iptables is disabled 处理
[root@localhost ~]# vim /etc/sysctl.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1-->(Reboot)
net.bridge.bridge-nf-call-arptables = 1
Usage
使用命令行的工具来检索名字为“tutorial”的镜像
[root@localhost ~]# docker search tutorial
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/georgeyord/reactjs-tutorial This is the backend of the React comment b... 4 [OK]
docker.io docker.io/egamas/docker-tutorial Funny manpages 2 [OK]
docker.io docker.io/mhausenblas/kairosdb-tutorial GitHub fetcher for KairosDB tutorial 1 [OK]
docker.io docker.io/mjansche/tts-tutorial Software for a Text-to-Speech tutorial 1 [OK]
docker.io docker.io/odk211/spree-tutorial 1 [OK]
docker.io docker.io/trausch/tutorial-delly Cancer Genomics Tutorial of Delly 1 [OK]
docker.io docker.io/activeeon/par-connector-tutorial Do the par-connector tutorial with R. The ... 0 [OK]
docker.io docker.io/ajyounge/muelu-tutorial Modified muelu tutorial 0 [OK]
docker.io docker.io/algas/wercker-tutorial wercker tutorial 0 [OK]
docker.io docker.io/biopython/biopython-tutorial Biopython with Tutorial running on top of ... 0 [OK]
docker.io docker.io/camphor/python-tutorial camphor-/python-tutorial 0 [OK]
docker.io docker.io/cazcade/weave-multicast-tutorial 0 [OK]
docker.io docker.io/chris24walsh/flask-aws-tutorial Runs a simple flask webapp demo, with the ... 0 [OK]
docker.io docker.io/delta2323/jnns2015-tutorial 0 [OK]
docker.io docker.io/filipe/react-tutorial React comment box example, React tutorial:... 0 [OK]
docker.io docker.io/guillon/qemu-tutorial Image for QEMU tutorial based on qemu-plugins 0 [OK]
docker.io docker.io/kobe25/docker-tutorial Docker Tutorial 0 [OK]
docker.io docker.io/locksmithdon/ssb-tutorial The image used in a Secure Scuttlebutt tut... 0 [OK]
docker.io docker.io/michelesr/docker-tutorial Docker Tutorial 0 [OK]
docker.io docker.io/onekit/rest-tutorial REST API server-side tutorial. How to do i... 0 [OK]
docker.io docker.io/paulcos11/docker-tutorial docker tutorial 0 [OK]
docker.io docker.io/rinnocente/gromed-ts-tutorial-2017 GRO[macs] + [plu]MED for the Trieste tutor... 0 [OK]
docker.io docker.io/rubygem/hydra-tutorial Auto-Generated Image for Ruby Gem hydra-tu... 0 [OK]
docker.io docker.io/sampige/koha-tutorial Koha Tutorial for Schools 0 [OK]
docker.io docker.io/zinuzoid/docker-swarm-tutorial-worker https://github.com/zinuzoid/docker-swarm-t... 0 [OK]
使用docker命令来下载镜像
[root@localhost ~]# docker pull learn/tutorial
Using default tag: latest
Trying to pull repository docker.io/learn/tutorial ...
latest: Pulling from docker.io/learn/tutorial
查看已下载的镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/learn/tutorial latest a7876479f1aa 4 years ago 128 MB
在docker容器中运行hello world!
docker run命令有两个参数,一个是镜像名,一个是要在镜像中运行的命令。
[root@localhost ~]# docker run learn/tutorial echo "hello world"
hello world
Ref:Docker Hub-Explore Official Repositories
Ref:Docker Home
Ref:Docker Community Edition for Mac
Ref:Docker — 从入门到实践
Ref:awesome-docker
Ref:持续集成的容器化实践
Ref:Docker入门实战
Ref:docker_practice
Ref:Docker 中文指南