最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關咨詢
選擇下列產品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網營銷解決方案
Docker系列2:Docker安裝配置與基本使用

一、基礎環(huán)境介紹

成都創(chuàng)新互聯(lián)公司是一家專業(yè)提供合山企業(yè)網站建設,專注與成都網站建設、做網站、H5響應式網站、小程序制作等業(yè)務。10年已為合山眾多企業(yè)、政府機構等服務。創(chuàng)新互聯(lián)專業(yè)網絡公司優(yōu)惠進行中。

1、基礎軟硬件環(huán)境介紹

  • 需要64位的CPU

  • linux內核版本3.10及以上

  • 內核支持cggroups 和 namespace

  • 系統(tǒng)版本為CentOS7.4【centos6也可安裝,但是不穩(wěn)定】

  • Docker版本為18.06

  • K8S版本為1.16 【k8s版本必須和docker版本兼容】

2、查看k8s與docker版本的對應關系

第一步:登錄github

https://github.com/kubernetes/kubernetes/releases

第二步:查看指定版本k8s的CHANGELOG文件

Docker系列2:Docker安裝配置與基本使用

第三步:搜索docker version,查看支持的docker版本

Docker系列2:Docker安裝配置與基本使用

3、配置yum源

1)用阿里云的鏡像即可,路徑為 https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/x86_64/stable/Packages/,如下

Docker系列2:Docker安裝配置與基本使用

2)配置yum源

[root@host1?~]#?cat?/etc/yum.repos.d/docker.repo?
[docker]
name=aliyun?docker?repo
enabled=1
gpgcheck=0
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/x86_64/stable/

查看是否配置成功

[root@host1?~]#?yum?repolist
Loaded?plugins:?fastestmirror
Loading?mirror?speeds?from?cached?hostfile
?*?base:?mirror.bit.edu.cn
?*?extras:?mirrors.huaweicloud.com
?*?updates:?mirrors.huaweicloud.com
repo?id???????????????????????????????????????repo?name????????????????????????????????????????status
docker????????????????????????????????????????aliyun?docker?repo???????????????????????????????????58
base/7/x86_64?????????????????????????????????CentOS-7?-?Base??????????????????????????????????10,097
extras/7/x86_64???????????????????????????????CentOS-7?-?Extras???????????????????????????????????307
updates/7/x86_64??????????????????????????????CentOS-7?-?Updates??????????????????????????????????997

二、安裝配置docker

1、安裝docker 18.06.0

[root@host1?~]#?yum?install?docker-ce-18.06.0.ce

2、創(chuàng)建json文件加速docker鏡像下載速度

[root@host1?~]#?mkdir?/etc/docker
[root@host1?~]#?cat?/etc/docker/daemon.json
{
????"registry-mirrors":?["https://registry.docker-cn.com"]
}

3、啟動服務

[root@host1?~]#?systemctl?start?docker
[root@host1?~]#?systemctl?status?docker

看下docker版本

[root@host1?~]#?docker?--version
Docker?version?18.06.0-ce,?build?0ffa825

查看docker信息

[root@host1?~]#?docker?info

三、關于鏡像的操作

1、關于防火墻問題

docker是需要啟動iptables這個服務的,但是在centos7中,默認是用firewalld來管理,而不是iptables,所以可能會導致docer使用有問題,因為需要iptables做端口映射。可以用如下的方式來解決

[root@host1?~]#?systemctl?disable?firewalld??????????^C
[root@host1?~]#?yum?install?iptables-services?-y???????^C
[root@host1?~]#?systemctl?enable?iptables?????????????^C

2、查看本地的鏡像

[root@host1?~]#?docker?images
REPOSITORY??????????TAG?????????????????IMAGE?ID????????????CREATED?????????????SIZE

3、搜索鏡像,如搜索nginx鏡像

[root@host1?~]#?docker?search?nginx

從上面的search的結果可以看到,有些搜索出來的結果就是一個內容,而有些結果是用斜杠分割的

  • 沒有斜杠分隔的,我們稱之為頂級倉庫,一般就是官方的

  • 有分隔的稱之為:用戶倉庫或者像倉庫,一般就是用戶自己注冊賬號,然后做個倉庫,并放一些鏡像給別人用。

4、拉去幾個鏡像

1)拉取nginx鏡像,為節(jié)省帶寬,此處選alpine版本

[root@host1?~]#?docker?image?pull?nginx:1.14-alpine
1.14-alpine:?Pulling?from?library/nginx
bdf0201b3a05:?Pull?complete?
3d0a573c81ed:?Pull?complete?
8129faeb2eb6:?Pull?complete?
3dc99f571daf:?Pull?complete?
Digest:?sha256:485b610fefec7ff6c463ced9623314a04ed67e3945b9c08d7e53a47f6d108dc7
Status:?Downloaded?newer?image?for?nginx:1.14-alpine

2)拉取busybox鏡像

