docker 镜像的构建CMD ENTRYPOINT 的区别

多个服务的镜像构建
需要在dockerfile里面将所选装的服务应用写完全,并下在supervisor

[root@foundation19 al]# cat Dockerfile 
FROM rhel7
EXPOSE 80 22
COPY dvd.repo /etc/yum.repos.d/dvd.repo
RUN rpmdb --rebuilddb && yum install -y httpd openssh-server openssh-clients supervisor && yum clean all && ssh-keygen -q -t rsa -f /etc/ssh_host_rsa_key -N "" && ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N "" && ssh-keygen -q -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N "" && echo root:redhat | chpasswd
COPY supervisord.conf /etc/supervisord.conf
CMD ["/usr/bin/supervisord"]
[root@foundation19 al]# cat dvd.repo 
[rhel-dvd]
name="Remote classroom copy of dvd"
baseurl=http://172.25.254.250/rhel7.3
gpgcheck=0

[docker]
name=docker
baseurl=http://172.25.254.250/pub/docker
gpgcheck=0

supervisor的配置文件中写名启动的程序

[root@foundation19 al]# cat supervisord.conf 
[supervisord]
nodaemon=true

[program:sshd]
command=/usr/sbin/sshd -D


[program:httpd]
command=/usr/sbin/httpd

构建镜像

[root@foundation19 al]# docker build -t rhel7:v4 .

利用该镜像构建一个容器

[root@foundation19 al]# docker run -d --name  vm1  -v /root/aaa/:/var/www/html rhel7:v4 
96390f6651beb076e192fe0ceeecf44d494af4dc4602e975750302f24438ff7a

这里写图片描述
这里写图片描述
cmd ENTRYPOINT

[root@foundation19 test]# vim Dockerfile
[root@foundation19 test]# docker build -t rhel7:v2 .
Sending build context to Docker daemon 2.048 kB
Step 1/2 : FROM rhel7
 ---> 0a3eb3fde7fd
Step 2/2 : CMD echo "hello word!" #使用cmd可以被覆盖
 ---> Running in d72aa769ec69
 ---> 864403728301
Removing intermediate container d72aa769ec69
Successfully built 864403728301
[root@foundation19 test]# docker run --rm rhel7:v2 
hello word!
[root@foundation19 test]# docker run --rm rhel7:v2 echo yes  # 在后边加内容时候输出结果会更改原来的结果会被覆盖掉
yes
[root@foundation19 test]# docker rmi  rhel7:v2 
Untagged: rhel7:v2
Deleted: sha256:864403728301b90e6f893d5398ccbe515c2474916a95fcf030c6d2b9ffd1a5c2
[root@foundation19 test]# vim Dockerfile 
[root@foundation19 test]# docker build -t rhel7:v2 .
Sending build context to Docker daemon 2.048 kB
Step 1/2 : FROM rhel7
 ---> 0a3eb3fde7fd
Step 2/2 : ENTRYPOINT echo "hello world" #使用 ENTRYPOINT 不会配覆盖掉
 ---> Running in c8629771d34b
 ---> 90918057b327
Removing intermediate container c8629771d34b
Successfully built 90918057b327
[root@foundation19 test]# docker run --rm rhel7:v2 echo ww #无论后面跟的是什么都不会被覆盖掉
hello world
[root@foundation19 test]# docker rmi  rhel7:v2 
Untagged: rhel7:v2
Deleted: sha256:90918057b3271c7e104a0176f6edc43b7b5cf9e40757b098d457be9094d78d61
[root@foundation19 test]# vim Dockerfile 
[root@foundation19 test]# docker build -t rhel7:v2 .
Sending build context to Docker daemon 2.048 kB
Step 1/3 : FROM rhel7
 ---> 0a3eb3fde7fd
Step 2/3 : ENTRYPOINT /bin/echo hello
 ---> Running in 2020a37760aa
 ---> 64ec5e8f7306
Removing intermediate container 2020a37760aa
Step 3/3 : CMD word
 ---> Running in 3abf6f528c6c
 ---> 6f560a9b78d3
Removing intermediate container 3abf6f528c6c
Successfully built 6f560a9b78d3
[root@foundation19 test]# docker run --rm rhel7:v2 boy
hello boy
[root@foundation19 test]# docker run --rm rhel7:v2 echo boy
hello echo boy
[root@foundation19 test]# docker rmi  rhel7:v2 
Untagged: rhel7:v2
Deleted: sha256:6f560a9b78d399a16f02f5f2c4c72d3bd8fee8e6ca44e030549922f70460e6c9
Deleted: sha256:64ec5e8f730646613d64a3ac6cf5017322edef8c18ed0da4a8581c8f3aff054f
[root@foundation19 test]# vim Dockerfile 
[root@foundation19 test]# docker build -t rhel7:v2 .
Sending build context to Docker daemon 2.048 kB
Step 1/3 : FROM rhel7
 ---> 0a3eb3fde7fd
Step 2/3 : ENV name redhat
 ---> Running in 9f26b182cbd5
 ---> a74f7ae44bb6
Removing intermediate container 9f26b182cbd5
Step 3/3 : ENTRYPOINT /bin/sh -c echo $name #使用shell格式可以用来传递参数
 ---> Running in 37aa06e11225
 ---> db3c942ab266
Removing intermediate container 37aa06e11225
Successfully built db3c942ab266
[root@foundation19 test]# docker run --rm rhel7:v2 
redhat

对cpu 内存进行压力测试

[root@foundation19 ~]# docker run --rm -it --name vm3 -m 100M --memory 100M stress --vm 1 --vm-bytes 90M
docker run --rm -it --cpu-shares 512 stress -c 4
docker run --rm -it --cpu-shares 1024 stress -c 4

可以看到相差为1倍
因为我这里时4核的cpu
所以-c 后面为4
这两可以处于一种竞争的状态 否则 看不出什么效果
这里写图片描述
控制磁盘的写入速度

[root@foundation19 ~]# docker run --rm -it --device-write-bps /dev/sda:10M ubuntu
ubuntu         ubuntu:latest  
[root@foundation19 ~]# docker run --rm -it --device-write-bps /dev/sda:10M ubuntu
root@c5e4fe341989:/# dd if=/dev/zero of=testfile bs=1M count=100 oflag=direct #直接向磁盘中写入
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 9.95562 s, 10.5 MB/s 

以下为限制20M

[root@foundation19 ~]# docker run --rm -it --device-write-bps /dev/sda:20M ubuntu
root@9d7b31ab83b5:/# dd if=/dev/zero of=testfile bs=1M count=100 oflag=direct
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 4.93384 s, 21.3 MB/s 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值