docker--build base image
通过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的更多相关文章
- Docker build Dockerfile 构建镜像 - 二
Dockerfile 制作镜像 https://hub.docker.com/ 搜索需要镜像: https://hub.docker.com/_/centos/ 官方示例: centos:6 1.这里 ...
- [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 ...
- 【云计算】docker build如何支持参数化构建?
docker 1.9.0版本之后,已经支持docker build参数化构建. docker 版本更新记录: github讨论: 参开资料: https://github.com/docker/doc ...
- docker: "build" requires 1 argument. See 'docker build --help'.
http://bbs.csdn.net/topics/391040030 docker build --tag="ouruser/sinatra:v3" -<Dockerf ...
- 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服务器上使用命 ...
- 25.week4 docker build 也就是创建自己的image 上传image到dockerhub 从dockerhub下载images
dado可以写你自己的名字 这个命令就会根据目录下的Dockerfile(固定用和这个名字)文件里面的内容 去下载并创建运行命令一步一步地 Setting up libxfixes3:amd64 (: ...
- docker build 指定dockerfile
1. Dockerfile文件使用 docker build命令会根据Dockerfile文件及上下文构建新Docker镜像.构建上下文是指Dockerfile所在的本地路径或一个URL(Git仓库地 ...
- "docker build" requires exactly 1 argument(s).
Docker 是怎么样的东西,这里就不说了,这里说说dockerfile创建容器时遇到的问题. 首先我想达到的目的很简单,就是用dockerfile去创建容器,步骤如下: 创建并编辑dockerfil ...
- 使用dockerfile文件创建镜像时docker build没有反应
问题: 先 docker pull centos:7 拉取了一个官方的基础镜像,为后续创建jdk8镜像做准备,在创建如下的dockerfile文件 执行docker build -t jdk_8u19 ...
- gradle multiproject && docker build
备注: 环境准备 : docker , gradle(使用wrapper,或者全局安装),测试环境使用mac 1. gradle 安装 brew install gradle 2. docke ...
随机推荐
- JavaFx开发桌面软件
JavaFx开发桌面软件 */--> code {color: #FF0000} pre.src {background-color: #002b36; color: #839496;} Jav ...
- docker--shell和Exec格式
shell格式 RUN apt-get install -y vim CMD echo "docker so easy" ENTRYPOINT echo "docker ...
- go读写文本文件
一.文件读取 1. 将整个文件读取到内存中 package main import ( "flag" "fmt" "io/ioutil" ) ...
- Groovy学习:第一章 用Groovy简化Java代码
1. Groovy的安装 目前Groovy的最新版本为2.1.2版,下载地址为:http://groovy.codehaus.org/Download下载后解压groovy-binary-2.1.2. ...
- 一、spring的基本认识
Spring的认识 Spring是一个开放源代码的设计层面框架,它解决的是业务逻辑层和其他各层的松耦合问题,因此它将面向接口的编程思想贯穿整个系统应用 Spring是于2003 年兴起的一个轻量级的J ...
- java 多线程 线程安全及非线程安全的集合对象
一.概念: 线程安全:就是当多线程访问时,采用了加锁的机制:即当一个线程访问该类的某个数据时,会对这个数据进行保护,其他线程不能对其访问,直到该线程读取完之后,其他线程才可以使用.防止出现数据不一致或 ...
- nginx的虚拟主机和反向代理和一些技巧应用
前言 nginx是什么,一般用来做反向代理,也可以用来放静态htnl等文件..当然代理tcp协议也没啥问题,但做好是别用哈.性能不咋样. 虚拟主机 什么是虚拟主机? 个人理解,比如一台主机装一个ngi ...
- 【转载】将本地图片转成base64
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- windows 安装 jenkins笔记
Jenkins 所有镜像列表: http://mirrors.jenkins-ci.org/status.html 可在镜像网站上下载安装文件,比官方下载快些 jenkins 官网地址: https: ...
- JavaSE---main方法解读
1.概述 1.1 java程序入口:main方法 public static void main(String[] args){} a,public:java类由JVM调用,为了让JVM自由调用mai ...