Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。
主要利用 linux 内核 namespace 实现沙盒隔离,用cgroup 实现资源限制
一个完整的Docker有以下几个部分组成:
dockerClient客户端
Docker Daemon守护进程
Docker Image镜像
DockerContainer容器
安装docser,开启服务
[root@foundation7 Desktop]# yum install -y
docker-engine-17.03.1.ce-1.el7.centos.x86_64.rpm
docker-engine-selinux-17.03.1.ce-1.el7.centos.noarch.rpm
[root@foundation7 Desktop]# systemctl start docker
查看版本号信息:
[root@foundation7 Desktop]# docker version
Client:
Version: 17.03.1-ce
API version: 1.27
Go version: go1.7.5
Git commit: c6d412e
Built: Fri Mar 24 00:36:45 2017
OS/Arch: linux/amd64
Server:
Version: 17.03.1-ce
API version: 1.27 (minimum version 1.12)
Go version: go1.7.5
Git commit: c6d412e
Built: Fri Mar 24 00:36:45 2017
OS/Arch: linux/amd64
Experimental: false
镜像用来创建容器,是容器的只读模板,默认可以从 docker hub 上下载。docker 的镜像是
增量修改,每次创建新的镜像都会在父镜像上构建一个增量的层,基于 AUFS 技术。
# docker search 查询镜像
# docker pull 拉取镜像
# docker push 推送镜像
# docker save ubuntu > ubuntu.tar 导出镜像
# docker load -i ubuntu.tar 导入镜像
# docker commit 更新镜像
# docker rmi 删除镜像
导入镜像
[root@foundation7 Desktop]# docker load -i /home/kiosk/Desktop/game2048.tar
011b303988d2: Loading layer 5.05 MB/5.05 MB
36e9226e74f8: Loading layer 51.46 MB/51.46 MB
192e9fad2abc: Loading layer 3.584 kB/3.584 kB
6d7504772167: Loading layer 4.608 kB/4.608 kB
88fca8ae768a: Loading layer 629.8 kB/629.8 kB
Loaded image: game2048:latest
查看镜像
[root@foundation7 Desktop]# docker images game2048
REPOSITORY TAG IMAGE ID CREATED SIZE
game2048 latest 19299002fdbe 20 months ago 55.5 MB
具体步骤:1.输入:www.aliyun.com,点击注册–>注册帐号–>登陆—->管理控制台—>点击产品与服务–>容器镜像服务,点击镜像加速器查看配置文件
[root@foundation62 docker]# mkdir -p /etc/docker/
[root@foundation62 docker]# vim daemon.json
{
"registry-mirrors": ["https://umsuwu83.mirror.aliyuncs.com"]
}
[root@foundation62 docker]# systemctl daemon-reload
[root@foundation62 docker]# systemctl restart docker.service
创建成功后可以进行查找对应的镜像
[root@foundation62 docker]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 9323 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker c... 1386 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable ... 609 [OK]
jrcs/letsencrypt-nginx-proxy-companion LetsEncrypt container to use with nginx as... 396 [OK]
kong Open-source Microservice & API Management ... 216 [OK]
webdevops/php-nginx Nginx with PHP-FPM 111 [OK]
kitematic/hello-world-nginx A light-weight nginx container that demons... 108
zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server ... 63 [OK]
bitnami/nginx Bitnami nginx Docker Image 57 [OK]
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 43 [OK]
linuxserver/nginx An Nginx container, brought to you by Linu... 38
tobi312/rpi-nginx NGINX on Raspberry Pi / armhf 20 [OK]
blacklabelops/nginx Dockerized Nginx Reverse Proxy Server. 12 [OK]
nginxdemos/nginx-ingress NGINX Ingress Controller for Kubernetes . ... 11
wodby/drupal-nginx Nginx for Drupal container image 10 [OK]
webdevops/nginx Nginx container 8 [OK]
nginxdemos/hello NGINX webserver that serves a simple page ... 8 [OK]
centos/nginx-18-centos7 Platform for running nginx 1.8 or building... 7
1science/nginx Nginx Docker images that include Consul Te... 4 [OK]
centos/nginx-112-centos7 Platform for running nginx 1.12 or buildin... 4
pebbletech/nginx-proxy nginx-proxy sets up a container running ng... 2 [OK]
toccoag/openshift-nginx Nginx reverse proxy for Nice running on sa... 1 [OK]
travix/nginx NGinx reverse proxy 1 [OK]
mailu/nginx Mailu nginx frontend 1 [OK]
ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 0 [OK]
对镜像进行拉取:
[root@foundation62 docker]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
be8881be8156: Pull complete
32d9726baeef: Pull complete
87e5e6f71297: Pull complete
Digest: sha256:d85914d547a6c92faa39ce7058bd7529baacab7e0cd4255442b04577c4d1f424
Status: Downloaded newer image for nginx:latest
[root@foundation62 docker]# docker images nginx
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest c82521676580 3 weeks ago 109 MB
# docker run -it --name vm1 ubuntu bash 创建容器
# docker ps -a 查看容器进程
# docker attach vm1 连接容器
# docker top vm1 查看容器进程
# docker logs vm1 查看容器指令输出 -f 参数可以实时查看
# docker inspect vm1 查看容器详情
# docker stats vm1 查看容器资源使用率
# docker diff vm1 查看容器修改
# docker run -d --name vm1 ubuntu bash -c "while true; do echo westos; sleep 1; done" 后台运行
# docker stop vm1 停止容器
# docker start vm1 启动容器
# docker kill vm1 强制干掉容器
# docker restart vm1 重启容器
# docker pause/unpause vm1 暂停/恢复容器
# docker rm vm1 删除容器
# docker export vm1 > vm1.tar 导出容器
# docker import vm1.tar image 导入容器为镜像 image
通过镜像创建容器 -d打入后台
[root@foundation7 Desktop]# docker run -d --name vm1 game2048
91be26d778ee743824536d266df492756c7c0e8d26e9a0400b81d0035299394a
[root@foundation7 Desktop]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
91be26d778ee game2048 "/bin/sh -c 'sed -..." 10 minutes ago Up 10 minutes 80/tcp, 443/tcp vm1
[root@foundation7 Desktop]# docker inspect vm1
访问ipaddress
(ctrl+pq将容器打入后台 ctrl+d将容器关闭不打入后台)
[root@foundation62 docker---]# docker run -it --name vm1 ubuntu bash
root@73e92c41d675:/# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
root@73e92c41d675:/# [root@foundation62 docker---]#
# ctlr+pq退出之后,重新连接容器
[root@foundation62 docker---]# docker container attach vm1
root@73e92c41d675:/#
root@foundation7 Desktop]# docker load -i /home/kiosk/Desktop/nginx.tar
[root@foundation7 Desktop]# docker images nginx
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest af4b3d7d5401 2 years ago 190 MB
[root@foundation7 Desktop]# docker run -d --name vm2 -p 8080:80 nginx
57f3982fb3192e530808f4b4845b1d0ad84e4c0389b20456366de81b41ef7a7c
[root@foundation7 Desktop]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
57f3982fb319 nginx "nginx -g 'daemon ..." 9 seconds ago Up 7 seconds 443/tcp, 0.0.0.0:8080->80/tcp vm2
91be26d778ee game2048 "/bin/sh -c 'sed -..." About an hour ago Up About an hour 80/tcp, 443/tcp vm1
[root@foundation7 Desktop]# docker inspect vm2
[root@foundation7 ~]# cd /etc/docker/
[root@foundation7 docker]# ls
daemon.json key.json
[root@foundation7 docker]# cat daemon.json
{
"registry-mirrors": ["https://umsuwu83.mirror.aliyuncs.com"]
}
[root@foundation7 docker]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
be8881be8156: Pull complete
32d9726baeef: Pull complete
87e5e6f71297: Pull complete
Digest: sha256:d85914d547a6c92faa39ce7058bd7529baacab7e0cd4255442b04577c4d1f424
Status: Downloaded newer image for nginx:latest
[root@foundation7 docker]# docker images nginx
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest c82521676580 3 weeks ago 109 MB
移除所有停止的容器
[root@foundation7 docker]# docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:
91be26d778ee743824536d266df492756c7c0e8d26e9a0400b81d0035299394a
Total reclaimed space: 4.074 kB
[root@foundation7 docker]# docker run -d --name vm1 nginx
e11349ca6abe8c3e19d691c49a593607da1064cc7bd4007f967bbf14a5799251
给vm1进行推送发布界面
[root@foundation7 ~]# cd /tmp/docker/web/
[root@foundation7 web]# cat index.html
www.westos.org
www.westos.org
www.westos.org
www.westos.org
www.westos.org
www.westos.org
www.westos.org
www.westos.org
www.westos.org
[root@foundation7 ~]# docker run -d --name vm1 -v /tmp/docker/web:/usr/share/nginx/html nginx
b15fd4de1bcc151e548d9161d145794decc11377d0511b721e7f842e80b3811b
使用 supervisor封装httpd和sshd镜像
[root@foundation7 docker]# pwd
/tmp/docker
[root@foundation7 docker]# vim Dockerfile
FROM rhel7
EXPOSE 80 22
COPY dvd.repo /etc/yum.repos.d/dvd.repo
RUN rpmdb --rebuilddb && yum install -y httpd openssh-clients openssh-server supervisor && yum clean all && ssh-keygen -q -t rsa -f /etc/ssh/ssh_host_rsa_key -N "" && ssh-keygen -q -t ecdsa -f /etc/ssh_host_ecdsa_key -N "" && ssh-keygen -q -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N "" && echo root:westps|chpasswd
COPY supervisord.conf /etc/supervisord.conf
CMD ["/usr/bin/supervisord"
[root@foundation7 docker]# cat supervisord.conf
[supervisord]
nodaemon=true
[program:sshd]
command=/usr/sbin/sshd -D
[program:httpd]
command=/usr/sbin/httpd
新建镜像
[root@foundation7 docker]# docker build -t rhel7:v3 .
Sending build context to Docker daemon 8.192 kB
Step 1/6 : FROM rhel7
---> 0a3eb3fde7fd
Step 2/6 : EXPOSE 80 22
---> Running in 7923821b439c
---> 48dc3ffb0527
Removing intermediate container 7923821b439c
Step 3/6 : COPY dvd.repo /etc/yum.repos.d/dvd.repo
---> bc890fd0a34f
Removing intermediate container 6aa447d4d25e
Step 4/6 : RUN rpmdb --rebuilddb && yum install -y httpd openssh-clients openssh-server supervisor && yum clean all && ssh-keygen -q -t rsa -f /etc/ssh/ssh_host_rsa_key -N "" && ssh-keygen -q -t ecdsa -f /etc/ssh_host_ecdsa_key -N "" && ssh-keygen -q -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N "" && echo root:westps|chpasswd
---> Running in 6f131bc4f902
Skipping unreadable repository '///etc/yum.repos.d/rhel7.repo'
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-45.el7 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-45.el7 for package: httpd-2.4.6-45.el7.x86_64
--> Processing Dependency: system-logos >= 7.92.1-1 for package: httpd-2.4.6-45.el7.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-45.el7.x86_64
--> Processing Dependency: libsystemd-daemon.so.0(LIBSYSTEMD_DAEMON_31)(64bit) for package: httpd-2.4.6-45.el7.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-45.el7.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-45.el7.x86_64
--> Processing Dependency: libsystemd-daemon.so.0()(64bit) for package: httpd-2.4.6-45.el7.x86_64
---> Package openssh-clients.x86_64 0:6.6.1p1-31.el7 will be installed
--> Processing Dependency: openssh = 6.6.1p1-31.el7 for package: openssh-clients-6.6.1p1-31.el7.x86_64
--> Processing Dependency: fipscheck-lib(x86-64) >= 1.3.0 for package: openssh-clients-6.6.1p1-31.el7.x86_64
--> Processing Dependency: libedit.so.0()(64bit) for package: openssh-clients-6.6.1p1-31.el7.x86_64
--> Processing Dependency: libfipscheck.so.1()(64bit) for package: openssh-clients-6.6.1p1-31.el7.x86_64
---> Package openssh-server.x86_64 0:6.6.1p1-31.el7 will be installed
--> Processing Dependency: libwrap.so.0()(64bit) for package: openssh-server-6.6.1p1-31.el7.x86_64
---> Package supervisor.noarch 0:3.1.3-3.el7 will be installed
--> Processing Dependency: python-meld3 >= 0.6.5 for package: supervisor-3.1.3-3.el7.noarch
--> Processing Dependency: python-setuptools for package: supervisor-3.1.3-3.el7.noarch
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package fipscheck-lib.x86_64 0:1.4.1-5.el7 will be installed
--> Processing Dependency: /usr/bin/fipscheck for package: fipscheck-lib-1.4.1-5.el7.x86_64
---> Package httpd-tools.x86_64 0:2.4.6-45.el7 will be installed
---> Package libedit.x86_64 0:3.0-12.20121213cvs.el7 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
---> Package openssh.x86_64 0:6.6.1p1-31.el7 will be installed
---> Package python-meld3.x86_64 0:0.6.10-1.el7 will be installed
---> Package python-setuptools.noarch 0:0.9.8-4.el7 will be installed
--> Processing Dependency: python-backports-ssl_match_hostname for package: python-setuptools-0.9.8-4.el7.noarch
---> Package redhat-logos.noarch 0:70.0.3-6.el7 will be installed
---> Package systemd-libs.x86_64 0:219-30.el7 will be installed
--> Processing Dependency: libdw.so.1()(64bit) for package: systemd-libs-219-30.el7.x86_64
---> Package tcp_wrappers-libs.x86_64 0:7.6-77.el7 will be installed
--> Running transaction check
---> Package elfutils-libs.x86_64 0:0.166-2.el7 will be installed
--> Processing Dependency: elfutils-libelf(x86-64) = 0.166-2.el7 for package: elfutils-libs-0.166-2.el7.x86_64
--> Processing Dependency: libelf.so.1(ELFUTILS_1.7)(64bit) for package: elfutils-libs-0.166-2.el7.x86_64
---> Package fipscheck.x86_64 0:1.4.1-5.el7 will be installed
---> Package python-backports-ssl_match_hostname.noarch 0:3.4.0.2-4.el7 will be installed
--> Processing Dependency: python-backports for package: python-backports-ssl_match_hostname-3.4.0.2-4.el7.noarch
--> Running transaction check
---> Package elfutils-libelf.x86_64 0:0.158-3.el7 will be updated
---> Package elfutils-libelf.x86_64 0:0.166-2.el7 will be an update
---> Package python-backports.x86_64 0:1.0-8.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository
Size
================================================================================
Installing:
httpd x86_64 2.4.6-45.el7 dvd 1.2 M
openssh-clients x86_64 6.6.1p1-31.el7 dvd 642 k
openssh-server x86_64 6.6.1p1-31.el7 dvd 440 k
supervisor noarch 3.1.3-3.el7 docker 445 k
Installing for dependencies:
apr x86_64 1.4.8-3.el7 dvd 103 k
apr-util x86_64 1.5.2-6.el7 dvd 92 k
elfutils-libs x86_64 0.166-2.el7 dvd 262 k
fipscheck x86_64 1.4.1-5.el7 dvd 21 k
fipscheck-lib x86_64 1.4.1-5.el7 dvd 11 k
httpd-tools x86_64 2.4.6-45.el7 dvd 84 k
libedit x86_64 3.0-12.20121213cvs.el7 dvd 92 k
mailcap noarch 2.1.41-2.el7 dvd 31 k
openssh x86_64 6.6.1p1-31.el7 dvd 437 k
python-backports x86_64 1.0-8.el7 dvd 5.8 k
python-backports-ssl_match_hostname noarch 3.4.0.2-4.el7 dvd 12 k
python-meld3 x86_64 0.6.10-1.el7 docker 73 k
python-setuptools noarch 0.9.8-4.el7 dvd 397 k
redhat-logos noarch 70.0.3-6.el7 dvd 13 M
systemd-libs x86_64 219-30.el7 dvd 367 k
tcp_wrappers-libs x86_64 7.6-77.el7 dvd 66 k
Updating for dependencies:
elfutils-libelf x86_64 0.166-2.el7 dvd 208 k
Transaction Summary
================================================================================
Install 4 Packages (+16 Dependent packages)
Upgrade ( 1 Dependent package)
Total download size: 18 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
--------------------------------------------------------------------------------
Total 62 MB/s | 18 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : fipscheck-1.4.1-5.el7.x86_64 1/22
Installing : fipscheck-lib-1.4.1-5.el7.x86_64 2/22
Installing : apr-1.4.8-3.el7.x86_64 3/22
Installing : apr-util-1.5.2-6.el7.x86_64 4/22
Installing : openssh-6.6.1p1-31.el7.x86_64 5/22
Installing : httpd-tools-2.4.6-45.el7.x86_64 6/22
Updating : elfutils-libelf-0.166-2.el7.x86_64 7/22
Installing : elfutils-libs-0.166-2.el7.x86_64 8/22
Installing : systemd-libs-219-30.el7.x86_64 9/22
Installing : libedit-3.0-12.20121213cvs.el7.x86_64 10/22
Installing : python-backports-1.0-8.el7.x86_64 11/22
Installing : python-backports-ssl_match_hostname-3.4.0.2-4.el7.noarch 12/22
Installing : python-setuptools-0.9.8-4.el7.noarch 13/22
Installing : python-meld3-0.6.10-1.el7.x86_64 14/22
Installing : redhat-logos-70.0.3-6.el7.noarch 15/22
Installing : tcp_wrappers-libs-7.6-77.el7.x86_64 16/22
Installing : mailcap-2.1.41-2.el7.noarch 17/22
Installing : httpd-2.4.6-45.el7.x86_64 18/22
Installing : openssh-server-6.6.1p1-31.el7.x86_64 19/22
Installing : supervisor-3.1.3-3.el7.noarch 20/22
Installing : openssh-clients-6.6.1p1-31.el7.x86_64 21/22
Cleanup : elfutils-libelf-0.158-3.el7.x86_64 22/22
Verifying : python-backports-ssl_match_hostname-3.4.0.2-4.el7.noarch 1/22
Verifying : mailcap-2.1.41-2.el7.noarch 2/22
Verifying : tcp_wrappers-libs-7.6-77.el7.x86_64 3/22
Verifying : httpd-2.4.6-45.el7.x86_64 4/22
Verifying : python-setuptools-0.9.8-4.el7.noarch 5/22
Verifying : redhat-logos-70.0.3-6.el7.noarch 6/22
Verifying : python-meld3-0.6.10-1.el7.x86_64 7/22
Verifying : openssh-server-6.6.1p1-31.el7.x86_64 8/22
Verifying : openssh-clients-6.6.1p1-31.el7.x86_64 9/22
Verifying : elfutils-libs-0.166-2.el7.x86_64 10/22
Verifying : apr-util-1.5.2-6.el7.x86_64 11/22
Verifying : python-backports-1.0-8.el7.x86_64 12/22
Verifying : supervisor-3.1.3-3.el7.noarch 13/22
Verifying : fipscheck-lib-1.4.1-5.el7.x86_64 14/22
Verifying : systemd-libs-219-30.el7.x86_64 15/22
Verifying : apr-1.4.8-3.el7.x86_64 16/22
Verifying : libedit-3.0-12.20121213cvs.el7.x86_64 17/22
Verifying : openssh-6.6.1p1-31.el7.x86_64 18/22
Verifying : httpd-tools-2.4.6-45.el7.x86_64 19/22
Verifying : elfutils-libelf-0.166-2.el7.x86_64 20/22
Verifying : fipscheck-1.4.1-5.el7.x86_64 21/22
Verifying : elfutils-libelf-0.158-3.el7.x86_64 22/22
Installed:
httpd.x86_64 0:2.4.6-45.el7
openssh-clients.x86_64 0:6.6.1p1-31.el7
openssh-server.x86_64 0:6.6.1p1-31.el7
supervisor.noarch 0:3.1.3-3.el7
Dependency Installed:
apr.x86_64 0:1.4.8-3.el7
apr-util.x86_64 0:1.5.2-6.el7
elfutils-libs.x86_64 0:0.166-2.el7
fipscheck.x86_64 0:1.4.1-5.el7
fipscheck-lib.x86_64 0:1.4.1-5.el7
httpd-tools.x86_64 0:2.4.6-45.el7
libedit.x86_64 0:3.0-12.20121213cvs.el7
mailcap.noarch 0:2.1.41-2.el7
openssh.x86_64 0:6.6.1p1-31.el7
python-backports.x86_64 0:1.0-8.el7
python-backports-ssl_match_hostname.noarch 0:3.4.0.2-4.el7
python-meld3.x86_64 0:0.6.10-1.el7
python-setuptools.noarch 0:0.9.8-4.el7
redhat-logos.noarch 0:70.0.3-6.el7
systemd-libs.x86_64 0:219-30.el7
tcp_wrappers-libs.x86_64 0:7.6-77.el7
Dependency Updated:
elfutils-libelf.x86_64 0:0.166-2.el7
Complete!
Skipping unreadable repository '///etc/yum.repos.d/rhel7.repo'
Cleaning repos: docker dvd
Cleaning up everything
---> da56ac41f01d
Removing intermediate container 6f131bc4f902
Step 5/6 : COPY supervisord.conf /etc/supervisord.conf
---> a005a2cf0c6d
Removing intermediate container 6cbe5f97528d
Step 6/6 : CMD /usr/bin/supervisord
---> Running in d6b2153bf4ac
---> b17d295b8cc6
Removing intermediate container d6b2153bf4ac
Successfully built b17d295b8cc6
创建容器:
[root@foundation7 docker]# docker run -d --name vm1 -v /tmp/docker/web:/var/www/html rhel7:v3
a366220c7432c45cc06ac655d1f8a66e3687caf788d49d4934ae830ad2f1992a
[root@foundation7 docker]# docker inspect vm1
CMD可被覆盖.
[root@foundation7 test]# cat Dockerfile
FROM rhel7
CMD echo "hello world!"
[root@foundation7 test]# docker build -t rhel7:v4 .
[root@foundation7 test]# docker run --rm rhel7:v4
hello world!
[root@foundation7 test]# docker run --rm rhel7:v4 echo westos
westos
[root@foundation7 test]# docker rmi rhel7:v4
Untagged: rhel7:v4
ENTRYPOINT不可被覆盖
[root@foundation7 test]# cat Dockerfile
FROM rhel7
ENTRYPOINT echo "hello world!"
[root@foundation7 test]# docker build -t rhel7:v4 .
[root@foundation7 test]# docker run --rm rhel7:v4
hello world!
[root@foundation7 test]# docker run --rm rhel7:v4 westos
hello world!
[root@foundation7 test]# docker run --rm rhel7:v4 echo westos
hello world!
CMD作为ENTRYPOINT的参数
[root@foundation7 test]# vim Dockerfile
FROM rhel7
ENTRYPOINT ["/bin/echo","hello"]
CMD ["world"]
[root@foundation7 test]# docker build -t rhel7:v4 .
[root@foundation7 test]# docker run --rm rhel7:v4
hello world
[root@foundation7 test]# docker run --rm rhel7:v4 westos
hello westos