摘要:下圖是與其他虛擬技術(shù)的對(duì)比圖。的目標(biāo)是,基于這個(gè)目標(biāo),將你需要發(fā)布的應(yīng)用組件及需要的環(huán)境配置都封裝成一個(gè)鏡像,然后基于鏡像創(chuàng)建容器并啟動(dòng)運(yùn)行。這樣就可以達(dá)到組建級(jí)別的一次封裝,多次運(yùn)行。而默認(rèn)情況下,屬于用戶,需要權(quán)限才能訪問。
docker玩過很多次,但每次都是從零開始,所以這次而打算記錄下來,方便后面查詢。
docker的技術(shù)基礎(chǔ)是LXC虛擬化技術(shù),虛擬化技術(shù)有很多,有硬件層面和軟件層面的,我在
2018年第13周-虛擬化技術(shù)理解大概有描述。其中LXC就是軟件層面的虛擬化技術(shù)。其內(nèi)存利用率很高,這是因?yàn)樗刑摂M機(jī)(在docker里叫Container)都共享宿主的操作系統(tǒng)實(shí)例,,不存在由于運(yùn)行多個(gè)操作系統(tǒng)實(shí)例所造成的性能損耗。下圖是docker與其他虛擬技術(shù)的對(duì)比圖。
Docker的目標(biāo)是“Build, Ship and Run Any App, Anywhere”,基于這個(gè)目標(biāo),將你需要發(fā)布的應(yīng)用組件及需要的環(huán)境配置都封裝成一個(gè)image(鏡像),然后基于鏡像創(chuàng)建Container(容器)并啟動(dòng)運(yùn)行。這樣就可以達(dá)到組建級(jí)別的一次封裝,多次運(yùn)行。是不是跟JVM很像,一次編譯,多處運(yùn)行。
歷史本版的Docker可能被叫為docker或docker-engine. 如果它們有安裝 ,卸載它以及它們的依賴. 命令如下:
$ sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine
/var/lib/docker/目錄里的內(nèi)容將被保留, 以及images, containers, volumes, 和networks將會(huì)被保留.
Docker CE包現(xiàn)在叫 docker-ce
你可以從很多地方安裝Docker CE, 這取決于你的需求:
很多用戶設(shè)置Docker的yum倉(cāng)庫(kù), 然后安裝docker, 這樣容易安裝和升級(jí). 推薦此方法.
有些用戶下載ROM包, 并手工安裝和手工管理升級(jí). 這種方法對(duì)于那些無法連上網(wǎng)的服務(wù)器是很有用的.
在測(cè)試和開發(fā)環(huán)境, 有些用戶選擇自動(dòng)方便的腳本來安裝docker.
從倉(cāng)庫(kù)安裝在安裝Docker CE之前, 你需要設(shè)置Docker的yum倉(cāng)庫(kù). 然后在安裝.
設(shè)置倉(cāng)庫(kù)安裝需要的包. yum-utils提供yum-config-manager工具, devicemapper存儲(chǔ)驅(qū)動(dòng)則需要device-mapper-persistent-data和lvm2
$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
我centos7系統(tǒng)安裝時(shí)選擇的SOFTWARE SELECTION是Infrastuctue Server (Server for operating network infrastuctue Server)
[root@amd usb]# sudo yum install -y yum-utils > device-mapper-persistent-data > lvm2 Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirror.lzu.edu.cn * extras: mirrors.zju.edu.cn * updates: mirrors.zju.edu.cn Package yum-utils-1.1.31-46.el7_5.noarch already installed and latest version Package device-mapper-persistent-data-0.7.3-3.el7.x86_64 already installed and latest version Package 7:lvm2-2.02.177-4.el7.x86_64 already installed and latest version Nothing to do
使用以下命令設(shè)置stable倉(cāng)庫(kù), 就算你想安裝edge或test倉(cāng)庫(kù), 也還是得安裝stable倉(cāng)庫(kù).
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
[root@amd usb]# sudo yum-config-manager > --add-repo > https://download.docker.com/linux/centos/docker-ce.repo Loaded plugins: fastestmirror, langpacks adding repo from: https://download.docker.com/linux/centos/docker-ce.repo grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo repo saved to /etc/yum.repos.d/docker-ce.repo
可選: 啟動(dòng)edge和test倉(cāng)庫(kù), 這些倉(cāng)庫(kù)都是包含在docker.repo文件, 只是默認(rèn)是關(guān)閉的.
$ sudo yum-config-manager --enable docker-ce-edge $ sudo yum-config-manager --enable docker-ce-test
通過yum-config-manager命令關(guān)閉edge和test倉(cāng)庫(kù).
sudo yum-config-manager --disable docker-ce-edge安裝Docker CE
安裝最新版本的Docker CE, 或者參考下一步可指定版本:
sudo yum install docker-ce
如果需要確認(rèn)GPG key, 確認(rèn)fingerprint是否匹配060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35, 匹配上了則確認(rèn)
多個(gè)docker庫(kù)的情況下
如果你有多個(gè)docker庫(kù)啟用了, 而且安裝或升級(jí)時(shí)不指定版本, 那么yum install或yum update命令則總會(huì)安裝盡可能高的版本, 這也許不符合你穩(wěn)定的要求.
到此位置, docker已經(jīng)安裝, 但還未啟動(dòng). Linux的docker group也創(chuàng)建了, 但沒有users在這組里.
安裝過程:
[root@amd ~]# sudo yum install docker-ce Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirror.lzu.edu.cn * extras: mirrors.zju.edu.cn * updates: mirrors.zju.edu.cn base | 3.6 kB 00:00:00 docker-ce-stable | 2.9 kB 00:00:00 epel | 3.2 kB 00:00:00 extras | 3.4 kB 00:00:00 updates | 3.4 kB 00:00:00 (1/2): epel/x86_64/updateinfo | 935 kB 00:00:05 (2/2): epel/x86_64/primary | 3.6 MB 00:00:14 epel 12742/12742 Resolving Dependencies --> Running transaction check ---> Package docker-ce.x86_64 0:18.06.1.ce-3.el7 will be installed --> Processing Dependency: container-selinux >= 2.9 for package: docker-ce-18.06.1.ce-3.el7.x86_64 --> Processing Dependency: libcgroup for package: docker-ce-18.06.1.ce-3.el7.x86_64 --> Processing Dependency: libltdl.so.7()(64bit) for package: docker-ce-18.06.1.ce-3.el7.x86_64 --> Running transaction check ---> Package container-selinux.noarch 2:2.68-1.el7 will be installed --> Processing Dependency: policycoreutils-python for package: 2:container-selinux-2.68-1.el7.noarch ---> Package libcgroup.x86_64 0:0.41-15.el7 will be installed ---> Package libtool-ltdl.x86_64 0:2.4.2-22.el7_3 will be installed --> Running transaction check ---> Package policycoreutils-python.x86_64 0:2.5-22.el7 will be installed --> Processing Dependency: setools-libs >= 3.3.8-2 for package: policycoreutils-python-2.5-22.el7.x86_64 --> Processing Dependency: libsemanage-python >= 2.5-9 for package: policycoreutils-python-2.5-22.el7.x86_64 --> Processing Dependency: audit-libs-python >= 2.1.3-4 for package: policycoreutils-python-2.5-22.el7.x86_64 --> Processing Dependency: python-IPy for package: policycoreutils-python-2.5-22.el7.x86_64 --> Processing Dependency: libqpol.so.1(VERS_1.4)(64bit) for package: policycoreutils-python-2.5-22.el7.x86_64 --> Processing Dependency: libqpol.so.1(VERS_1.2)(64bit) for package: policycoreutils-python-2.5-22.el7.x86_64 --> Processing Dependency: libapol.so.4(VERS_4.0)(64bit) for package: policycoreutils-python-2.5-22.el7.x86_64 --> Processing Dependency: checkpolicy for package: policycoreutils-python-2.5-22.el7.x86_64 --> Processing Dependency: libqpol.so.1()(64bit) for package: policycoreutils-python-2.5-22.el7.x86_64 --> Processing Dependency: libapol.so.4()(64bit) for package: policycoreutils-python-2.5-22.el7.x86_64 --> Running transaction check ---> Package audit-libs-python.x86_64 0:2.8.1-3.el7_5.1 will be installed ---> Package checkpolicy.x86_64 0:2.5-6.el7 will be installed ---> Package libsemanage-python.x86_64 0:2.5-11.el7 will be installed ---> Package python-IPy.noarch 0:0.75-6.el7 will be installed ---> Package setools-libs.x86_64 0:3.3.8-2.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ===================================================================================================================================================================================================================== Package Arch Version Repository Size ===================================================================================================================================================================================================================== Installing: docker-ce x86_64 18.06.1.ce-3.el7 docker-ce-stable 41 M Installing for dependencies: audit-libs-python x86_64 2.8.1-3.el7_5.1 updates 75 k checkpolicy x86_64 2.5-6.el7 base 294 k container-selinux noarch 2:2.68-1.el7 extras 36 k libcgroup x86_64 0.41-15.el7 base 65 k libsemanage-python x86_64 2.5-11.el7 base 112 k libtool-ltdl x86_64 2.4.2-22.el7_3 base 49 k policycoreutils-python x86_64 2.5-22.el7 base 454 k python-IPy noarch 0.75-6.el7 base 32 k setools-libs x86_64 3.3.8-2.el7 base 619 k Transaction Summary ===================================================================================================================================================================================================================== Install 1 Package (+9 Dependent packages) Total size: 42 M Installed size: 46 M Is this ok [y/d/N]: y Downloading packages: warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-18.06.1.ce-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY Retrieving key from https://download.docker.com/linux/centos/gpg Importing GPG key 0x621E9F35: Userid : "Docker Release (CE rpm)" Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35 From : https://download.docker.com/linux/centos/gpg Is this ok [y/N]: y Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : libcgroup-0.41-15.el7.x86_64 1/10 Installing : audit-libs-python-2.8.1-3.el7_5.1.x86_64 2/10 Installing : setools-libs-3.3.8-2.el7.x86_64 3/10 Installing : libtool-ltdl-2.4.2-22.el7_3.x86_64 4/10 Installing : python-IPy-0.75-6.el7.noarch 5/10 Installing : checkpolicy-2.5-6.el7.x86_64 6/10 Installing : libsemanage-python-2.5-11.el7.x86_64 7/10 Installing : policycoreutils-python-2.5-22.el7.x86_64 8/10 Installing : 2:container-selinux-2.68-1.el7.noarch 9/10 setsebool: SELinux is disabled. Installing : docker-ce-18.06.1.ce-3.el7.x86_64 10/10 Verifying : libcgroup-0.41-15.el7.x86_64 1/10 Verifying : docker-ce-18.06.1.ce-3.el7.x86_64 2/10 Verifying : policycoreutils-python-2.5-22.el7.x86_64 3/10 Verifying : libsemanage-python-2.5-11.el7.x86_64 4/10 Verifying : 2:container-selinux-2.68-1.el7.noarch 5/10 Verifying : checkpolicy-2.5-6.el7.x86_64 6/10 Verifying : python-IPy-0.75-6.el7.noarch 7/10 Verifying : libtool-ltdl-2.4.2-22.el7_3.x86_64 8/10 Verifying : setools-libs-3.3.8-2.el7.x86_64 9/10 Verifying : audit-libs-python-2.8.1-3.el7_5.1.x86_64 10/10 Installed: docker-ce.x86_64 0:18.06.1.ce-3.el7 Dependency Installed: audit-libs-python.x86_64 0:2.8.1-3.el7_5.1 checkpolicy.x86_64 0:2.5-6.el7 container-selinux.noarch 2:2.68-1.el7 libcgroup.x86_64 0:0.41-15.el7 libsemanage-python.x86_64 0:2.5-11.el7 libtool-ltdl.x86_64 0:2.4.2-22.el7_3 policycoreutils-python.x86_64 0:2.5-22.el7 python-IPy.noarch 0:0.75-6.el7 setools-libs.x86_64 0:3.3.8-2.el7 Complete!
指定版本安裝Docker CE, 首先先列出倉(cāng)庫(kù)有哪些docker-ce版本, 然后在選擇安裝
a. 列出并排序有哪些版本在倉(cāng)庫(kù)里, 以下是例子, 從高級(jí)到低級(jí).
[root@amd ~]# yum list docker-ce --showduplicates | sort -r * updates: mirrors.zju.edu.cn Loading mirror speeds from cached hostfile Loaded plugins: fastestmirror, langpacks Installed Packages * extras: mirrors.zju.edu.cn docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.06.1.ce-3.el7 @docker-ce-stable docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stable docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable * base: mirror.lzu.edu.cn Available Packages
這列表內(nèi)容取決于哪個(gè)倉(cāng)庫(kù)被啟動(dòng), 并且指定了你CentOS版本(在這例子里是.el7)
b. 安裝指定版本, 需指定全限定包名, 也就是包名(docker-ce)加版本字符串(第2列), 以橫杠(-)隔開, 例如: docker-ce-18.03.0.ce
sudo yum install docker-ce-
Dokcer
到此位置, docker已經(jīng)安裝, 但還未啟動(dòng). Linux的docker group也創(chuàng)建了, 但沒有users在這組里.
啟動(dòng)Docker
$ sudo systemctl start docker
驗(yàn)證Docker是否安裝正確, 我們運(yùn)行個(gè)hello-world鏡像
sudo docker run hello-world
此命令會(huì)下載一個(gè)test鏡像, 然后運(yùn)行在一個(gè)容器里, 當(dāng)容器運(yùn)行時(shí), 它會(huì)輸出信息, 然后退出.
Docker CE已經(jīng)安裝并且運(yùn)行著, 你需要用sudo在運(yùn)行Docker. 可以繼續(xù)教程Linux postinstall 來運(yùn)行沒有權(quán)限的用戶運(yùn)行Docker命令.
升級(jí)Docker-CE就在yum中直接選擇新版本安裝即可
docker操作 查詢鏡像docker search centos下載鏡像
docker pull centos本地鏡像列表
docker images啟動(dòng)centos并進(jìn)入bash
docker run -ti centos /bin/bash查看所有容器情況
docker ps -a使用宿主的所有網(wǎng)絡(luò)信息的啟動(dòng)docker
docker run -tid --name can_download --net host centos /bin/bash創(chuàng)建bridge的網(wǎng)關(guān)
docker run -tid --name my-net-centos --network my-net centos /bin/bash指定bridge的網(wǎng)關(guān) 連接后臺(tái)運(yùn)行的container
docker exec -it my-net-centos /bin/bash宿主與container傳輸文件
docker cp jdk-8u172-linux-x64.tar.gz f858312b67c20f1ff5303ae8f8333133c8791d434ee30c0e3395ccfb6b345d4f:/root/jdk-8u172-linux-x64.tar.gzTroubleShoot 管理權(quán)限
nescafe@nescafe-PC:~$ docker images Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.38/images/json: dial unix /var/run/docker.sock: connect: permission denied原因
摘自docker mannual上的一段話
Manage Docker as a non-root user解決方法1
The docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can only access it using sudo. The docker daemon always runs as the root user.
If you don’t want to use sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group.
大概的意思就是:docker進(jìn)程使用Unix Socket而不是TCP端口。而默認(rèn)情況下,Unix socket屬于root用戶,需要root權(quán)限才能訪問。
使用sudo獲取管理員權(quán)限,運(yùn)行docker命令
解決方法2docker守護(hù)進(jìn)程啟動(dòng)的時(shí)候,會(huì)默認(rèn)賦予名字為docker的用戶組讀寫Unix socket的權(quán)限,因此只要?jiǎng)?chuàng)建docker用戶組,并將當(dāng)前用戶加入到docker用戶組中,那么當(dāng)前用戶就有權(quán)限訪問Unix socket了,進(jìn)而也就可以執(zhí)行docker相關(guān)命令
sudo groupadd docker #添加docker用戶組 sudo gpasswd -a $USER docker #將登陸用戶加入到docker用戶組中 newgrp docker #更新用戶組 docker ps #測(cè)試docker命令是否可以使用sudo正常使用
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/27582.html
摘要:在開發(fā)或測(cè)試環(huán)境可能有大量服務(wù)器數(shù)據(jù)庫(kù)應(yīng)用服務(wù)器中間件服務(wù)器等特別大數(shù)據(jù)系統(tǒng)涉及的服務(wù)器很多的時(shí)候很難記就算修改本機(jī)但每次新增刪除一個(gè)對(duì)于的域名都是很麻煩的于是搭建一個(gè)就非常必須了這里使用無侵入式的搭建服務(wù)不要時(shí)刪除即可新建三個(gè)文件在宿主新 在開發(fā)或測(cè)試環(huán)境, 可能有大量服務(wù)器, 數(shù)據(jù)庫(kù), 應(yīng)用服務(wù)器, 中間件服務(wù)器等. 特別大數(shù)據(jù)系統(tǒng), 涉及的服務(wù)器很多的時(shí)候, ip很難記, 就算修...
摘要:流程源處理源代碼,例如過濾任何值。工藝類從編譯后處理生成的文件,例如對(duì)類進(jìn)行字節(jié)碼增強(qiáng)。整合后的測(cè)試執(zhí)行集成測(cè)試后執(zhí)行所需的操作。校驗(yàn)運(yùn)行任何檢查以驗(yàn)證包裝是否有效并符合質(zhì)量標(biāo)準(zhǔn)。 nodejs和es6 nodejs的語法和es6不一樣,如模塊系統(tǒng),一個(gè)是CommonJS的require、一個(gè)是es6的import,寫模塊也不一樣。 nodejs的npm 我來理解,nodejs類似與j...
閱讀 2215·2021-11-25 09:43
閱讀 1181·2021-11-23 09:51
閱讀 3514·2021-11-23 09:51
閱讀 3643·2021-11-22 09:34
閱讀 1576·2021-10-09 09:43
閱讀 2138·2019-08-30 15:53
閱讀 3174·2019-08-30 14:07
閱讀 582·2019-08-28 18:14