[root@host1?~]#?docker?image?pull?busybox
Using?default?tag:?latest
latest:?Pulling?from?library/busybox
322973677ef5:?Pull?complete?
Digest:?sha256:1828edd60c5efd34b2bf5dd3282ec0cc04d47b2ff9caa0b6d4f07a21d1c08084
Status:?Downloaded?newer?image?for?busybox:latest

3)查看本地已經下載的鏡像

[root@host1?~]#?docker?image?ls
REPOSITORY??????????TAG?????????????????IMAGE?ID????????????CREATED?????????????SIZE
busybox?????????????latest??????????????b534869c81f0????????2?weeks?ago?????????1.22MB
nginx???????????????1.14-alpine?????????8a2fb25a19f5????????8?months?ago????????16MB

  • REPOSITORY:倉庫名稱

  • TAG:標簽

  • IMAGE ID:唯一ID值

  • CREATED:什么時間創(chuàng)建的

  • SIZE:大小

4)查看鏡像的詳細信息

[root@host1?~]#?docker?image?ls?--no-trunc
REPOSITORY??????????TAG?????????????????IMAGE?ID??????????????????????????????????????????????????????????????????CREATED?????????????SIZE
busybox?????????????latest??????????????sha256:b534869c81f05ce6fbbdd3a3293e64fd032e059ab4b28a0e0d5b485cf904be4b???2?weeks?ago?????????1.22MB
nginx???????????????1.14-alpine?????????sha256:8a2fb25a19f5dc1528b7a3fabe8b3145ff57fe10e4f1edac6c718a3cf4aa4b73???8?months?ago????????16MB

四、關于容器的操作

1、容器操作包括如下

  • 啟動容器:start

  • 停止容器:stop

  • 強制停止:kill

  • 創(chuàng)建后直接啟動容器:run

  • 暫停容器:pause

  • 取消暫停(繼續(xù)運行)容器:unpause

  • 也可以列出來全部的容器:docker ps或docker container ls

2、啟動容器操作

啟動容器用run命令,包括如下參數(shù)

  • -t:這里是指定一個終端,如果沒有終端,是無法登陸這個容器的

  • -i, --interactive:如果想用交互式訪問,就需要用這個選項

  • --name string:這里是指定容器的名字

  • --rm:當容器停止的時候,自動刪除容器對象

  • -d, --detach :讓當前的這個容器工作在后臺

  • --network string :指定容器加入到哪個網絡,如果不加的話,默認是一個bridge網絡

3、基于busybox啟動容器

[root@host1?~]#?docker?run?--name?bbox?-it?busybox
/?#
  • 此時就啟動了容器,同時進入了容器的shell中

此時,在其他的終端可以看到busybox容器已經啟動了

[root@host1?~]#?docker?ps
CONTAINER?ID????????IMAGE???????????????COMMAND?????????????CREATED??????????????STATUS??????????????PORTS???????????????NAMES
dc696a322096????????busybox?????????????"sh"????????????????About?a?minute?ago???Up?About?a?minute???????????????????????bbox

查看busybox容器中的信息可以看到此時id為1的進程是sh而不是init

/?#?ps
PID???USER?????TIME??COMMAND
????1?root??????0:00?sh
????6?root??????0:00?ps

在busybox容器中模擬apache

/?#?mkdir?/data/html?-p
/?#?echo?"test?page">>/data/html/index.html
/?#?
/?#?httpd?-f?-h?/data/html/

也可以在bash中查看一下容器的詳細信息

[root@host1?~]#?docker?inspect?bbox2?|?grep?IPAddress
????????????"SecondaryIPAddresses":?null,
????????????"IPAddress":?"172.17.0.3",
????????????????????"IPAddress":?"172.17.0.3",
  • 可看到這個容器的地址是172.16.0.3

其實在安裝了docker以后,系統(tǒng)默認生成一個虛擬網卡docker0,物理機就是用docker0和虛擬機通信的

[root@host1?~]#?ip?addr?
1:?lo:??mtu?65536?qdisc?noqueue?state?UNKNOWN?group?default?qlen?1000
2:?ens33:??mtu?1500?qdisc?pfifo_fast?state?UP?group?default?qlen?1000
3:?ens37:??mtu?1500?qdisc?pfifo_fast?state?UP?group?default?qlen?1000
4:?docker0:??mtu?1500?qdisc?noqueue?state?UP?group?default?
????link/ether?02:42:d5:cc:54:6d?brd?ff:ff:ff:ff:ff:ff
????inet?172.17.0.1/16?brd?172.17.255.255?scope?global?docker0
???????valid_lft?forever?preferred_lft?forever
????inet6?fe80::42:d5ff:fecc:546d/64?scope?link?
???????valid_lft?forever?preferred_lft?forever
6:?veth96dc278@if5:??mtu?1500?qdisc?noqueue?master?docker0?state?UP?group?default?
10:?veth793182e@if9:??mtu?1500?qdisc?noqueue?master?docker0?state?UP?group?default
  • docker0的地址是172.17.0.1

