Write a Dockerfile

In detail:

  • FROM(指定基础image)

    构建指令,必须指定且需要在Dockerfile其他指令的前面。后续的指令都依赖于该指令指定的image。FROM指令指定的基础image可以是官方远程仓库中的,也可以位于本地仓库。

    FROM <image>
    FROM <image>:<tag>
  • MAINTAINER(用来指定镜像创建者信息)构建指令,用于将image的制作者相关的信息写入到image中。当我们对该image执行docker inspect命令时,输出中有相应的字段记录该信息。

      MAINTAINER <name>
  • RUN(安装软件用)构建指令,RUN可以运行任何被基础image支持的命令。如基础image选择了ubuntu,那么软件管理部分只能使用ubuntu的命令。

    RUN <command> (the command is run in a shell - `/bin/sh -c`)
    RUN ["executable", "param1", "param2" ... ] (exec form)
  • CMD(设置container启动时执行的操作)设置指令,用于container启动时指定的操作。该操作可以是执行自定义脚本,也可以是执行系统命令。该指令只能在文件中存在一次,如果有多个,则只执行最后一条。

     CMD ["executable","param1","param2"] (like an exec, this is the preferred form)
    CMD command param1 param2 (as a shell)
  • ENTRYPOINT(设置container启动时执行的操作)设置指令,指定容器启动时执行的命令,可以多次设置,但是只有最后一个有效。

     ENTRYPOINT ["executable", "param1", "param2"] (like an exec, the preferred form)
    ENTRYPOINT command param1 param2 (as a shell)
  • USER(设置container容器的用户)设置指令,设置启动容器的用户,默认是root用户。

  • EXPOSE(指定容器需要映射到宿主机器的端口)

     EXPOSE <port> [<port>...]
    # 映射多个端口
    EXPOSE port1 port2 port3
  • ENV(用于设置环境变量)

     ENV <key> <value>
    ENV JAVA_HOME /path/to/java/dirent
  • ADD(从src复制文件到container的dest路径)

     ADD <src> <dest>

For example, create a dockerfile in /home/pyt/test/:

FROM ubuntu:14.04.4
MAINTAINER puyangsky "puyangsky@163.com"
RUN apt-get update
RUN apt-get install -y nginx
RUN echo "hi , i am in your container" > /usr/share/nginx/html/index.html
expose 80

Build the image:

# docker build -t="puyangsky/test:v0.1" /home/pyt/test/

the result is like:

we see all images:

# docker images

Run the image

the second one is that we just created. And we run it up.

# docker run -d -p 80:80 --name test puyangsky/test:v0.1 nginx -g "daemon off;"
4f6306d2ff200ce37cd3c1ddffee97d29725aeb1871122051ca9a96e0ee852a0

we open the browser and type "localhost:80" and we get:

Push the image to Dockerhub

root@pyt:/home/pyt/test# docker push puyangsky/test:v0.1
The push refers to a repository [puyangsky/test] (len: 1)
229fc9eec22a: Image already exists
737e1830ecac: Image successfully pushed
12094b42ed11: Image successfully pushed
2ff6c8fffe7e: Image successfully pushed
874509123f48: Image successfully pushed
87d8afb341b5: Image successfully pushed
46e772baf32a: Image successfully pushed
0a7a3b768106: Image successfully pushed
e094bcb9d0fe: Image successfully pushed
a16f6804bd85: Image successfully pushed
Digest: sha256:174cec58394568c6af9a8a98c822a352f535811b2c30171e0e2e217bd60436be

And the image is uploaded to hub.docker.com, https://hub.docker.com/r/puyangsky/test/

Automated from github

Created a github repo: https://github.com/puyangsky/nginx_demo, and create from dockerhub.

So the image is automated by the github repo at https://hub.docker.com/r/puyangsky/nginx_demo/

最新文章

  1. Java 名词
  2. CentOS升级Python 2.6到2.7
  3. 微软职位内部推荐-Sr. SW Engineer for Azure Networking
  4. JS 学习笔记--9---变量-作用域-内存相关
  5. 转载:页面加载swf插件:swfobject
  6. Js 读写cookies
  7. TP框架多上传域上传图片
  8. HDU 4893 Wow! Such Sequence!(2014年多校联合 第三场 G)(线段树)
  9. C--控制语句循环例子
  10. 转:设置Loadrunner负载机临时文件目录
  11. Java 包装类Integer的值比较
  12. HTTPS和HTTP的区别是什么?
  13. c# ffmpeg视频转换【转载】
  14. Canvas-自由绘制
  15. 微信开发获取地理位置实例(java,非常详细,附工程源码)
  16. 解决Azure 消息队列ServiceBus提示证书不信任无权限的问题
  17. saltstack通过jinja模板,将变量值增加到配置文件中?通过引用变量值修改配置文件?
  18. python 定义带默认参数的函数
  19. Linux-入门配置jdk,tomcat,mysql
  20. 颠倒的价牌|2013年蓝桥杯A组题解析第四题-fishers

热门文章

  1. [转]Excel 取汉字拼音首位
  2. Spring +SpringMVC 实现文件上传功能。。。
  3. 图解Android Studio导入Eclipse项目源码
  4. iOS中两个APP之间的跳转和通信
  5. Java范型随笔
  6. What he did
  7. 【转】进程与CPU
  8. js之事件
  9. innobackupex使用实践
  10. JavaScript-创建新数组