通过dockerfile build一个base image,在上面运行一个c程序

首先

1、创建一个目录。

2、然后创建一个c写的小程序,并且gcc编译好。

3、创建一个Dockerfile


FROM scratch #scrath表示运行在内核之上
ADD soeasy2 / #增加文件
CMD ["/soeasy2"]#运行程序

4、build image

5、运行image

[root@localhost docker_test]# ls
Dockerfile soeasy2 soeasy.c soeasy.sh
[root@localhost docker_test]# vim Dockerfile
[root@localhost docker_test]# docker build -t bigni/test1 . #-t表示tag 最后的点号,表示在当前目录寻找Dockerfile
Sending build context to Docker daemon .8kB
Step / : FROM scratch
--->
Step / : ADD soeasy2 /
---> 3ec8199c2855
Step / : CMD ["/soeasy2"]
---> Running in 7fcaf3239425
Removing intermediate container 7fcaf3239425
---> f5620b92331c
Successfully built f5620b92331c
Successfully tagged bigni/test1:latest
[root@localhost docker_test]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
bigni/test1 latest f5620b92331c seconds ago 861kB
ubuntu 14.04 2c5e00d77a67 weeks ago 188MB
centos latest 9f38484d220f months ago 202MB
hello-world latest fce289e99eb9 months ago .84kB
[root@localhost docker_test]# docker run f5620b92331c #运行image
docker so easy
[root@localhost docker_test]# cat Dockerfile
FROM scratch
ADD soeasy2 /
CMD ["/soeasy2"]
[root@localhost docker_test]# cat soeasy.c
#include<stdio.h> int main()
{
printf("docker so easy\n");
}
[root@localhost docker_test]#

把程序改成shell脚本,然后还是在linux kernel上构建base image,结果程序运行不起来,改成在centos image上构建,则运行成功。

[root@localhost docker_test]# vim soeasy.sh
[root@localhost docker_test]# cat soeasy.sh
#!/bin/bash
echo "docker so easy !"
[root@localhost docker_test]# vim Dockerfile
[root@localhost docker_test]# cat Dockerfile
FROM scratch
ADD soeasy.sh /
CMD ["/soeasy.sh"]
[root@localhost docker_test]# docker build -t bigni/test2 .
Sending build context to Docker daemon .8kB
Step / : FROM scratch
--->
Step / : ADD soeasy.sh /
---> 93d27c3e1b5b
Step / : CMD ["/soeasy.sh"]
---> Running in 4af6bd362099
Removing intermediate container 4af6bd362099
---> e2b5b08cc31c
Successfully built e2b5b08cc31c
Successfully tagged bigni/test2:latest
[root@localhost docker_test]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
bigni/test2 latest e2b5b08cc31c About a minute ago 36B
bigni/test1 latest f5620b92331c minutes ago 861kB
ubuntu 14.04 2c5e00d77a67 weeks ago 188MB
centos latest 9f38484d220f months ago 202MB
hello-world latest fce289e99eb9 months ago .84kB
[root@localhost docker_test]# docker run e2b5b08cc31c #运行image
standard_init_linux.go:: exec user process caused "no such file or directory"
[root@localhost docker_test]# vim Dockerfile
[root@localhost docker_test]# cat Dockerfile
FROM centos #改成centos
ADD soeasy.sh /
CMD ["/soeasy.sh"]
[root@localhost docker_test]# docker build -t bigni/test3 .
Sending build context to Docker daemon .8kB
Step / : FROM centos
---> 9f38484d220f
Step / : ADD soeasy.sh /
---> 9ae6ad56171a
Step / : CMD ["/soeasy.sh"]
---> Running in b53205a3eb75
Removing intermediate container b53205a3eb75
---> cfbfd0a29d1c
Successfully built cfbfd0a29d1c
Successfully tagged bigni/test3:latest
[root@localhost docker_test]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
bigni/test3 latest cfbfd0a29d1c seconds ago 202MB
bigni/test2 latest e2b5b08cc31c minutes ago 36B
bigni/test1 latest f5620b92331c minutes ago 861kB
ubuntu 14.04 2c5e00d77a67 weeks ago 188MB
centos latest 9f38484d220f months ago 202MB
hello-world latest fce289e99eb9 months ago .84kB
[root@localhost docker_test]# docker run cfbfd0a29d1c
docker so easy !
[root@localhost docker_test]#