在物理機用curl可以訪問容器中的apache

[root@host1?~]#?curl?172.17.0.3
test?page

3、停止容器與重新啟動容器

執(zhí)行exit就可以退出容器

/?#?exit
[root@host1?~]#

退出容器后,容器只是停止了,但是依然存在

  • docker ps:查看正在運行的容器

  • docker ps -a:查看全部的容器,包括已經停止的

[root@host1?~]#?docker?ps
CONTAINER?ID????????IMAGE???????????????COMMAND?????????????CREATED?????????????STATUS??????????????PORTS???????????????NAMES

[root@host1?~]#?docker?ps?-a
CONTAINER?ID????????IMAGE???????????????COMMAND?????????????CREATED?????????????STATUS???????????????????????PORTS???????????????NAMES
dc696a322096????????busybox?????????????"sh"????????????????2?hours?ago?????????Up?2?hours???????????????????????????????????????bbox

重啟啟動這個停止的容器,用start命令,可能用兩個選項

  • -i:交互模式

  • -a:附加到終端上

[root@host1?~]#?docker?start?-i?-a?bbox

4、刪除已經停止的容器

[root@host1?~]#?docker?rm?bbox
bbox
[root@host1?~]#?docker?ps?-a
CONTAINER?ID????????IMAGE???????????????COMMAND?????????????CREATED?????????????STATUS???????????????????????PORTS???????????????NAMES

在創(chuàng)建容器的時候加入rm選項,可以實現(xiàn)當容器停止的時候,自動刪除

[root@host1?~]#?docker?run?--rm?-it?--name?bbox2?busybox
/?#?
/?#?exit

[root@host1?~]#?docker?ps?-a
CONTAINER?ID????????IMAGE???????????????COMMAND?????????????CREATED?????????????STATUS??????????????PORTS???????????????NAMES

在刪除容器時候可以指定名稱來刪除,也可以指定容器的ID來刪除

  • 在指定ID的時候,不需要寫全部的ID內容,寫開頭的一部分即可

[root@host1?~]#?docker?ps?-a
CONTAINER?ID????????IMAGE???????????????COMMAND?????????????CREATED?????????????STATUS????????????????????PORTS???????????????NAMES
9c2d1bbe32e8????????busybox?????????????"sh"????????????????3?seconds?ago???????Exited?(0)?1?second?ago???????????????????????bbox

[root@host1?~]#?docker?rm?9c2d
9c2d

[root@host1?~]#?docker?ps?-a
CONTAINER?ID????????IMAGE???????????????COMMAND?????????????CREATED?????????????STATUS??????????????PORTS???????????????NAMES

下面的命令可以一次將所有已經停止的容器刪除

[root@host1?~]#?docker?rm?$(docker?ps?-a?-q)

5、刪除鏡像、導出鏡像、導入鏡像

  • rmi:刪除本地的鏡像

  • load:導入鏡像文件

  • save:導出鏡像文件

查看當前有哪些鏡像

[root@host1?~]#?docker?image?ls
REPOSITORY??????????TAG?????????????????IMAGE?ID????????????CREATED?????????????SIZE
busybox?????????????latest??????????????b534869c81f0????????2?weeks?ago?????????1.22MB
nginx???????????????1.14-alpine?????????8a2fb25a19f5????????8?months?ago????????16MB

導出busybox的鏡像到tmp下

[root@host1?~]#?docker?save?busybox:latest>/tmp/busybox-latest.tar.gz
[root@host1?~]#?ls?/tmp/
busybox-latest.tar.gz

刪除本地的busybox鏡像

[root@host1?~]#?docker?rmi?b53
Untagged:?busybox:latest
Untagged:?busybox@sha256:1828edd60c5efd34b2bf5dd3282ec0cc04d47b2ff9caa0b6d4f07a21d1c08084
Deleted:?sha256:b534869c81f05ce6fbbdd3a3293e64fd032e059ab4b28a0e0d5b485cf904be4b
Deleted:?sha256:eac247cb7af5edc34d3620e8bce653d4af7d4e3a0427d487a97530c7fac0b841

[root@host1?~]#?docker?image?ls
REPOSITORY??????????TAG?????????????????IMAGE?ID????????????CREATED?????????????SIZE
nginx???????????????1.14-alpine?????????8a2fb25a19f5????????8?months?ago????????16MB

從tmp下導入鏡像文件

[root@host1?~]#?docker?load]??1.437MB/1.437MB
Loaded?image:?busybox:latest

[root@host1?~]#?docker?image?ls
REPOSITORY??????????TAG?????????????????IMAGE?ID????????????CREATED?????????????SIZE
busybox?????????????latest??????????????b534869c81f0????????2?weeks?ago?????????1.22MB
nginx???????????????1.14-alpine?????????8a2fb25a19f5????????8?months?ago????????16MB


名稱欄目:Docker系列2:Docker安裝配置與基本使用
文章轉載:http://fisionsoft.com.cn/article/jggdic.html