docker2

 

Docker镜像介绍

 

[root@zizhen02 ~]# docker container commit (或者简写#docker commit)

"docker container commit" requires at least 1 and at most 2 arguments.

See 'docker container commit --help'.

 

Usage:  docker container commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

 

Create a new image from a container's changes

[root@zizhen02 ~]#

 

[root@zizhen02 ~]# docker image build (简写为#docker build)

"docker image build" requires exactly 1 argument.

See 'docker image build --help'.

 

Usage:  docker image build [OPTIONS] PATH | URL | -

 

Build an image from a Dockerfile

[root@zizhen02 ~]# docker build

"docker build" requires exactly 1 argument.

See 'docker build --help'.

 

Usage:  docker build [OPTIONS] PATH | URL | -

 

Build an image from a Dockerfile

[root@zizhen02 ~]#

 

通过已经存在的image,创建一个新的image

运行centos  container安装vim,退出

[root@zizhen02 ~]# docker run -it centos

[root@adeb5ede1e7a /]# yum install -y vim

[root@adeb5ede1e7a ~]# exit

exit

[root@zizhen02 ~]# docker container ls -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES

adeb5ede1e7a        centos              "/bin/bash"         5 minutes ago       Exited (0) 47 seconds ago                       mystifying_hermann

[root@zizhen02 ~]#

Commit成一个新的image ,

[root@zizhen02 ~]# docker container commit

"docker container commit" requires at least 1 and at most 2 arguments.

See 'docker container commit --help'.

 

Usage:  docker container commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

 

Create a new image from a container's changes

[root@zizhen02 ~]# docker container ls -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES

adeb5ede1e7a        centos              "/bin/bash"         11 minutes ago      Exited (0) 6 minutes ago                       mystifying_hermann

[root@zizhen02 ~]# docker  commit

"docker commit" requires at least 1 and at most 2 arguments.

See 'docker commit --help'.

 

Usage:  docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

 

Create a new image from a container's changes

[root@zizhen02 ~]# docker container commit mystifying_hermann xiaoming163/centos-vim

sha256:a2af669c930e09ae1db6124ffbe3874553c28ed52be7084e480c9991fd1dbcac

[root@zizhen02 ~]# docker images

REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE

xiaoming163/centos-vim   latest              a2af669c930e        7 seconds ago       335MB

xiaoli163/hello-world    latest              a821094d0306        38 hours ago        857kB

nginx                    latest              881bd08c0b08        8 days ago          109MB

ubuntu                   14.04               5dbc3f318ea5        7 weeks ago         188MB

centos                   latest              1e1148e4cc2c        3 months ago        202MB

[root@zizhen02 ~]# docker container ls

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@zizhen02 ~]# docker container ls -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES

adeb5ede1e7a        centos              "/bin/bash"         14 minutes ago      Exited (0) 9 minutes ago                       mystifying_hermann

[root@zizhen02 ~]# docker history

"docker history" requires exactly 1 argument.

See 'docker history --help'.

 

Usage:  docker history [OPTIONS] IMAGE

 

Show the history of an image

[root@zizhen02 ~]# docker history 1e1148e4cc2c

IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT

1e1148e4cc2c        3 months ago        /bin/sh -c #(nop)  CMD ["/bin/bash"]            0B                  

<missing>           3 months ago        /bin/sh -c #(nop)  LABEL org.label-schema.sc…   0B                 

<missing>           3 months ago        /bin/sh -c #(nop) ADD file:6f877549795f4798a…   202MB              

[root@zizhen02 ~]# docker history a2af669c930e

IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT

a2af669c930e        4 minutes ago       /bin/bash                                       133MB              

1e1148e4cc2c        3 months ago        /bin/sh -c #(nop)  CMD ["/bin/bash"]            0B                 

<missing>           3 months ago        /bin/sh -c #(nop)  LABEL org.label-schema.sc…   0B                 

<missing>           3 months ago        /bin/sh -c #(nop) ADD file:6f877549795f4798a…   202MB              

[root@zizhen02 ~]#

以上不提倡创建image, 不安全;

[root@zizhen02 ~]# docker image rm a2af669c930e

Untagged: xiaoming163/centos-vim:latest

Deleted: sha256:a2af669c930e09ae1db6124ffbe3874553c28ed52be7084e480c9991fd1dbcac

Deleted: sha256:991dfb3163719f8ad5692ebe404ebe8537f3ee49b9b472c9f7e9cd8126a43085

[root@zizhen02 ~]# docker images

REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE

xiaoli163/hello-world   latest              a821094d0306        38 hours ago        857kB

