【docker部署】基於linux的centos操做系統部署安裝docker容器

1、docker介紹

  容器是輕量級的,包含應用運行所需全部東西(代碼、庫、運行時環境、系統設置,以及依賴關係)的獨立的包。每一個容器都部署於它本身的 CPU、內存、塊 I/O,以及網絡資源上,全部這些都不依賴於某個內核和操做系統。這也是容器與虛擬機之間最大的不一樣;相比之下,虛擬機是一個運行於宿主機操做系統上的完整的操做系統平臺,而容器不是。容器容許你以一種史無前例的方式擴展交付能力(無論內部仍是外部的)html

docker和VM虛擬機的區別在於:python

  • 容器提供了基於進程的隔離,而虛擬機提供了資源的徹底隔離。
  • 虛擬機可能須要一分鐘來啓動,而容器只須要一秒鐘或更短。
  • 容器使用宿主操做系統的內核,而虛擬機使用獨立的內核

docker發行版本分爲:linux

  • Docker CE(社區版):免費開源版本-Docker Engine
  • Docker EE(企業版):商用收費版本-Docker Data Center   

docker安裝環境:c++

  • 公有云環境:基於阿里雲以及騰訊雲主機等安裝Docker
  • 私有云環境:基於自主主機環境安裝Docker

Docker 平臺基本上由三部分組成:git

  • 客戶端:用戶使用 Docker 提供的工具(CLI 以及 API 等)來構建,上傳鏡像併發布命令來建立和啓動容器Docker
  • 主機:從 Docker registry 上下載鏡像並啓動容器Docker
  • registry:Docker 鏡像倉庫,用於保存鏡像,並提供鏡像上傳和下載。

 

2、Docker容器安裝部署

2.1 Docker容器部署

# 查看系統開發環境
[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

2.2 Docker安裝

2.2.1 部署Docker添加yum源:

# 安裝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

2.2.2 安裝docker最新版本:

# 安裝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

2.2.3 啓動docker服務

[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.

2.2.4 檢驗安裝docker服務信息

[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

2.3 Docker配置阿里雲鏡像加速器

阿里雲官網配置: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

2.4 Docker容器基本組件部署與安裝

2.4.1 Compose組件部署與安裝:

  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

2.4.2 Machine組件部署與安裝

  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

 

 

 

 

 

參考博客:

https://www.cnblogs.com/mazhilin/p/11553510.html

相關文章
相關標籤/搜索