日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Docker从入门到放弃------docker的安装与初始化配置

發(fā)布時間:2024/1/8 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Docker从入门到放弃------docker的安装与初始化配置 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

本來是已經(jīng)準(zhǔn)備開始K8S的內(nèi)容,但是K8S與Docker關(guān)聯(lián)比較大,于是決定先寫一些關(guān)于Docker的文章
本文所有內(nèi)容基于CentOS8系統(tǒng)

文章目錄

  • 概述
  • 下載二進(jìn)制文件
  • 下載二進(jìn)制安裝腳本
  • 修改腳本權(quán)限
  • 執(zhí)行安裝腳本
  • 修改Docker安裝目錄
    • 新建Docker目錄
    • 修改Docker配置文件
    • 重啟Docker
    • 查看DockerInfo
    • 驗(yàn)證

概述

Docker社區(qū)版本中提供了MacOS、Windows和Linux等系統(tǒng)的安裝包,同時也支持在云服務(wù)器上的安裝,如AWSCloud。網(wǎng)上在各種系統(tǒng)下安裝Docker的教程也比較多,本文中僅介紹在Linux下Docker二進(jìn)制文件的安裝方式。

下載二進(jìn)制文件

下載地址:Docker二進(jìn)制文件官方下載地址

選擇我們需要的版本下載,這里我選擇的是docker-18.06.2-ce.tgz

進(jìn)入你存放下載文件的文件件,執(zhí)行以下命令

wget https://download.docker.com/linux/static/stable/x86_64/docker-18.06.2-ce.tgz

等待下載完成

--2020-12-03 21:26:22-- https://download.docker.com/linux/static/stable/x86_64/docker-18.06.2-ce.tgz 正在解析主機(jī) download.docker.com (download.docker.com)... 13.225.2.81, 13.225.2.92, 13.225.2.103, ... 正在連接 download.docker.com (download.docker.com)|13.225.2.81|:443... 已連接。 已發(fā)出 HTTP 請求,正在等待回應(yīng)... 200 OK 長度:43834194 (42M) [application/x-tar] 正在保存至: “docker-18.06.2-ce.tgz”docker-18.06.2-ce.tgz 100%[============================================================================>] 41.80M 9.29MB/s 用時 6.8s 2020-12-03 21:26:29 (6.17 MB/s) - 已保存 “docker-18.06.2-ce.tgz” [43834194/43834194])

下載二進(jìn)制安裝腳本

地址:Docker二進(jìn)制安裝腳本地址

在剛才的文件夾下創(chuàng)建一個名為install-docker.sh的文件

vim install-docker.sh

將install-docker.sh中的內(nèi)容復(fù)制到我們創(chuàng)建的文件中

#!/bin/shusage(){echo "Usage: $0 FILE_NAME_DOCKER_CE_TAR_GZ"echo " $0 docker-17.09.0-ce.tgz"echo "Get docker-ce binary from: https://download.docker.com/linux/static/stable/x86_64/"echo "eg: wget https://download.docker.com/linux/static/stable/x86_64/docker-17.09.0-ce.tgz"echo "" } SYSTEMDDIR=/usr/lib/systemd/system SERVICEFILE=docker.service DOCKERDIR=/usr/bin DOCKERBIN=docker SERVICENAME=dockerif [ $# -ne 1 ]; thenusageexit 1 elseFILETARGZ="$1" fiif [ ! -f ${FILETARGZ} ]; thenecho "Docker binary tgz files does not exist, please check it"echo "Get docker-ce binary from: https://download.docker.com/linux/static/stable/x86_64/"echo "eg: wget https://download.docker.com/linux/static/stable/x86_64/docker-17.09.0-ce.tgz"exit 1 fiecho "##unzip : tar xvpf ${FILETARGZ}" tar xvpf ${FILETARGZ} echoecho "##binary : ${DOCKERBIN} copy to ${DOCKERDIR}" cp -p ${DOCKERBIN}/* ${DOCKERDIR} >/dev/null 2>&1 which ${DOCKERBIN}echo "##systemd service: ${SERVICEFILE}" echo "##docker.service: create docker systemd file" cat >${SYSTEMDDIR}/${SERVICEFILE} <<EOF [Unit] Description=Docker Application Container Engine Documentation=http://docs.docker.com After=network.target docker.socket [Service] Type=notify EnvironmentFile=-/run/flannel/docker WorkingDirectory=/usr/local/bin ExecStart=/usr/bin/dockerd \-H tcp://0.0.0.0:4243 \-H unix:///var/run/docker.sock \--selinux-enabled=false \--log-opt max-size=1g ExecReload=/bin/kill -s HUP $MAINPID # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity # Uncomment TasksMax if your systemd version supports it. # Only systemd 226 and above support this version. #TasksMax=infinity TimeoutStartSec=0 # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes # kill only the docker process, not all processes in the cgroup KillMode=process Restart=on-failure [Install] WantedBy=multi-user.target EOFecho ""systemctl daemon-reload echo "##Service status: ${SERVICENAME}" systemctl status ${SERVICENAME} echo "##Service restart: ${SERVICENAME}" systemctl restart ${SERVICENAME} echo "##Service status: ${SERVICENAME}" systemctl status ${SERVICENAME}echo "##Service enabled: ${SERVICENAME}" systemctl enable ${SERVICENAME}echo "## docker version" docker version

