通过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. 附: K8S入门系列之集群健康检查

    Kubernetes的kubectl常用命令 1. pod操作 # 获取所有的pod kubectl get pods --all-namespaces -o wide # 使用yaml文件创建pod ...

  2. 44.Linked List Cycle II(环的入口节点)

    Level:   Medium 题目描述: Given a linked list, return the node where the cycle begins. If there is no cy ...

  3. win10下RabbitMQ的安装和配置

    在win10环境下安装RabbitMQ的步骤 第一步:下载并安装erlang 原因:RabbitMQ服务端代码是使用并发式语言Erlang编写的,安装Rabbit MQ的前提是安装Erlang. 下载 ...

  4. 怎么更新 WIN10里的SMBv1协议

    控制面板 ---启用或关闭Windows功能---打开SMBv1服务:

  5. 使用Python+Qt时解决QTreeWidget中的内容超出边界后自动隐藏的问题

    问题: 默认情况下,内容超出边界后会自动省略,以...代替,而且无法出现水平滚动条 解决方法: 把VerticalScrollBar和HorizontalScrollBar的值都设为ScrollBar ...

  6. 转载 Log4j2在WEB项目中配置

    最近决定在新WEB项目中使用新的日志系统Log4j2. 官方介绍和学习文档网址为http://logging.apache.org/log4j/2.x/ 首先在WEB项目中引入以下几个jar包: ① ...

  7. 【leetcode】986. Interval List Intersections

    题目如下: Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted ...

  8. c++11的构造函数继承

    https://en.cppreference.com/w/cpp/language/using_declaration 在[Inheriting constructors]这一节. 其实叫做"基类的 ...

  9. yii2 后台前后台 前后台登陆、退出问题

    问题描述:我使用前后台分离 配置如下: 'user' => [ 'identityClass' => 'app\models\User', 'enableAutoLogin' => ...

  10. 3D打印切片软件Cura及CuraEngine原理分析

    引言 年初开始进入3D打印行业,受命以Cura为基础,研发一款自主的3D打印切片软件. 自主研发要取其长处,补其不足,首先自然是要搞清楚Cura到底做了什么,读Cura的代码是必需的.我一向都觉得比起 ...