Images之base image
Create a base image
Most Dockerfiles start from a parent image.
If you need to completely control the contents of your image, you might need to create a base image instead.
Here’s the difference:
A parent image is the image that your image is based on. It refers to the contents of the
FROM
directive in the Dockerfile. Each subsequent declaration in the Dockerfile modifies this parent image. Most Dockerfiles start from a parent image, rather than a base image. However, the terms are sometimes used interchangeably.A base image either has no
FROM
line in its Dockerfile, or hasFROM scratch
.
This topic shows you several ways to create a base image. The specific process will depend heavily on the Linux distribution you want to package.
We have some examples below, and you are encouraged to submit pull requests to contribute new ones.
Create a full image using tar
In general, start with a working machine that is running the distribution you’d like to package as a parent image, though that is not required for some tools like Debian’s Debootstrap, which you can also use to build Ubuntu images.
It can be as simple as this to create an Ubuntu parent image:
$ sudo debootstrap xenial xenial > /dev/null
$ sudo tar -C xenial -c . | docker import - xenial a29c15f1bf7a $ docker run xenial cat /etc/lsb-release DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04 LTS"
Linux sudo命令以系统管理者的身份执行指令,也就是说,经由 sudo 所执行的指令就好像是 root 亲自执行。
使用权限:在 /etc/sudoers 中有出现的使用者。
debootstrap是debian/ubuntu下的一个工具,用来构建一套基本的系统(根文件系统)。生成的目录符合Linux文件系统标准(FHS),即包含了/boot、/etc、/bin、/usr等等目录,但它比发行版本的Linux体积小很多,当然功能也没那么强大,因此,只能说是“基本的系统”。
ubuntu默认没有安装debootstrap,安装十分简单,执行下列命令即可:
# sudo apt-get install debootstrap
使用也十分简单,命令格式为:
sudo debootstrap –arch [平台] [发行版本代号] [目录]
比如下面的命令
sudo debootstrap –arch i386 trusty /mnt
即是构建x86(32位)平台ubuntu最新发行版14.04(代号为trusty)的基本系统,存放到/mnt目录下。
There are more example scripts for creating parent images in the Docker GitHub Repo:
- BusyBox
- CentOS / Scientific Linux CERN (SLC) on Debian/Ubuntu or on CentOS/RHEL/SLC/etc.
- Debian / Ubuntu
Create a simple parent image using scratch
You can use Docker’s reserved, minimal image, scratch
, as a starting point for building containers.
Using the scratch
“image” signals to the build process that you want the next command in the Dockerfile
to be the first filesystem layer in your image.
While scratch
appears in Docker’s repository on the hub, you can’t pull it, run it, or tag any image with the name scratch
.
Instead, you can refer to it in your Dockerfile
.
For example, to create a minimal container using scratch
:
FROM scratch
ADD hello /
CMD ["/hello"]
Assuming you built the “hello” executable example by following the instructions at https://github.com/docker-library/hello-world/, and you compiled it with the -static
flag, you can build this Docker image using this docker build
command:
docker build --tag hello .
Don’t forget the .
character at the end, which sets the build context to the current directory.
Note: Because Docker for Mac and Docker for Windows use a Linux VM, you need a Linux binary, rather than a Mac or Windows binary. You can use a Docker container to build it:
$ docker run --rm -it -v $PWD:/build ubuntu:16.04 container# apt-get update && apt-get install build-essential
container# cd /build
container# gcc -o hello -static -nostartfiles hello.c
To run your new image, use the docker run
command:
docker run --rm hello
This example creates the hello-world image used in the tutorials. If you want to test it out, you can clone the image repo.
More resources
There are lots more resources available to help you write your Dockerfile
.
- There’s a complete guide to all the instructions available for use in a
Dockerfile
in the reference section. - To help you write a clear, readable, maintainable
Dockerfile
, we’ve also written aDockerfile
best practices guide. - If your goal is to create a new Official Repository, be sure to read up on Docker’s Official Repositories.
Images之base image的更多相关文章
- 小白解决CENTOS7错误:Cannot find a valid baseurl for repo: base/7/x86_6
刚入手的MacBook想着学点东西,本汪还是决定玩玩CentOS服务器,安装好了VirtualBox + CentOS. 打开一看,懵逼了!命令行! 行吧,先装个图形界面: $sudo yum gro ...
- 分布式系列文章——从ACID到CAP/BASE
事务 事务的定义: 事务(Transaction)是由一系列对系统中数据进行访问与更新的操作所组成的一个程序执行逻辑单元(Unit),狭义上的事务特指数据库事务. 事务的作用: 当多个应用程序并发访问 ...
- base的应用
------------父类 public class Person { public Person(string name,int age) { this.Na ...
- C# base 64图片编码解码
使用WinForm实现了图片base64编码解码的 效果图: 示例base 64编码字符串: /9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKD ...
- c++ builder 2010 错误 F1004 Internal compiler error at 0x9740d99 with base 0x9
今天遇到一个奇怪的问题,拷贝项目后,在修改,会出现F1004 Internal compiler error at 0x9740d99 with base 0x9 ,不管怎么改,删除改动,都没用,关闭 ...
- MVC中的BASE.ONACTIONEXECUTING(FILTERCONTEXT) 的作用
一句话,就是调用base.OnActionExecuting(filterContext)这个后,才会执行后续的ActionFilter,如果你确定只有一个,或是不想执行后续的话,那么可以不用调用该语 ...
- 安装CentOS7文字界面版后,无法联网,用yum安装软件提示 cannot find a valid baseurl for repo:base/7/x86_64 的解决方法
*无法联网的明显表现会有: 1.yum install出现 Error: cannot find a valid baseurl or repo:base 2.ping host会提示unknown ...
- 在ASP.NET Core中使用Angular2,以及与Angular2的Token base身份认证
注:下载本文提到的完整代码示例请访问:How to authorization Angular 2 app with asp.net core web api 在ASP.NET Core中使用Angu ...
- 在ASP.NET Core中实现一个Token base的身份认证
注:本文提到的代码示例下载地址> How to achieve a bearer token authentication and authorization in ASP.NET Core 在 ...
- SharePoint Claim base authentication EnsureUser 不带claim(i:0#.w|)user Failed
环境信息: 带有Form base authentication(FBA).Active Directory Federation Services(ADFS).以及windows Authentic ...
随机推荐
- Ngine X 完全开发指南 读书笔记-前言
一开始接触的编程语言是VF,那是一种可视化编程语言,所谓的可视化,就是运行结果能直接看得到的,非常直观,便于调试,适合刚刚接触编程的新人学习.当时学得懵懂,半知半解,就是感觉程序非常神奇,常常几句代码 ...
- Python 学习记录之----模块 paramiko
paramiko 一.安装 pip3.5 install paramiko pip3.5 install pycrypto # pycrypto,由于 paramiko 模块内部依赖pycrypto, ...
- Linux 系统管理命令
1,uanme 查看是什么系统 uname - r 查看系统内核版本 2 cat /proc/cpuinfo 查看cpu 信息 3 cat /proc/meminfo 查看内存信息 4 date 查看 ...
- 使用IntelljIDEA生成接口的类继承图及装饰器模式
类图生成方法 以一个装饰器模式实现数学运算的例子为例. 安装 Intellj Ultimate , lience server: http://xdouble.cn:8888/ 在类上右键点击 cla ...
- flask 在模板中渲染表单
在模板中渲染表单 为了能够在模板中渲染表单,我们需要把表单类实例传入模板.首先在视图函数里实例化表单类LoginForm,然后再render_template()函数中使用关键脑子参数form将表单实 ...
- tomcat1章1
package ex01.pyrmont; import java.net.Socket; import java.net.ServerSocket; import java.net.InetAddr ...
- Django框架----Form组件补充
一.Form类 创建Form类时,主要涉及到 [字段] 和 [插件],字段用于对用户请求数据的验证,插件用于自动生成HTML; 1.Django内置字段如下: 1 Field 2 required=T ...
- foreach嵌套遍历循环的问题
在foreach嵌套循环中使用==和equals的问题 JSONArray ja1= new JSONArray(); JSONArray ja2 = new JSONArray(); JSONObj ...
- 通过数组和枚举简化GPIO操作编码(转)
源: 通过数组和枚举简化GPIO操作编码
- JavaScript笔记 #05# 用Regex辅助生成文章目录
PS. 用来生成个人笔记的目录 1.输入:html文本 <h2>Notes</h2> <p>1.小标题1.正文正文正文</p> <div clas ...