Docker学习总结(3)——Docker实战之入门以及Dockerfile(三)

阅读:574 2019-03-19 14:42:37 来源:新网

应用镜像csphere/wordpress:4.2

#cddocker-training/wordpress/#ls-a.license.txtwp-config-sample.phpwp-login.php..readme.htmlwp-contentwp-mail.phpdockerfilewp-activate.phpwp-cron.phpwp-settings.php.dockerignorewp-adminwp-includeswp-signup.phpindex.phpwp-blog-header.phpwp-links-opml.phpwp-trackback.phpinit.shwp-comments-post.phpwp-load.phpxmlrpc.php/docker-training/wordpress#catdockerfilefromcsphere/php-fpm:5.4addinit.sh/init.shentrypoint["/init.sh","/usr/bin/supervisord","-n","-c","/etc/supervisord.conf"]

使用docker后,在项目代码目录下,写dockerfile文件,非常方便把项目代码直接打包到docker镜像中,如有哪些文件不想被打包进去,可以在.dockerignore文件中定义

dockerfile解析:

生成wordpress镜像

dockerbuild-tcsphere/wordpress:4.2.

查看当前主机本地都有哪些docker镜像

dockerimages

创建wordpress准备

查看主机ip地址

ifconfigeth0192.168.1.20

创建wordpress容器:

dockerrun-d-p80:80--namewordpress-ewordpress_db_host=192.168.1.20-ewordpress_db_user=admin-ewordpress_db_password=csphere2015csphere/wordpress:4.249d0cddb4e6998a43285fe09165030ba80485065867b9cb8fae9fbdb97cd077f

参数解析:

访问http://your_ip,选择语言,并进行设置wordpress

entrypoint解析

定义:

anentrypointallowsyoutoconfigureacontainerthatwillrunasanexecutable

运行一个docker容器像运行一个程序一样

entrypoint的使用方法:

1.entrypoint["executable","param1","param2"](thepreferredexecform)

推荐使用1方法,启动起来后,pid为1

2.entrypointcommandparam1param2(shellform)

启动起来后,pid号为shell命令执行完的pid号

cmd解析

cmd的使用方法:

1.cmd["executable","param1","param2"](execform,thisisthepreferredform)

运行一个可执行的文件并提供参数

2.cmd["param1","param2"](asdefaultparameterstoentrypoint)

为entrypoint指定参数

3.cmdcommandparam1param2(shellform)

是以”/bin/sh-c”的方法执行的命令

实战测试cmd

vimdockerfilefromcentos:centos7.1.1503cmd["/bin/echo","thisistestcmd"]

生成cmd镜像dockerbuild-tcsphere/cmd:0.1.生成cmd容器,进行测试dockerrun-it--rmcsphere/cmd:0.1thisistestcmd测试是否可以替换cmd的命令dockerrun-itcsphere/cmd:0.1/bin/bash[root@c1963a366319/]#

测试结果,在dockerfile中定义的cmd命令,在执行dockerrun的时候,cmd命令可以被替换。

实战测试entrypoint

fromcentos:centos7.1.1503entrypoint["/bin/echo","thisistestentrypoint"]

生成ent(entrypoint)镜像dockerbuild-tcsphere/ent:0.1.

生成ent容器,进行测试dockerrun-itcsphere/ent:0.1thisistestentrypoint测试是否可以替换entrypoint的命令dockerrun-itcsphere/ent:0.1/bin/bashthisistestentrypoint/bin/bash

测试结果,在dockerfile定义的entrypoint命令,通过以上方式不能被替换

实战再次测试entrypoint

相关文章
{{ v.title }}
{{ v.description||(cleanHtml(v.content)).substr(0,100)+'···' }}
你可能感兴趣
推荐阅读 更多>
推荐商标

{{ v.name }}

{{ v.cls }}类

立即购买 联系客服