nginx                   latest              881bd08c0b08        8 days ago          109MB

ubuntu                  14.04               5dbc3f318ea5        7 weeks ago         188MB

centos                  latest              1e1148e4cc2c        3 months ago        202MB

[root@zizhen02 ~]#

 

用Dockerfile 创建新的image;

[root@zizhen02 ~]# mkdir docker-centos-vim

[root@zizhen02 ~]# cd docker-centos-vim/

[root@zizhen02 docker-centos-vim]# vim Dockerfile

[root@zizhen02 docker-centos-vim]# cat Dockerfile

FROM centos

RUN yum install -y vim

[root@zizhen02 docker-centos-vim]# ls

Dockerfile

[root@zizhen02 docker-centos-vim]# ll

total 4

-rw-r--r-- 1 root root 35 Mar 13 13:25 Dockerfile

[root@zizhen02 docker-centos-vim]# docker build -t xiaoming163/centos-vim-new .

Sending build context to Docker daemon  2.048kB

Step 1/2 : FROM centos

 ---> 1e1148e4cc2c

Step 2/2 : RUN yum install -y vim

 ---> Running in 8b87ae034b92

Loaded plugins: fastestmirror, ovl

Determining fastest mirrors

 * base: mirrors.aliyun.com

 * extras: mirrors.shu.edu.cn

 * updates: mirrors.huaweicloud.com

Resolving Dependencies

--> Running transaction check

---> Package vim-enhanced.x86_64 2:7.4.160-5.el7 will be installed

………………..

………………..

………………..

vim-common.x86_64 2:7.4.160-5.el7                                            

  vim-filesystem.x86_64 2:7.4.160-5.el7                                        

  which.x86_64 0:2.20-7.el7                                                    

 

Complete!

Removing intermediate container 8b87ae034b92

 ---> f9f19d2bc847

Successfully built f9f19d2bc847

Successfully tagged xiaoming163/centos-vim-new:latest

[root@zizhen02 docker-centos-vim]#

[root@zizhen02 docker-centos-vim]# docker images

REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE

xiaoming163/centos-vim-new   latest              f9f19d2bc847        5 minutes ago       335MB

xiaoli163/hello-world        latest              a821094d0306        39 hours ago        857kB

nginx                        latest              881bd08c0b08        8 days ago          109MB

ubuntu                       14.04               5dbc3f318ea5        7 weeks ago         188MB

centos                       latest              1e1148e4cc2c        3 months ago        202MB

[root@zizhen02 docker-centos-vim]#

 

 

Docker  dkfile语法讲解和案例

第1个关键字: FROM

 

 

 

第2个关键字:

 

 

 

 

 

 

第3个关键字: workdir

 

 

 

 

 

 

 

Docker代码库:https://github.com/docker-library

Dockerfile 官方文档:https://docs.docker.com/v17.09/engine/reference/builder/

 

 

 

Docker在虚拟机核心组件run  vs  cmd  vs  entrypoint

 

 

 

 

[root@zizhen02 ~]# mkdir cmd-run-entrypoint

[root@zizhen02 ~]# cd cmd-run-entrypoint/

[root@zizhen02 cmd-run-entrypoint]# vim Dockerfile

[root@zizhen02 cmd-run-entrypoint]# cat Dockerfile

FROM centos

ENV name Docker

ENTRYPOINT echo "hello $name"

[root@zizhen02 cmd-run-entrypoint]# docker build -t xiaoming/centos-entrypoint-shell .

Sending build context to Docker daemon  2.048kB

Step 1/3 : FROM centos

 ---> 1e1148e4cc2c

Step 2/3 : ENV name Docker

 ---> Running in 6fcabefdb228

Removing intermediate container 6fcabefdb228

 ---> e2827f0b9fb9

Step 3/3 : ENTRYPOINT echo "hello $name"

 ---> Running in 9741e86b2236

Removing intermediate container 9741e86b2236

 ---> 344ec38e6b59

Successfully built 344ec38e6b59

Successfully tagged xiaoming/centos-entrypoint-shell:latest

[root@zizhen02 cmd-run-entrypoint]# docker images

REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE

xiaoming/centos-entrypoint-shell   latest              344ec38e6b59        30 seconds ago      202MB

xiaoming163/centos-vim-new         latest              f9f19d2bc847        2 hours ago         335MB

xiaoli163/hello-world              latest              a821094d0306        40 hours ago        857kB

nginx                              latest              881bd08c0b08        8 days ago          109MB

ubuntu                             14.04               5dbc3f318ea5        7 weeks ago         188MB

