docker file

                        容器变为镜像

创建这个镜像

[root@localhost~]# docker create --name myxudong -it docker.io/java /bin/bash

98d030d2271ed262904af36e115f07dd5ea56fca2a1d7cf02ffed816fbdd7a96

进入这个镜像,在容器内创建文件

[root@localhost ~]# docker exec -it98d030d2271e /bin/bash

root@98d030d2271e:/# mkdir xudong

root@98d030d2271e:/# ls

bin boot  dev  etc home  lib  lib64 media  mnt  opt proc  root  run sbin  srv  sys tmp  usr  var xudong

root@98d030d2271e:/# exit

exit

将容器变成镜像为:bathroom

[root@localhost ~]# docker commit98d030d2271e bathroom

068bfde81f1e87930eae4f7b07f3e3c65fd6ec4a04eec06f2781d1f14ec7a75f

运行bathroom 这个容器进程查看。发现有:xudong  这个文件。

[root@localhost ~]# docker run -it bathroomls

Usage of loopback devices is stronglydiscouraged for production use. Either use `--storage-opt dm.thinpooldev` oruse `--storage-opt dm.no_warn_on_loop_devices=true` to suppress this warning.

bin boot  dev  etc home  lib  lib64 media  mnt  opt proc  root  run sbin  srv  sys tmp  usr  var xudong

[root@localhost ~]#

 

 

 

                        容器打包,发布为镜像,镜像变为容器

[root@localhost~]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES

5dc149936c54        bathroom            "ls"                39 minutes ago      Exited (0) 39 minutes ago                       agitated_stallman  

98d030d2271e        docker.io/java      "/bin/bash"         44 minutes ago      Up 43 minutes                                   myxudong           

[root@localhost ~]# docker export98d030d2271e >xudong_test.tar

[root@localhost ~]# cat xudong_test.tar |docker import - test/centos:v1.0

beb815f9e49e0d09ebadbcbdbfa1e603d0ee604225039770db2e13806130a237

[root@localhost~]# docker images

REPOSITORY                                TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

test/centos                               v1.0                beb815f9e49e        2 minutes ago       811.2 MB

bathroom                                 latest              068bfde81f1e        47 minutes ago      817.5 MB

docker.io/centos                          latest              0f73ae75014f        9 days ago          172.3 MB

<none>                                    <none>              5d9d413283ba        3 weeks ago         116.8 MB

docker.io/java                            latest              2f5a61e35ea4        3 weeks ago         817.5 MB

docker.io/jdeathe/centos-ssh-mysql        latest              4d49b9f0f5ef        6weeks ago         317.4 MB

docker.io/jdeathe/centos-ssh              latest              eebfc872609c        9 weeks ago         238.1 MB

docker.io/jdeathe/centos-ssh-apache-php   latest              05c259583efe        9 weeks ago         287.7 MB

 

[root@localhost ~]# docker create --nametest_xudong -it beb815f9e49e /bin/bash

31c00942aee17c93fc50b99c6da5c229241704b64b455b69aed15f6c1581399e

 

[root@localhost ~]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES

31c00942aee1        beb815f9e49e        "/bin/bash"         9 seconds ago                                                      test_xudong        

5dc149936c54        bathroom            "ls"                51 minutes ago      Exited (0) 51 minutes ago                       agitated_stallman  

98d030d2271e        docker.io/java      "/bin/bash"         56 minutes ago      Up 56 minutes                                  myxudong           

 

启动容器

[root@localhost ~]# docker start31c00942aee1

31c00942aee1

 

进入容器

[root@localhost ~]# docker exec -ti31c00942aee1 /bin/bash

root@31c00942aee1:/# ls

bin boot  dev  etc home  lib  lib64 media  mnt  opt proc  root  run sbin  srv  sys tmp  usr  var xudong

root@31c00942aee1:/#

 

 

[root@localhost ~]# docker run --nameovcer_the_container -i -t ubuntu /bin/bash
root@1ce9f640478d:/#

上面的命令将会创建一个名为ovcer_the_container的容器。对于一个合法的容器的名称来说只可以包括以下字符:小写字母a~z、大写字母A-Z、数字09、下划线、圆点、横线。

[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE             COMMAND            CREATED           STATUS                   PORTS             NAMES
8c342c0c275c        ubuntu:latest     "/bin/bash"        26 minutes ago     Exited (0) 5 minutes ago                     sharp_bohr 

 

8c342c0c275c:代表容器的ID

ubuntu:latest  :创建容器的镜像

"/bin/bash"  :容器最后执行的命令

26 minutes ago  :创建时间

Exited (0) 5 minutes :容器退出的状态

 sharp_bohr      :容器的名称

 

 

[root@localhost dockerfile]# cat Dockerfile

#xudong 20150918

#version 0.0.1

FROM 3b671edd9707

MAINTAINER frank"[email protected]"

 

RUN yum -yinstall nginx php-*

CMD systemctl start nginx.service

CMD systemctl start php.service

EXPOSE 80

EXPOSE 9000

[root@localhost dockerfile]# docker build-t xudong/nginx_php .


本文出自 “晴空” 博客,谢绝转载!

你可能感兴趣的:(File,docker)