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 has FROM 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:

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.

  

Images之base image的更多相关文章

  1. 小白解决CENTOS7错误:Cannot find a valid baseurl for repo: base/7/x86_6

    刚入手的MacBook想着学点东西,本汪还是决定玩玩CentOS服务器,安装好了VirtualBox + CentOS. 打开一看,懵逼了!命令行! 行吧,先装个图形界面: $sudo yum gro ...

  2. 分布式系列文章——从ACID到CAP/BASE

    事务 事务的定义: 事务(Transaction)是由一系列对系统中数据进行访问与更新的操作所组成的一个程序执行逻辑单元(Unit),狭义上的事务特指数据库事务. 事务的作用: 当多个应用程序并发访问 ...

  3. base的应用

    ------------父类   public class Person   {       public Person(string name,int age)    {       this.Na ...

  4. C# base 64图片编码解码

    使用WinForm实现了图片base64编码解码的 效果图: 示例base 64编码字符串: /9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKD ...

  5. c++ builder 2010 错误 F1004 Internal compiler error at 0x9740d99 with base 0x9

    今天遇到一个奇怪的问题,拷贝项目后,在修改,会出现F1004 Internal compiler error at 0x9740d99 with base 0x9 ,不管怎么改,删除改动,都没用,关闭 ...

  6. MVC中的BASE.ONACTIONEXECUTING(FILTERCONTEXT) 的作用

    一句话,就是调用base.OnActionExecuting(filterContext)这个后,才会执行后续的ActionFilter,如果你确定只有一个,或是不想执行后续的话,那么可以不用调用该语 ...

  7. 安装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 ...

  8. 在ASP.NET Core中使用Angular2,以及与Angular2的Token base身份认证

    注:下载本文提到的完整代码示例请访问:How to authorization Angular 2 app with asp.net core web api 在ASP.NET Core中使用Angu ...

  9. 在ASP.NET Core中实现一个Token base的身份认证

    注:本文提到的代码示例下载地址> How to achieve a bearer token authentication and authorization in ASP.NET Core 在 ...

  10. SharePoint Claim base authentication EnsureUser 不带claim(i:0#.w|)user Failed

    环境信息: 带有Form base authentication(FBA).Active Directory Federation Services(ADFS).以及windows Authentic ...

随机推荐

  1. codeoforces 975B Mancala

    题意: 一个游戏,有14个洞,每个洞中开始有若干个球或者没有球. 每一步的操作,是将一个洞中的所有球取出,再逆时针放一个球到它的后一个洞,后两个洞,后三个洞....如果当前放的是最后一个,那么下一个又 ...

  2. 定时调度任务quartz

    依赖 <!-- quartz --> <dependency> <groupId>org.quartz-scheduler</groupId> < ...

  3. spring 源码导入eclipse(sts)

    一. 准备工作 1.下载安装sts(springsource推荐使用) 下载地址: http://www.springsource.org/downloads/sts-ggts 2.下载安装gradl ...

  4. 20165215 2017-2018-2 《Java程序设计》第7周学习总结

    20165215 2017-2018-2 <Java程序设计>第七周学习总结 教材学习内容总结 chapter11 下载安装MySQL服务器 启动MySQL数据库服务器 在bin子目录中, ...

  5. Python数据类型深入学习之数字

    一. 数字常量 1. 下面来看看Python的数字常量中都要哪些类型: 数字 常量 129,-89,0 一般整数 9999848499999L,4594646469l 长整型数(无限大小) 1.232 ...

  6. Bluetooth协议栈学习之SDP

    服务发现协议(SDP或Bluetooth SDP)在蓝牙协议栈中对蓝牙环境中的应用程序有特殊的含意,发现哪个服务是可用的和确定这些可用服务的特征.SDP定义了bluetooth client发现可用b ...

  7. unittest和pytest的区别

    一.用例编写规则 1.unittest提供了test cases.test suites.test fixtures.test runner相关的类,让测试更加明确.方便.可控.使用unittest编 ...

  8. Django框架----Form组件

    Form介绍 我们之前在HTML页面中利用form表单向后端提交数据时,都会写一些获取用户输入的标签并且用form标签把它们包起来. 与此同时我们在好多场景下都需要对用户的输入做校验,比如校验用户是否 ...

  9. 怎样从外网访问内网WampServer?

    本地安装了一个WampServer,只能在局域网内访问,怎样从外网也能访问到本地的WampServer呢?本文将介绍具体的实现步骤. 准备工作 安装并启动WampServer 默认安装的WampSer ...

  10. 使用Holer将本地端口映射到公网

    What is holer Holerexposes local servers behind NATs and firewalls to the public internet over secur ...