Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu.Wang 2018-05-14 10:57:32 +08:00
commit d90001015a
3 changed files with 137 additions and 137 deletions

View File

@ -1,3 +1,5 @@
translating----geekpi
College student reflects on getting started in open source
======

View File

@ -1,137 +0,0 @@
translating---geekpi
How to build container images with Buildah
======
![](https://fedoramagazine.org/wp-content/uploads/2018/04/buildah-816x345.png)
Project Atomic, through their efforts on the Open Container Initiative (OCI), have created a great tool called [Buildah][1]. Buildah helps with creating, building and updating container images supporting Docker formatted images as well as OCI compliant images.
Buildah handles building container images without the need to have a full container runtime or daemon installed. This particularly shines for setting up a continuous integration and continuous delivery pipeline for building containers.
Buildah makes the containers filesystem directly available to the build host. Meaning that the build tooling is available on the host and not needed in the container image, keeping the build faster and the image smaller and safer. There are Buildah packages for CentOS, Fedora, and Debian.
### Installing Buildah
Since Fedora 26 Buildah can be installed using dnf.
```
$ sudo dnf install buildah -y
```
The current version of buildah is 0.16, which can be displayed by the following command.
```
$ buildah --version
```
### Basic commands
The first step needed to build a container image is to get a base image, this is done by the FROM statement in a Dockerfile. Buildah does handle this in a similar way.
```
$ sudo buildah from fedora
```
This command pulls the Fedora based image and stores it on the host. It is possible to inspect the images available on the host, by running the following.
```
$ sudo buildah images
IMAGE ID IMAGE NAME CREATED AT SIZE
9110ae7f579f docker.io/library/fedora:latest Mar 7, 2018 20:51 234.7 MB
```
After pulling the base image, a running container instance of this image is available, this is a “working-container”.
The following command displays the running containers.
```
$ sudo buildah containers
CONTAINER ID BUILDER IMAGE ID IMAGE NAME
CONTAINER NAME
6112db586ab9 * 9110ae7f579f docker.io/library/fedora:latest fedora-working-container
```
Buildah also provides a very useful command to stop and remove all the containers that are currently running.
```
$ sudo buildah rm --all
```
The full list of command is available using the help option.
```
$ buildah --help
```
### Building an Apache web server container image
Lets see how to use Buildah to install an Apache web server on a Fedora base image, then copy a custom index.html to be served by the server.
First lets create the custom index.html.
```
$ echo "Hello Fedora Magazine !!!" > index.html
```
Then install the httpd package inside the running container.
```
$ sudo buildah from fedora
$ sudo buildah run fedora-working-container dnf install httpd -y
```
Lets copy index.html to /var/www/html/.
```
$ sudo buildah copy fedora-working-container index.html /var/www/html/index.html
```
Then configure the container entrypoint to start httpd.
```
$ sudo buildah config --entrypoint "/usr/sbin/httpd -DFOREGROUND" fedora-working-container
```
Now to make the “working-container” available, the commit command saves the container to an image.
```
$ sudo buildah commit fedora-working-container hello-fedora-magazine
```
The hello-fedora-magazine image is now available, and can be pushed to a registry to be used.
```
$ sudo buildah images
IMAGE ID IMAGE NAME CREATED
AT SIZE
9110ae7f579f docker.io/library/fedora:latest
Mar 7, 2018 22:51 234.7 MB
49bd5ec5be71 docker.io/library/hello-fedora-magazine:latest
Apr 27, 2018 11:01 427.7 MB
```
It is also possible to use Buildah to test this image by running the following steps.
```
$ sudo buildah from --name=hello-magazine docker.io/library/hello-fedora-magazine
$ sudo buildah run hello-magazine
```
Accessing <http://localhost> will display “Hello Fedora Magazine !!!“
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/daemon-less-container-management-buildah/
作者:[Ashutosh Sudhakar Bhakare][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://fedoramagazine.org/author/ashutoshbhakare/
[1]:https://github.com/projectatomic/buildah

View File

@ -0,0 +1,135 @@
如何使用 Buildah 构建容器镜像
======
![](https://fedoramagazine.org/wp-content/uploads/2018/04/buildah-816x345.png)
Project Atomic 通过他们在 Open Container InitiativeOCI上的努力创造了一个名为 [Buildah][1] 的伟大工具。Buildah 能帮助创建、构建和更新,它支持 Docker 容器镜像以及 OCI 兼容镜像。
Buildah 处理构建容器镜像时无需安装完整的容器运行时或守护进程。这对建立容器的持续集成和持续交付管道尤其有用。
Buildah 使容器的文件系统可以直接供构建主机使用。这意味着构建工具在主机上可用并且在容器镜像中不需要从而使构建更快速镜像更小更安全。Buildah 有 CentOS、Fedora 和 Debian 的软件包。
### 安装 Buildah
从 Fedora 26 开始 Buildah 可以使用 dnf 进行安装。
```
$ sudo dnf install buildah -y
```
buildah 的当前版本为 0.16,可以通过以下命令显示。
```
$ buildah --version
```
### 基本命令
构建容器镜像的第一步是获取基础镜像,这是通过 Dockerfile 中的 FROM 语句完成的。Buildah 以类似的方式处理这个。
```
$ sudo buildah from fedora
```
该命令将拉取 Fedora 的基础镜像并存储在主机上。通过执行以下操作可以检查主机上可用的镜像。
```
$ sudo buildah images
IMAGE ID IMAGE NAME CREATED AT SIZE
9110ae7f579f docker.io/library/fedora:latest Mar 7, 2018 20:51 234.7 MB
```
在拉取基础镜像后,有一个该镜像的运行容器实例,这是一个“工作容器”。
以下命令显示正在运行的容器。
```
$ sudo buildah containers
CONTAINER ID BUILDER IMAGE ID IMAGE NAME
CONTAINER NAME
6112db586ab9 * 9110ae7f579f docker.io/library/fedora:latest fedora-working-container
```
Buildah 还提供了一个非常有用的命令来停止和删除当前正在运行的所有容器。
```
$ sudo buildah rm --all
```
完整的命令列表可以使用 -help 选项。
```
$ buildah --help
```
### 构建一个 Apache Web 服务器容器镜像
让我们看看如何使用 Buildah 在 Fedora 基础镜像上安装 Apache Web 服务器,然后复制一个可供服务的自定义 index.html。
首先让我们创建自定义的 index.html。
```
$ echo "Hello Fedora Magazine !!!" > index.html
```
然后在正在运行的容器中安装 httpd 包。
```
$ sudo buildah from fedora
$ sudo buildah run fedora-working-container dnf install httpd -y
```
让我们将 index.html 复制到 /var/www/html/。
```
$ sudo buildah copy fedora-working-container index.html /var/www/html/index.html
```
然后配置容器入口点以启动 httpd。
```
$ sudo buildah config --entrypoint "/usr/sbin/httpd -DFOREGROUND" fedora-working-container
```
现在为了使“工作容器”可用commit 命令将容器保存到镜像。
```
$ sudo buildah commit fedora-working-container hello-fedora-magazine
```
hello-fedora-magazine 镜像现在可用,并且可以推送到仓库以供使用。
```
$ sudo buildah images
IMAGE ID IMAGE NAME CREATED
AT SIZE
9110ae7f579f docker.io/library/fedora:latest
Mar 7, 2018 22:51 234.7 MB
49bd5ec5be71 docker.io/library/hello-fedora-magazine:latest
Apr 27, 2018 11:01 427.7 MB
```
通过运行以下步骤,还可以使用 Buildah 来测试此镜像。
```
$ sudo buildah from --name=hello-magazine docker.io/library/hello-fedora-magazine
$ sudo buildah run hello-magazine
```
访问 <http://localhost> 将显示 “Hello Fedora Magazine !!!”
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/daemon-less-container-management-buildah/
作者:[Ashutosh Sudhakar Bhakare][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://fedoramagazine.org/author/ashutoshbhakare/
[1]:https://github.com/projectatomic/buildah