修改腳本權(quán)限

執(zhí)行命令

chmod -x ./install-docker.sh

執(zhí)行安裝腳本

執(zhí)行命令

bash ./install-docker.sh docker-18.06.2-ce.tgz

腳本會自動安裝我們下載的Docker安裝包并且重啟Docker

##unzip : tar xvpf docker-18.06.2-ce.tgz docker/ docker/docker-containerd docker/docker-proxy docker/docker docker/docker-runc docker/dockerd docker/docker-containerd-ctr docker/docker-containerd-shim docker/docker-init##binary : docker copy to /usr/bin /usr/bin/docker ##systemd service: docker.service ##docker.service: create docker systemd file##Service status: docker ● docker.service - Docker Application Container EngineLoaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)Active: inactive (dead)Docs: http://docs.docker.com ##Service restart: docker ##Service status: docker ● docker.service - Docker Application Container EngineLoaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)Active: active (running) since Thu 2020-12-03 21:42:22 CST; 31ms agoDocs: http://docs.docker.comMain PID: 3164626 (dockerd)Tasks: 18 (limit: 11540)Memory: 22.8MCGroup: /system.slice/docker.service├─3164626 /usr/bin/dockerd -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock --selinux-enabled=false --log-opt max-size=1g└─3164645 docker-containerd --config /var/run/docker/containerd/containerd.toml12月 03 21:42:16 VM-0-4-centos dockerd[3164626]: time="2020-12-03T21:42:16.588103107+08:00" level=info msg="pickfirstBalancer: HandleSubConnStateChange: 0x> 12月 03 21:42:16 VM-0-4-centos dockerd[3164626]: time="2020-12-03T21:42:16.588258691+08:00" level=info msg="pickfirstBalancer: HandleSubConnStateChange: 0x> 12月 03 21:42:16 VM-0-4-centos dockerd[3164626]: time="2020-12-03T21:42:16.588274371+08:00" level=info msg="Loading containers: start." 12月 03 21:42:21 VM-0-4-centos dockerd[3164626]: time="2020-12-03T21:42:21.490469755+08:00" level=info msg="Default bridge (docker0) is assigned with an IP> 12月 03 21:42:22 VM-0-4-centos dockerd[3164626]: time="2020-12-03T21:42:22.055802015+08:00" level=info msg="Loading containers: done." 12月 03 21:42:22 VM-0-4-centos dockerd[3164626]: time="2020-12-03T21:42:22.134787833+08:00" level=info msg="Docker daemon" commit=6d37f41 graphdriver(s)=ov> 12月 03 21:42:22 VM-0-4-centos dockerd[3164626]: time="2020-12-03T21:42:22.134924559+08:00" level=info msg="Daemon has completed initialization" 12月 03 21:42:22 VM-0-4-centos dockerd[3164626]: time="2020-12-03T21:42:22.236492421+08:00" level=info msg="API listen on /var/run/docker.sock" 12月 03 21:42:22 VM-0-4-centos dockerd[3164626]: time="2020-12-03T21:42:22.236569607+08:00" level=info msg="API listen on [::]:4243" 12月 03 21:42:22 VM-0-4-centos systemd[1]: Started Docker Application Container Engine.

查看Docker信息

