Centos下的純命令記錄Docker學習(2)-配置阿里云鏡像加速和開啟Docker遠程訪問(生產環(huán)境謹慎開啟勋眯,不然可能被用于挖礦)

原因:

龜速和加速的區(qū)別捡偏。

步驟

1)登入阿里云鏡像服務中心(需使用賬號登入)
地址:https://cr.console.aliyun.com/cn-shenzhen/new
2)獲取地址:

image.png

3)按照要求修改OS的Docker配置文件
image.png

在/etc/docker/下查找daemon.json文件垛叨,無則創(chuàng)建额获。并寫入以下的內容:


[root@localhost ~]# nano /etc/docker/daemon.json
[root@localhost ~]#

寫入的內容:

{
  "registry-mirrors": ["https://xxxxxxxx.mirror.aliyuncs.com"]
}

4 ) 重啟daemon

 [root@localhost ~]#systemctl daemon-reload

5 ) 重啟docker

[root@localhost ~]# systemctl restart docker

6 ) 查看修改的后docker信息

[root@localhost ~]# docker info
Client:
 Debug Mode: false

Server:
 Containers: 2
  Running: 0
  Paused: 0
  Stopped: 2
 Images: 1
 Server Version: 19.03.13
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Native Overlay Diff: false
 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: 8fba4e9a7d01810a393d5d25a3621dc101981175
 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
 init version: fec3683
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 3.10.0-514.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 1
 Total Memory: 976.5MiB
 Name: localhost.localdomain
 ID: TT6R:HUR2:3AQG:JLBU:CGAO:BG5T:LMC4:FYTX:PRGV:4D56:4TAN:BGFE
 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://aiyf7r3a.mirror.aliyuncs.com/
 Live Restore Enabled: false

WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
[root@localhost ~]#

7 ) 測試拉取一個ubuntu:15.10的鏡像

[root@localhost ~]# docker pull ubuntu:15.10
15.10: Pulling from library/ubuntu
7dcf5a444392: Pull complete
759aa75f3cee: Pull complete
3fa871dc8a2b: Pull complete
224c42ae46e7: Pull complete
Digest: sha256:02521a2d079595241c6793b2044f02eecf294034f31d6e235ac4b2b54ffc41f3
Status: Downloaded newer image for ubuntu:15.10
docker.io/library/ubuntu:15.10
[root@localhost ~]#

附加其他的對鏡像的操作測試處理:

8) 查看本地的鏡像


[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              bf756fb1ae65        9 months ago        13.3kB
ubuntu              15.10               9b9cb95443b5        4 years ago         137MB
[root@localhost ~]#

9)使用鏡像跑一個示例 前臺模式的啟動

說明:/bin/echo "Hello world": 在啟動的容器里執(zhí)行的命令

[root@localhost ~]# docker run ubuntu:15.10 /bin/echo "Hello world"
Hello world

其他一些容器的基本的操作:
root@0a22083fa318:~# cd ll
bash: cd: ll: No such file or directory
root@0a22083fa318:~# cd ~
root@0a22083fa318:~# ll
total 8
drwx------. 2 root root   37 Jul  6  2016 ./
drwxr-xr-x. 1 root root    6 Oct 19 07:57 ../
-rw-r--r--. 1 root root 3106 Feb 20  2014 .bashrc
-rw-r--r--. 1 root root  140 Feb 20  2014 .profile
root@0a22083fa318:~# cd ..
root@0a22083fa318:/# ls
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr
root@0a22083fa318:/# eixt
bash: eixt: command not found
root@0a22083fa318:/# exit
exit
[root@localhost ~]# docker run -i -t ubuntu:15.10 /bin/bash
root@a2cc1c83603a:/# exit

10)前臺模式的啟動 查看的相關的容器情況


[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS                        PORTS               NAMES
a2cc1c83603a        ubuntu:15.10        "/bin/bash"              26 seconds ago       Exited (0) 24 seconds ago                         elated_cartwright
0a22083fa318        ubuntu:15.10        "/bin/bash"              About a minute ago   Exited (127) 29 seconds ago                       epic_galileo
e0069b97f043        ubuntu:15.10        "/bin/echo 'Hello wo…"   3 minutes ago        Exited (0) 3 minutes ago                          intelligent_lamport
209fc9dd3324        hello-world         "/hello"                 56 minutes ago       Exited (0) 56 minutes ago                         flamboyant_knuth
d6087f654d9e        hello-world         "/hello"                 2 hours ago          Exited (0) 2 hours ago                            practical_wozniak

11)后臺的模式啟動的容器實例

[root@localhost ~]# docker run -d ubuntu:15.10 /bin/sh -c "while true; do echo hello world; sleep 1; done"
f1b40b91bb48a2cc832412b9e71860a44cddcd4fa83a82db7b64fcc9c68ad82f
[root@localhost ~]#

12)再次查看容器的情況:


[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
f1b40b91bb48        ubuntu:15.10        "/bin/sh -c 'while t…"   3 minutes ago       Up 3 minutes                            great_tereshkova
[root@localhost ~]#

13)停止容器:

[root@localhost ~]# docker stop f1b40b91bb48
f1b40b91bb48
[root@localhost ~]#

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

開啟Docker遠程訪問

Docker遠程訪問可以用于手續(xù)的霜浴,直接使用Pycharm等工具連接的到我們的Docker晶衷,然后直接的使用工具進行鏡像的制作!

PS:該方法千萬不要在生產環(huán)境阴孟,否則100%被挖礦!!!!!!!!!!!!!

步驟

  • 1)編輯docker的宿主機文件/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# 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

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# 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

[Install]
WantedBy=multi-user.target


  • 2)修改內容:
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
  • 3)更新修改
[root@localhost web_statistics]# systemctl daemon-reload
    1. 重啟docker服務
[root@localhost web_statistics]# systemctl restart docker
    1. 測試訪問情況
[root@localhost web_statistics]# curl http://localhost:2375/version
{"Platform":{"Name":"Docker Engine - Community"},"Components":[{"Name":"Engine","Version":"19.03.13","Details":{"ApiVersion":"1.40","Arch":"amd64","BuildTime":"2020-09-16T17:02:21.000000000+00:00","Experimental":"false","GitCommit":"4484c46d9d","GoVersion":"go1.13.15","KernelVersion":"3.10.0-1127.19.1.el7.x86_64","MinAPIVersion":"1.12","Os":"linux"}},{"Name":"containerd","Version":"1.3.7","Details":{"GitCommit":"8fba4e9a7d01810a393d5d25a3621dc101981175"}},{"Name":"runc","Version":"1.0.0-rc10","Details":{"GitCommit":"dc9208a3303feef5b3839f4323d9beb36df0a9dd"}},{"Name":"docker-init","Version":"0.18.0","Details":{"GitCommit":"fec3683"}}],"Version":"19.03.13","ApiVersion":"1.40","MinAPIVersion":"1.12","GitCommit":"4484c46d9d","GoVersion":"go1.13.15","Os":"linux","Arch":"amd64","KernelVersion":"3.10.0-1127.19.1.el7.x86_64","BuildTime":"2020-09-16T17:02:21.000000000+00:00"}
[root@localhost web_statistics]#

  • 6)外網訪問


    image.png
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末晌纫,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子永丝,更是在濱河造成了極大的恐慌锹漱,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,657評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件慕嚷,死亡現(xiàn)場離奇詭異哥牍,居然都是意外死亡,警方通過查閱死者的電腦和手機喝检,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,889評論 3 394
  • 文/潘曉璐 我一進店門嗅辣,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人挠说,你說我怎么就攤上這事澡谭。” “怎么了损俭?”我有些...
    開封第一講書人閱讀 164,057評論 0 354
  • 文/不壞的土叔 我叫張陵蛙奖,是天一觀的道長。 經常有香客問我杆兵,道長雁仲,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,509評論 1 293
  • 正文 為了忘掉前任琐脏,我火速辦了婚禮伯顶,結果婚禮上,老公的妹妹穿的比我還像新娘骆膝。我一直安慰自己祭衩,他們只是感情好,可當我...
    茶點故事閱讀 67,562評論 6 392
  • 文/花漫 我一把揭開白布阅签。 她就那樣靜靜地躺著掐暮,像睡著了一般。 火紅的嫁衣襯著肌膚如雪政钟。 梳的紋絲不亂的頭發(fā)上路克,一...
    開封第一講書人閱讀 51,443評論 1 302
  • 那天樟结,我揣著相機與錄音,去河邊找鬼精算。 笑死瓢宦,一個胖子當著我的面吹牛,可吹牛的內容都是我干的灰羽。 我是一名探鬼主播驮履,決...
    沈念sama閱讀 40,251評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼廉嚼!你這毒婦竟也來了玫镐?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 39,129評論 0 276
  • 序言:老撾萬榮一對情侶失蹤怠噪,失蹤者是張志新(化名)和其女友劉穎恐似,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體傍念,經...
    沈念sama閱讀 45,561評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡矫夷,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,779評論 3 335
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了憋槐。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片双藕。...
    茶點故事閱讀 39,902評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖秦陋,靈堂內的尸體忽然破棺而出蔓彩,到底是詐尸還是另有隱情,我是刑警寧澤驳概,帶...
    沈念sama閱讀 35,621評論 5 345
  • 正文 年R本政府宣布赤嚼,位于F島的核電站,受9級特大地震影響顺又,放射性物質發(fā)生泄漏更卒。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,220評論 3 328
  • 文/蒙蒙 一稚照、第九天 我趴在偏房一處隱蔽的房頂上張望蹂空。 院中可真熱鬧,春花似錦果录、人聲如沸上枕。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,838評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽辨萍。三九已至,卻和暖如春返弹,著一層夾襖步出監(jiān)牢的瞬間锈玉,已是汗流浹背爪飘。 一陣腳步聲響...
    開封第一講書人閱讀 32,971評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留拉背,地道東北人师崎。 一個月前我還...
    沈念sama閱讀 48,025評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像椅棺,于是被迫代替她去往敵國和親犁罩。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,843評論 2 354