centos                             latest              1e1148e4cc2c        3 months ago        202MB

[root@zizhen02 cmd-run-entrypoint]# docker run xiaoming/centos-entrypoint-shell

hello Docker

[root@zizhen02 cmd-run-entrypoint]#

 

Exec格式如下;怎样被shell执行命令

[root@zizhen02 cmd-run-entrypoint]# ls

Dockerfile

[root@zizhen02 cmd-run-entrypoint]# vim Dockerfile

[root@zizhen02 cmd-run-entrypoint]# cat Dockerfile

FROM centos

ENV name Docker

ENTRYPOINT ["/bin/echo", "hello $name"]

[root@zizhen02 cmd-run-entrypoint]# docker build -t xiaoming/centos-entrypoint-exec .

Sending build context to Docker daemon  2.048kB

Step 1/3 : FROM centos

 ---> 1e1148e4cc2c

Step 2/3 : ENV name Docker

 ---> Using cache

 ---> e2827f0b9fb9

Step 3/3 : ENTRYPOINT ["/bin/echo", "hello $name"]

 ---> Running in 0f0607b2e879

Removing intermediate container 0f0607b2e879

 ---> b2137f7cf5da

Successfully built b2137f7cf5da

Successfully tagged xiaoming/centos-entrypoint-exec:latest

[root@zizhen02 cmd-run-entrypoint]# docker image ls

REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE

xiaoming/centos-entrypoint-exec    latest              b2137f7cf5da        15 seconds ago      202MB

xiaoming/centos-entrypoint-shell   latest              344ec38e6b59        4 minutes ago       202MB

xiaoming163/centos-vim-new         latest              f9f19d2bc847        2 hours ago         335MB

xiaoli163/hello-world              latest              a821094d0306        40 hours ago        857kB

nginx                              latest              881bd08c0b08        8 days ago          109MB

ubuntu                             14.04               5dbc3f318ea5        7 weeks ago         188MB

centos                             latest              1e1148e4cc2c        3 months ago        202MB

[root@zizhen02 cmd-run-entrypoint]# docker run xiaoming/centos-entrypoint-exec

hello $name

[root@zizhen02 cmd-run-entrypoint]#

[root@zizhen02 cmd-run-entrypoint]# vim Dockerfile

[root@zizhen02 cmd-run-entrypoint]# docker build -t xiaoming/centos-entrypoint-exec-new1 .

Sending build context to Docker daemon  2.048kB

Step 1/3 : FROM centos

 ---> 1e1148e4cc2c

Step 2/3 : ENV name Docker

 ---> Using cache

 ---> e2827f0b9fb9

Step 3/3 : ENTRYPOINT ["/bin/bash","-c","echo","hello $name"]

 ---> Running in 73f4b46e312b

Removing intermediate container 73f4b46e312b

 ---> 620ace42fe56

Successfully built 620ace42fe56

Successfully tagged xiaoming/centos-entrypoint-exec-new1:latest

[root@zizhen02 cmd-run-entrypoint]# cat Dockerfile

FROM centos

ENV name Docker

ENTRYPOINT ["/bin/bash","-c","echo","hello $name"]

[root@zizhen02 cmd-run-entrypoint]# docker images

REPOSITORY                             TAG                 IMAGE ID            CREATED              SIZE

xiaoming/centos-entrypoint-exec-new1   latest              620ace42fe56        20 seconds ago       202MB

xiaoming/centos-entrypoint-exec-new    latest              6995428fbe6a        About a minute ago   202MB

xiaoming/centos-entrypoint-exec        latest              b2137f7cf5da        10 minutes ago       202MB

xiaoming/centos-entrypoint-shell       latest              344ec38e6b59        14 minutes ago       202MB

xiaoming163/centos-vim-new             latest              f9f19d2bc847        2 hours ago          335MB

xiaoli163/hello-world                  latest              a821094d0306        41 hours ago         857kB

nginx                                  latest              881bd08c0b08        8 days ago           109MB

ubuntu                                 14.04               5dbc3f318ea5        7 weeks ago          188MB

centos                                 latest              1e1148e4cc2c        3 months ago         202MB

[root@zizhen02 cmd-run-entrypoint]# docker run xiaoming/centos-entrypoint-exec-new1

 

[root@zizhen02 cmd-run-entrypoint]# docker run xiaoming/centos-entrypoint-exec-new1 .

 

[root@zizhen02 cmd-run-entrypoint]# docker run xiaoming/centos-entrypoint-exec-new1

 

[root@zizhen02 cmd-run-entrypoin

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值