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 ...
随机推荐
- 启动与关闭WebService
[1]代码 /* * @brief: 启动WebServcie服务器 * @return:void */ void UPCSoftphoneClient::startWebService() { m_ ...
- python isinstance()方法的使用
1. 描述Python中的 isinstance() 函数,是Python中的一个内置函数,用来判断一个函数是否是一个已知的类型,类似 type(). 2. 语法isinstance(object,c ...
- 设计模式之Composite(组合)(转)
Composite定义: 将对象以树形结构组织起来,以达成"部分-整体" 的层次结构,使得客户端对单个对象和组合对象的使用具有一致性. Composite比较容易理解,想到Comp ...
- JDBC (29)
1.JDBC:就是一套API,由sun公司定义类或者定义的接口.(全称 java database connectivity:是Java访问数据库的标准规范),Java提供访问数据库规范称为JDBC, ...
- tensorflow学习6
g_w1 = tf.get_variable('g_w1', [z_dim, 3136], dtype=tf.float32, initializer=tf.truncated_normal_init ...
- idea下导入Tomcat源码
对于web开发者来说,如果明白了tomcat那对于开发还是后面的学习都是有很大益处的,但在网上看了很多的文章,总是没弄好,经历了很久才弄好了,写个文章记录下,希望也能帮助到其他人.下载Tomcat源码 ...
- cookie 和 session 的一些事 中间件
cookie 和 session cookie 1. 保存在浏览器上一组组键值对,服务器让浏览器进行设置. 2. 为什么要用cookie? HTTP协议是无状态.使用cookie保存状态. 3. dj ...
- 一起学习在 Ubuntu 上授予和移除 sudo 权限
如你所知,用户可以在 Ubuntu 系统上使用 sudo 权限执行任何管理任务.在 Linux 机器上创建新用户时,他们无法执行任何管理任务,直到你将其加入 sudo 组的成员.在这个简短的教程中,我 ...
- 浏览收藏夹 看到了hadoop3.0 的改动
大数据非常前卫的it网站 https://www.iteblog.com/archives/tag/hadoop/ 1.多个服务的默认端口被改变 在此之前,多个Hadoop服务的默认端口都属于Li ...
- OSI七层详解
OSI 七层模型通过七个层次化的结构模型使不同的系统不同的网络之间实现可靠的通讯,因此其最主要的功能就是帮助不同类型的主机实现数据传输 . 完成中继功能的节点通常称为中继系统.在OSI七层模型中,处于 ...