0
点赞
收藏
分享

微信扫一扫

docker 之容器Container深入


文章目录

  • ​​Image到Container​​
  • ​​Container到Image​​
  • ​​centos样例​​
  • ​​1.我们首先拉取最新版本的centos镜像​​
  • ​​2.运行镜像​​
  • ​​3.修改上面容器Container的配置​​
  • ​​4.退出当前容器​​
  • ​​5.根据当前运行的Container 制作最新的image​​
  • ​​6.进入最新的容器的Container,验证是否包含vim​​
  • ​​Container资源限制​​
  • ​​内存限制 --memory 大小​​
  • ​​CPU限制 --cpu-shares 权重比例​​
  • ​​Container资源监控​​
  • ​​图形化资源监控 Weave Scope​​
  • ​​官方地址​​
  • ​​概述​​
  • ​​安装​​
  • ​​监控页面​​

Image到Container

1.我们通过 docker run image-name 可以生成Container,这里就不再进行赘述

Container到Image

1.既然image可以生成Container,相反,通过一个Container我们也可以生成一个image

centos样例

1.我们首先拉取最新版本的centos镜像

[root@iZwz91h49n3mj8r232gqweZ opt]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
Digest: sha256:f94c1d992c193b3dc09e297ffd54d8a4f1dc946c37cbeceb26d35ce1647f88d9
Status: Image is up to date for centos:latest
docker.io/library/centos:latest
[root@iZwz91h49n3mj8r232gqweZ opt]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 0f3e07c0138f 2 months ago 220MB
hello-world latest fce289e99eb9 11 months ago 1.84kB

2.运行镜像

[root@iZwz91h49n3mj8r232gqweZ opt]# docker run -d -it --name first-centos centos
332439fb5554d60553fff952078ec29511253ba563af5255ad5ac13cb43e2c55

3.修改上面容器Container的配置

[root@iZwz91h49n3mj8r232gqweZ opt]# docker exec -it first-centos bash
[root@332439fb5554 /]# pwd
/
[root@332439fb5554 /]# vim
bash: vim: command not found
[root@332439fb5554 /]# yum install -y vim
Failed to set locale, defaulting to C
CentOS-8 - AppStream 1.4 MB/s | 6.3 MB 00:04
CentOS-8 - Base 2.6 MB/s | 7.9 MB 00:03
CentOS-8 - Extras 817 B/s | 2.1 kB 00:02
Last metadata expiration check: 0:00:01 ago on Sun Dec 1 04:13:02 2019.
Dependencies resolved.
。。。。
Complete!

再次查看是否已经安装成功,可以使用了

[root@332439fb5554 /]# vim test.txt

4.退出当前容器

[root@332439fb5554 /]# exit   
exit

5.根据当前运行的Container 制作最新的image

[root@iZwz91h49n3mj8r232gqweZ opt]# docker commit first-centos vim-centos
sha256:c3a1001b03e45645888fe8c051f0cc28c5021132a02c4bf71b991cd5cb729c38
[root@iZwz91h49n3mj8r232gqweZ opt]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
vim-centos latest c3a1001b03e4 4 seconds ago 286MB
centos latest 0f3e07c0138f 2 months ago 220MB
hello-world latest fce289e99eb9 11 months ago 1.84kB

6.进入最新的容器的Container,验证是否包含vim

[root@iZwz91h49n3mj8r232gqweZ opt]# docker run -d -it --name first-vim-centos vim-centos
86a02874f0952c89924f11cfcceb0a0ee7a78b905e2b31d325a6e50a4c8208ab
[root@iZwz91h49n3mj8r232gqweZ opt]# docker exec -it first-vim-centos bash
[root@86a02874f095 /]# vim test.txt
[root@86a02874f095 /]#

1.从上面最新的容器,我们可以看到 已经包含vim这种功能;

Container资源限制

内存限制 --memory 大小

1.对于容器,如果资源不够用,它会自动去物理机器上去实时或许更多的内存,但是这样无限制去获取显然是不合适的;
因此我们可以在启动容器的过程中,预先设置内存;

[root@iZwz91h49n3mj8r232gqweZ ~]# docker run -d -it --memory 100M --name first-centos centos
7aa9960b8e1ae75de034d88cd8cdcbd3d4307d49138ac6d427247ede01166147
[root@iZwz91h49n3mj8r232gqweZ ~]#

CPU限制 --cpu-shares 权重比例

[root@iZwz91h49n3mj8r232gqweZ ~]# docker run -d -it --memory 100M --cpu-shares 10 --name second-centos centos                     
f987e94f9251c01a8b48c591fd7866adb6fd1fccee394acd2452325fa3796860
[root@iZwz91h49n3mj8r232gqweZ ~]#

Container资源监控

图形化资源监控 Weave Scope

官方地址

​​https://github.com/weaveworks/scope​​

概述

1.Weave Scope 是对Docker 以及K8S的一种比较好的监控工具

安装

[root@iZwz91h49n3mj8r232gqweZ ~]# cd /opt/
[root@iZwz91h49n3mj8r232gqweZ opt]# ll
total 765164
drwx--x--x 4 root root 4096 Dec 1 09:09 containerd
-rw-r--r-- 1 root root 0 Dec 1 09:05 device-mapper-persistent-data
drwxr-xr-x 3 root root 4096 Dec 1 10:36 harbor
-rw-r--r-- 1 root root 597857483 Dec 1 09:43 harbor-offline-installer-v1.7.1.tgz
drwxr-xr-x 7 10 143 4096 Jul 7 2018 jdk1.8.0_181
-rw-r--r-- 1 root root 185646832 Nov 30 19:55 jdk-8u181-linux-x64.tar.gz
-rw-r--r-- 1 root root 163 Dec 1 09:05 lvm2
[root@iZwz91h49n3mj8r232gqweZ opt]# sudo curl -L git.io/scope -o /usr/local/bin/scope
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:05 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:06 --:--:-- 0
0 0 0 595 0 0 87 0 --:--:-- 0:00:06 --:--:-- 87
100 11664 100 11664 0 0 1478 0 0:00:07 0:00:07 --:--:-- 20903
[root@iZwz91h49n3mj8r232gqweZ opt]# sudo chmod a+x /usr/local/bin/scope
[root@iZwz91h49n3mj8r232gqweZ opt]# scope launch
Unable to find image 'weaveworks/scope:1.12.0' locally
1.12.0: Pulling from weaveworks/scope
5d20c808ce19: Pull complete
bbde3b770a97: Pull complete
b648e9d51e9d: Pull complete
d284dfe4b906: Pull complete
83e88b3b6bfb: Pull complete
a00e32a7ca7a: Pull complete
5cbd69f2576c: Pull complete
4915fcaf1597: Pull complete
7d8a6e574629: Pull complete
f0175c50e258: Pull complete
Digest: sha256:2f063422cd74d6b0cc6a4c7a26aeb531a69d719de1fa039ca592877662051446
Status: Downloaded newer image for weaveworks/scope:1.12.0
b9cd90b554769211c5a11d39c2d1a7caf55fa4898da3fb9b44d0e6e90d3df118
Scope probe started
Weave Scope is listening at the following URL(s):
* http://XXX.XXX.XXX.XXX:4040/
* http://XXX.XXX.XXX.XXX:4040/
[root@iZwz91h49n3mj8r232gqweZ opt]#

监控页面

然后访问(这里注意下,需要开通4040的访问权限)

​​http://XXX.XXX.XXX.XXX:4040/​​

docker 之容器Container深入_vim


举报

相关推荐

0 条评论