[root@VM-0-4-centos download]# docker info Containers: 0Running: 0Paused: 0Stopped: 0 Images: 0 Server Version: 18.06.2-ce Storage Driver: overlay2Backing Filesystem: extfsSupports d_type: trueNative Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins:Volume: localNetwork: bridge host macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: 468a545b9edcd5932818eb9de8e72413e616e86e runc version: 69663f0bd4b60df09991c08812a60108003fa340 init version: fec3683 Security Options:seccompProfile: default Kernel Version: 4.18.0-80.el8.x86_64 Operating System: CentOS Linux 8 (Core) OSType: linux Architecture: x86_64 CPUs: 1 Total Memory: 1.787GiB Name: VM-0-4-centos ID: BUHQ:DMTC:UM3Z:FJTX:FYWQ:U55P:MM2H:WT7X:YQFA:LUNL:MBDC:7DXS Docker Root Dir: /var/lib/docker Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries:127.0.0.0/8 Live Restore Enabled: false

修改Docker安裝目錄

從上文中Docker信息中我們可以看到,Docker的安裝目錄是

Docker Root Dir: /var/lib/docker

一般情況下,這個目錄的的空間較小,所以不建議將其安裝在var中。我們現(xiàn)在來修改一下Docker的安裝目錄

新建Docker目錄

mkdir -p /opt/docker/root

修改Docker配置文件

查詢Docker配置文件位置

[root@VM-0-4-centos download]# systemctl enable docker Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.

修改docker.service文件,在ExecStart屬性的最后面添加參數(shù)

--graph /opt/docker/root

重啟Docker

重新enable 一下docker 服務(wù) 重新進(jìn)行軟連接 以及進(jìn)行一次 daemon-reload

systemctl disable docker systemctl enable docker systemctl daemon-reload systemctl start docker

查看DockerInfo

[root@VM-0-4-centos ~]# systemctl restart docker 您在 /var/spool/mail/root 中有郵件 [root@VM-0-4-centos ~]# docker info Containers: 0Running: 0Paused: 0Stopped: 0 Images: 0 Server Version: 18.06.2-ce Storage Driver: overlay2Backing Filesystem: extfsSupports d_type: trueNative Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins:Volume: localNetwork: bridge host macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: 468a545b9edcd5932818eb9de8e72413e616e86e runc version: 69663f0bd4b60df09991c08812a60108003fa340 init version: fec3683 Security Options:seccompProfile: default Kernel Version: 4.18.0-80.el8.x86_64 Operating System: CentOS Linux 8 (Core) OSType: linux Architecture: x86_64 CPUs: 1 Total Memory: 1.787GiB Name: VM-0-4-centos ID: BUHQ:DMTC:UM3Z:FJTX:FYWQ:U55P:MM2H:WT7X:YQFA:LUNL:MBDC:7DXS Docker Root Dir: /opt/docker/root Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries:127.0.0.0/8 Live Restore Enabled: false

注:若啟動后Docker Root Dir未發(fā)生變化,請執(zhí)行以下命令再重新查看info

systemctl restart docker

驗(yàn)證

docker安裝MySQL:詳細(xì)教程鏈接,建議大家看一看詳細(xì)教程,里面也有安裝docker國內(nèi)源的內(nèi)容,可以大大加快你下載鏡像的速度

執(zhí)行拉取MySQL5.7的命令

[root@VM-0-4-centos ~]# docker pull mysql:5.7.29 5.7.29: Pulling from library/mysql 54fec2fa59d0: Pull complete bcc6c6145912: Pull complete 951c3d959c9d: Pull complete 05de4d0e206e: Pull complete 319f0394ef42: Pull complete d9185034607b: Pull complete 013a9c64dadc: Pull complete 58b7b840ebff: Pull complete 9b85c0abc43d: Pull complete bdf022f63e85: Pull complete 35f7f707ce83: Pull complete Digest: sha256:95b4bc7c1b111906fdb7a39cd990dd99f21c594722735d059769b80312eb57a7 Status: Downloaded newer image for mysql:5.7.29

執(zhí)行命令

du /var/lib/docker/

與命令

du /opt/docker/root/

可以看到,所有的鏡像都存在于文件夾/opt/docker/root/下
我是Baldwin,一個25歲的程序員,致力于讓學(xué)習(xí)變得更有趣!
現(xiàn)在關(guān)注作者即可領(lǐng)取海量學(xué)習(xí)資料與簡歷模板

往期好文:

用Python每天給女神發(fā)一句手機(jī)短信情話

MySQL優(yōu)化之explain

Spring源碼分析-MVC初始化

春風(fēng)得意馬蹄疾,一文看盡(JVM)虛擬機(jī)

造輪子的藝術(shù)

源碼閱讀技巧

Java注解詳解

教你自建SpringBoot服務(wù)器

更多文章請點(diǎn)擊

總結(jié)

以上是生活随笔為你收集整理的Docker从入门到放弃------docker的安装与初始化配置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。