Centos下的纯命令记录Docker学习(2)-配置阿里云镜像加速和开启Docker远程访问(生产环境谨慎开启,不然可能被用于挖矿)

原因:

龟速和加速的区别。

步骤

1)登入阿里云镜像服务中心(需使用账号登入)
地址:https://cr.console.aliyun.com/cn-shenzhen/new
2)获取地址:

image.png

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

在/etc/docker/下查找daemon.json文件,无则创建。并写入以下的内容:


[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": 在启动的容器里执行的命令

[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远程访问可以用于手续的,直接使用Pycharm等工具连接的到我们的Docker,然后直接的使用工具进行镜像的制作!

PS:该方法千万不要在生产环境,否则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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,185评论 6 503
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,652评论 3 393
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,524评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,339评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,387评论 6 391
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,287评论 1 301
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,130评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,985评论 0 275
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,420评论 1 313
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,617评论 3 334
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,779评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,477评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,088评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,716评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,857评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,876评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,700评论 2 354