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/

如何提交docker镜像到DockerHub的更多相关文章

  1. 如何push一个docker镜像到DockerHub上

    在DockerHub上创建账号:https://hub.docker.com/ 这里我的账号是firewarm 本地下载镜像(这里拿alpine做示例),并为镜像打tag [root@host-30 ...

  2. 发布Docker 镜像到dockerhub

    公有仓库 docker提供了一个类似于github的仓库dockerhub, 网址 https://hub.docker.com/ 需要注册使用 注意要保证image的tag是账户名,如果镜像名字不对 ...

  3. 如何使用vs将asp.net core项目添加容器支持并发布docker镜像到私有dockerhub和添加k8s/helm管理

    这篇文章介绍一下,如何使用VS2017给asp.net core添加容器支持,并发布镜像到私有docker hub,然后用chart管理容器镜像的操作流程. 话不多说,just do it. 新建项目 ...

  4. [Docker镜像] 关于阿里云容器镜像服务的使用(以天池比赛提交镜像为例)

    最近在参加天池比赛,由于比赛需要使用阿里云容器镜像服务完成线上预测任务,所以花费了3-4天的时间了解并使用Docker完成相关镜像操作,在此分享下我学习的内容,以下是本文的目录结构: 介绍 镜像 容器 ...

  5. Docker镜像的管理和创建

    1. Docker镜像和Docker容器:      Docker镜像实际上是一系列的文件系统,通常的Linux系统一般是两层文件系统,bootfs和rootfs,bootfs就是bootloader ...

  6. 使用镜像仓库托管自己构建的Docker镜像

    自己构建的Docker镜像,默认存储在本机中,Docker有提供某些方式分享这些镜像,但不是主流的镜像分享方式,也有违于开源社区的共享精神. 本文介绍如何使用GitHub托管Dockerfile:使用 ...

  7. Docker镜像细节

    前言 只有光头才能变强. 文本已收录至我的GitHub仓库,欢迎Star:https://github.com/ZhongFuCheng3y/3y 回顾前面: 为什么需要Docker? Docker入 ...

  8. docker镜像基本操作

    操作镜像 使用 docker 命令行操作 docker 镜像 获取镜像 使用「docker pull +镜像名称」从网络上下载image镜像 core@localhost ~ $ docker pul ...

  9. Docker容器打包成镜像 - OpenDaylight官方 SDN Hub Tutorial VM 的docker镜像

    由于工作需要,在看OpenDaylight (一个SDN的开源控制器) 官方Tutorial有一个比较基础且介绍比较详细的文档(http://sdnhub.org/tutorials/opendayl ...

随机推荐

  1. JS 菜单栏一直悬浮在顶部代码

    只需要把下面代码放到js中: $(function(){                //获取要定位元素距离浏览器顶部的距离         var navH = $(".menu&quo ...

  2. 修改eclipse中settings.xml和默认资源库保存地址

    1.打开eclipse 2.window-->references-->Maven0-->User Settings:修改User Settings,Browse重新选择新位置D:\ ...

  3. mysql and 和 or 的 优先级和 查询问题

    1. select * from trade where id=1 and cid=1 or pid=2 ; 2. select * from trade where cid=1 or (pid=2 ...

  4. __slots__ 属性绑定

    s = Student() # 创建新的实例 s.name = 'Michael' # 绑定属性'name' s.age = 25 # 绑定属性'age' s.score = 99 # 绑定属性'sc ...

  5. 拾遗:『Linux Capability』

    『Linux Capability』 For the purpose of performing permission checks, traditional UNIX implementations ...

  6. 关于CSS3的代码总结(部分)

    1. 构造样式表:selector{ Property:value; Property:value; } Selector是需要更改样式的元素,property为css属性的名称,value应用的哪种 ...

  7. Python-pycharm

    进入博客园的第一篇随笔,作为一个编程菜鸟,最近在学习Python,为毕设做准备.总觉得Python自带的idle不太好用,一位“大鸟”向我推荐了pycharm,于是我就抱着试试看的态度下了一个,目前感 ...

  8. Ubuntu下配置L2TP

    发现PPTP已经不可用了,不知是不是又被墙了.只能尝试L2TP了. Ubuntu可视化配置界面network-manager默认是没有L2TP配置选项的,需要安装第三方插件软件: sudo apt-a ...

  9. Linux更改服务器Hostname

    在我们需要维护较多的服务器时,有意义的Hostname将时刻提醒我们这台服务器的功能. ****** 1.Debian echo '127.0.1.1 git-server' >> /et ...

  10. [转]正确使用SQLCipher来加密Android数据库 - 朝野布告

    参考文档:http://www.tuicool.com/articles/eYNFbuA Android本身自带有不加密的数据库SQLite,如果要保存密码之类的敏感数据在本地的话方法一是使用字段加密 ...