docker--build base image的更多相关文章

  1. Docker build Dockerfile 构建镜像 - 二

    Dockerfile 制作镜像 https://hub.docker.com/ 搜索需要镜像: https://hub.docker.com/_/centos/ 官方示例: centos:6 1.这里 ...

  2. [Docker] Build a Simple Node.js Web Server with Docker

    Learn how to build a simple Node.js web server with Docker. In this lesson, we'll create a Dockerfil ...

  3. 【云计算】docker build如何支持参数化构建?

    docker 1.9.0版本之后,已经支持docker build参数化构建. docker 版本更新记录: github讨论: 参开资料: https://github.com/docker/doc ...

  4. docker: "build" requires 1 argument. See 'docker build --help'.

    http://bbs.csdn.net/topics/391040030 docker build  --tag="ouruser/sinatra:v3" -<Dockerf ...

  5. Jenkins Docker安装及Docker build step插件部署配置

    生产部署环境:A:192.168.1.2 B:192.168.1.3  两台服务器系统均是Centos 7.3 , Docker版本都1.12.6 Jenkins安装操作步骤: 1.在A服务器上使用命 ...

  6. 25.week4 docker build 也就是创建自己的image 上传image到dockerhub 从dockerhub下载images

    dado可以写你自己的名字 这个命令就会根据目录下的Dockerfile(固定用和这个名字)文件里面的内容 去下载并创建运行命令一步一步地 Setting up libxfixes3:amd64 (: ...

  7. docker build 指定dockerfile

    1. Dockerfile文件使用 docker build命令会根据Dockerfile文件及上下文构建新Docker镜像.构建上下文是指Dockerfile所在的本地路径或一个URL(Git仓库地 ...

  8. "docker build" requires exactly 1 argument(s).

    Docker 是怎么样的东西,这里就不说了,这里说说dockerfile创建容器时遇到的问题. 首先我想达到的目的很简单,就是用dockerfile去创建容器,步骤如下: 创建并编辑dockerfil ...

  9. 使用dockerfile文件创建镜像时docker build没有反应

    问题: 先 docker pull centos:7 拉取了一个官方的基础镜像,为后续创建jdk8镜像做准备,在创建如下的dockerfile文件 执行docker build -t jdk_8u19 ...

  10. gradle multiproject && docker build

    备注:   环境准备 : docker , gradle(使用wrapper,或者全局安装),测试环境使用mac 1. gradle 安装 brew install gradle   2. docke ...

随机推荐

  1. Vue 创建组件的两种方法

    地址:https://blog.csdn.net/cofecode/article/details/74634301 创建组件的两种方法 1.全局注册 2.局部注册 var child=Vue.ext ...

  2. 【转】C++ STL中常见容器的时间复杂度

    map, set, multimap, and multiset 上述四种容器采用红黑树实现,红黑树是平衡二叉树的一种.不同操作的时间复杂度近似为: 插入: O(logN) 查看:O(logN) 删除 ...

  3. A re-introduction to JavaScript (JS Tutorial) 转载自:https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript

    A re-introduction to JavaScript (JS Tutorial) Redirected from https://developer.mozilla.org/en-US/do ...

  4. MyBatis中XML 映射配置文件的简单介绍

    官网写的比较具体,可以查看以下的网站: http://www.mybatis.org/mybatis-3/zh/configuration.html 另外,实际用到标准的CRUD的操作和查询列表, & ...

  5. cnblogs添加打赏

    上图上真相 1.进入后台设置---文件 2.上传你的支付宝和微信收款码(注意图片格式为bmp格式) 2.还是上图的位置,选择设置选项,找到博客侧边栏公告(支持HTML代码)(支持JS代码) 3.将如下 ...

  6. Sublime Text 3 - there are no packages available for installation 解决方法

    解决方法: 1. 下载一个channel_v3.json ,  提取码: n2vc 2. 进入以下路径的设置界面 3. 添加代码 , 文件路径以各自下载保存路径为准 ( 重启sublime, 搞定 ! ...

  7. Window01

    1 <script src="~/jquery-easyui-1.5.5.2/jquery.min.js"></script> <link href= ...

  8. vue 前后端分离 接口及result规范 及drf安装使用方法

    接口 # 接口:url链接,通过向链接发送不同的类型请求与参数得到相应的响应数据​# 1.在视图层书写处理请求的 视图函数# 2.在路由层为视图函数配置 url链接 => 产生接口# 3.前台通 ...

  9. POJ A Plug for UNIX (最大流 建图)

    Description You are in charge of setting up the press room for the inaugural meeting of the United N ...

  10. 【dart学习】-- Dart之异步编程

    一,概述 编程中的代码执行,通常分为同步与异步两种. 同步:简单说,同步就是按照代码的编写顺序,从上到下依次执行,这也是最简单的我们最常接触的一种形式.但是同步代码的缺点也显而易见,如果其中某一行或几 ...