容器是輕量級的,包含應用運行所需全部東西(代碼、庫、運行時環境、系統設置,以及依賴關係)的獨立的包。每一個容器都部署於它本身的 CPU、內存、塊 I/O,以及網絡資源上,全部這些都不依賴於某個內核和操做系統。這也是容器與虛擬機之間最大的不一樣;相比之下,虛擬機是一個運行於宿主機操做系統上的完整的操做系統平臺,而容器不是。容器容許你以一種史無前例的方式擴展交付能力(無論內部仍是外部的)html
docker和VM虛擬機的區別在於:python
docker發行版本分爲:linux
docker安裝環境:c++
Docker 平臺基本上由三部分組成:git
# 查看系統開發環境 [root@VM_0_10_centos docker_install]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) # 查看系統內核版本 [root@VM_0_10_centos docker_install]# uname -a Linux VM_0_10_centos 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux 或 [root@VM_0_10_centos docker_install]# cat /proc/version Linux version 3.10.0-957.21.3.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-3 6) (GCC) ) #1 SMP Tue Jun 18 16:35:19 UTC 2019
在增長Docker阿里雲yum源以前須要執行基礎組件安裝以及卸載歷史版本:github
# 基礎組件安裝 [root@VM_0_10_centos docker_install]# yum -y install gcc gcc-c++ # 卸載歷史版本 [root@VM_0_10_centos docker_install]# yum -y remove docker docker-common docker-selinux docker-engine Loaded plugins: fastestmirror, langpacks No Match for argument: docker No Match for argument: docker-common No Match for argument: docker-selinux No Match for argument: docker-engine No Packages marked for removal # 或刪除已安裝的docker [root@VM_0_10_centos docker_install]# yum -y remove docker \ > docker-client \ > docker-client-latest \ > docker-common \ > docker-latest \ > docker-latest-logrotate \ > docker-selinux \ > docker-engine-selinux \ > docker-engine Loaded plugins: fastestmirror, langpacks No Match for argument: docker No Match for argument: docker-client No Match for argument: docker-client-latest No Match for argument: docker-common No Match for argument: docker-latest No Match for argument: docker-latest-logrotate No Match for argument: docker-selinux No Match for argument: docker-engine-selinux No Match for argument: docker-engine No Packages marked for removal
PS:Docker部署要求64位的系統且內核版本至少爲3.10docker
# 查看yum
[root@VM_0_10_centos docker_install]# yum -y install epel-release [root@VM_0_10_centos docker_install]# yum clean all Loaded plugins: fastestmirror, langpacks Repository epel is listed more than once in the configuration Cleaning repos: epel extras os updates Cleaning up list of fastest mirrors [root@VM_0_10_centos docker_install]# yum list
# 安裝yum工具 [root@VM_0_10_centos docker_install]# yum -y install yum-utils device-mapper-persistent-data lvm2 # 配置docker阿里雲yum源 [root@VM_0_10_centos docker_install]# yum-config-manager --add-repo=http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks Repository epel is listed more than once in the configuration adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo repo saved to /etc/yum.repos.d/docker-ce.repo # 更新yum緩存 [root@VM_0_10_centos docker_install]# yum -y makecache fast # 查看對應版本 [root@VM_0_10_centos docker_install]# yum list docker-ce --showduplicates
# 安裝yum install docker-ce docker-ce-cli 或者 yum install docker-io –y [root@VM_0_10_centos docker_install]# yum -y install docker-ce docker-ce-cli
[root@VM_0_10_centos docker_install]# systemctl start docker [root@VM_0_10_centos docker_install]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@VM_0_10_centos docker_install]# docker -v Docker version 19.03.5, build 633a0ea [root@VM_0_10_centos docker_install]# docker version Client: Docker Engine - Community Version: 19.03.5 API version: 1.40 Go version: go1.12.12 Git commit: 633a0ea Built: Wed Nov 13 07:25:41 2019 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 19.03.5 API version: 1.40 (minimum version 1.12) Go version: go1.12.12 Git commit: 633a0ea Built: Wed Nov 13 07:24:18 2019 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.2.10 GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339 runc: Version: 1.0.0-rc8+dev GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657 docker-init: Version: 0.18.0 GitCommit: fec3683 [root@VM_0_10_centos docker_install]# docker info Client: Debug Mode: false Server: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 19.03.5 Storage Driver: overlay2 Backing Filesystem: extfs Supports d_type: true Native Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: b34a5c8af56e510852c35414db4c1f4fa6172339 runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657 init version: fec3683 Security Options: seccomp Profile: default Kernel Version: 3.10.0-957.21.3.el7.x86_64 Operating System: CentOS Linux 7 (Core) OSType: linux Architecture: x86_64 CPUs: 1 Total Memory: 1.795GiB Name: VM_0_10_centos ID: ZYOK:IVEB:436X:2EJF:HMYJ:A6RA:XXNW:4WY7:4YL7:MIR7:GO33:XMLX Docker Root Dir: /var/lib/docker Debug Mode: false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false WARNING: bridge-nf-call-iptables is disabled WARNING: bridge-nf-call-ip6tables is disabled
阿里雲官網配置:json
# 默認etc下已經有docker目錄,這裏不用重複建立 sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://j98vrcq8.mirror.aliyuncs.com"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
編輯配置文件:vim /etc/docker/daemon.jsonvim
[root@VM_0_10_centos docker]# vi daemon.json { "registry-mirrors": ["https://j98vrcq8.mirror.aliyuncs.com"] }
[root@VM_0_10_centos docker]# systemctl daemon-reload
[root@VM_0_10_centos docker]# systemctl restart dockercentos
[root@VM_0_10_centos docker]# docker info Client: Debug Mode: false Server: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 19.03.5 Storage Driver: overlay2 Backing Filesystem: extfs Supports d_type: true Native Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: b34a5c8af56e510852c35414db4c1f4fa6172339 runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657 init version: fec3683 Security Options: seccomp Profile: default Kernel Version: 3.10.0-957.21.3.el7.x86_64 Operating System: CentOS Linux 7 (Core) OSType: linux Architecture: x86_64 CPUs: 1 Total Memory: 1.795GiB Name: VM_0_10_centos ID: ZYOK:IVEB:436X:2EJF:HMYJ:A6RA:XXNW:4WY7:4YL7:MIR7:GO33:XMLX Docker Root Dir: /var/lib/docker Debug Mode: false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Registry Mirrors: https://j98vrcq8.mirror.aliyuncs.com/ Live Restore Enabled: false WARNING: bridge-nf-call-iptables is disabled WARNING: bridge-nf-call-ip6tables is disabled
Docker Compose是一個用來定義和運行復雜應用的Docker工具。一個Docker容器的應用,一般由多個容器組成。Compose 經過一個配置文件來管理多個Docker容器,在配置文件中,全部的容器經過services來定義。而後使用docker-compose腳原本啓動,中止和重啓應用,和應用中的服務以及全部依賴服務的容器,很是適合組合使用多個容器進行開發的場景
安裝docker-compose的方式:
方式一:從github上下載docker-compose二進制文件安裝下載最新版的docker-compose文件
# curl -L參數是表示跳轉到新網址下載;-o輸出文件路徑;-i:顯示http response的頭信息;-I只顯示頭部信息 [root@VM_0_10_centos docker]# curl -L https://github.com/docker/compose/releases/download/1.25.1-rc1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 617 0 617 0 0 958 0 --:--:-- --:--:-- --:--:-- 958 100 16.2M 100 16.2M 0 0 105k 0 0:02:37 0:02:37 --:--:-- 127k # 添加可執行權限 [root@VM_0_10_centos docker]# chmod +x /usr/local/bin/docker-compose # 卸載(刪除該文件便可) [root@VM_0_10_centos docker]# rm /usr/local/bin/docker-compose
方式二:使用pip install命令安裝
# 使用pip安裝須要先安裝pip命令 [root@VM_0_10_centos docker]# yum -y install python-pip # 安裝 [root@VM_0_10_centos docker]# pip install docker-compose # 卸載 [root@VM_0_10_centos docker]# pip uninstall docker-compose
檢驗docker-compose安裝結果:
[root@VM_0_10_centos docker]# docker-compose version docker-compose version 1.25.1-rc1, build d92e9bee docker-py version: 4.1.0 CPython version: 3.7.4 OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019
Docker Machine是一個工具,可以讓您在虛擬主機上安裝Docker Engine,並使用docker-machine命令管理主機。
經過github下載安裝machine組件:
[root@VM_0_10_centos docker]# curl -L https://github.com/docker/machine/releases/download/v0.16.2/docker-machine-`uname -s`-`uname -m` > /usr/local/bin/docker-machine [root@VM_0_10_centos docker]# chmod +x /usr/local/bin/docker-machine
參考博客: