mirror of
https://github.com/yeasy/docker_practice.git
synced 2026-03-26 03:35:31 +00:00
Remove blank lines after code block markers
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
FCC 是 Fedora CoreOS Configuration (Fedora CoreOS 配置) 的简称。
|
||||
|
||||
```yaml
|
||||
|
||||
## example.fcc
|
||||
|
||||
variant: fcos
|
||||
@@ -20,7 +19,6 @@ passwd:
|
||||
ssh_authorized_keys:
|
||||
- ssh-rsa AAAA...
|
||||
```
|
||||
|
||||
将 `ssh-rsa AAAA...` 替换为自己的 SSH 公钥 (位于 `~/.ssh/id_rsa.pub`)。
|
||||
|
||||
### 17.2.3 转换 FCC 为 Ignition
|
||||
@@ -28,7 +26,6 @@ passwd:
|
||||
```bash
|
||||
$ docker run -i --rm quay.io/coreos/fcct:v0.5.0 --pretty --strict < example.fcc > example.ign
|
||||
```
|
||||
|
||||
### 17.2.4 挂载 ISO 启动虚拟机并安装
|
||||
|
||||
> 虚拟机需要分配 3GB 以上内存,否则会无法启动。
|
||||
@@ -38,7 +35,6 @@ $ docker run -i --rm quay.io/coreos/fcct:v0.5.0 --pretty --strict < example.fcc
|
||||
```bash
|
||||
$ sudo coreos-installer install /dev/sda --ignition-file example.ign
|
||||
```
|
||||
|
||||
安装之后重新启动即可使用。
|
||||
|
||||
### 17.2.5 使用
|
||||
|
||||
@@ -22,7 +22,6 @@ Podman 支持多种操作系统,安装过程也相对简单。
|
||||
```bash
|
||||
$ sudo yum -y install podman
|
||||
```
|
||||
|
||||
#### macOS
|
||||
|
||||
macOS 上需要安装 Podman Desktop 或通过 Homebrew 安装:
|
||||
@@ -32,7 +31,6 @@ $ brew install podman
|
||||
$ podman machine init
|
||||
$ podman machine start
|
||||
```
|
||||
|
||||
### 17.3.3 基本使用
|
||||
|
||||
`podman` 的命令行几乎与 `docker` 完全兼容,大多数情况下,你只需将 `docker` 替换为 `podman` 即可。
|
||||
@@ -40,30 +38,25 @@ $ podman machine start
|
||||
#### 运行容器
|
||||
|
||||
```bash
|
||||
|
||||
## $ docker run -d -p 80:80 nginx:alpine
|
||||
|
||||
$ podman run -d -p 80:80 nginx:alpine
|
||||
```
|
||||
|
||||
#### 列出容器
|
||||
|
||||
```bash
|
||||
$ podman ps
|
||||
```
|
||||
|
||||
#### 构建镜像
|
||||
|
||||
```bash
|
||||
$ podman build -t myimage .
|
||||
```
|
||||
|
||||
### 17.3.4 Pods 的概念
|
||||
|
||||
与 Docker 不同,Podman 支持“Pod”的概念 (类似于 Kubernetes 的 Pod),允许你在同一个网络命名空间中运行多个容器。
|
||||
|
||||
```bash
|
||||
|
||||
## 创建一个 Pod
|
||||
|
||||
$ podman pod create --name mypod -p 8080:80
|
||||
@@ -72,7 +65,6 @@ $ podman pod create --name mypod -p 8080:80
|
||||
|
||||
$ podman run -d --pod mypod --name webbing nginx
|
||||
```
|
||||
|
||||
### 17.3.5 迁移到 Podman
|
||||
|
||||
如果你习惯使用 `docker` 命令,可以简单地设置别名:
|
||||
@@ -80,13 +72,11 @@ $ podman run -d --pod mypod --name webbing nginx
|
||||
```bash
|
||||
$ alias docker=podman
|
||||
```
|
||||
|
||||
#### Systemd 集成
|
||||
|
||||
Podman 可以生成 systemd 单元文件,让容器像普通系统服务一样管理。
|
||||
|
||||
```bash
|
||||
|
||||
## 创建容器
|
||||
|
||||
$ podman run -d --name myweb -p 8080:80 nginx
|
||||
@@ -99,7 +89,6 @@ $ podman generate systemd --name myweb --files --new
|
||||
|
||||
$ systemctl --user enable --now container-myweb.service
|
||||
```
|
||||
|
||||
#### Podman Compose
|
||||
|
||||
虽然 Podman 兼容 Docker Compose,但在某些场景下你可能需要明确使用 `podman-compose`。
|
||||
|
||||
@@ -24,14 +24,12 @@ Buildah 由 Red Hat 主导开发,通常和 Podman、Skopeo 一起使用,被
|
||||
```bash
|
||||
$ sudo dnf install -y buildah
|
||||
```
|
||||
|
||||
以 Ubuntu/Debian 为例(需引入官方源后):
|
||||
|
||||
```bash
|
||||
$ sudo apt-get update
|
||||
$ sudo apt-get -y install buildah
|
||||
```
|
||||
|
||||
### 基础用法示例
|
||||
|
||||
#### 1. 从现有的 Dockerfile 构建镜像
|
||||
@@ -41,7 +39,6 @@ Buildah 最常见的用法就是像 Docker 一样根据 `Dockerfile` 来构建
|
||||
```bash
|
||||
$ buildah bud -t my-app:latest .
|
||||
```
|
||||
|
||||
可以看到在这点上,它与 `docker build` 的体验完全一致。
|
||||
|
||||
#### 2. 交互式从空镜像开始构建
|
||||
@@ -49,7 +46,6 @@ $ buildah bud -t my-app:latest .
|
||||
除了使用 Dockerfile,Buildah 最强大的功能来自于它的交互式和脚本化构建机制。我们可以从一个极简的镜像(或基础镜像)开始构建:
|
||||
|
||||
```bash
|
||||
|
||||
# 获取一个基础镜像
|
||||
$ container=$(buildah from alpine:latest)
|
||||
|
||||
@@ -71,7 +67,6 @@ $ buildah commit $container my-hello-image:latest
|
||||
$ buildah unmount $container
|
||||
$ buildah rm $container
|
||||
```
|
||||
|
||||
这种模式在自动化流水线中极为有用,因为我们可以将上述过程编写成标准的 bash 脚本,无需为了构建镜像而撰写只在其独立语法中运行的 Dockerfile 指令。
|
||||
|
||||
#### 3. 查看和推送镜像
|
||||
@@ -79,12 +74,10 @@ $ buildah rm $container
|
||||
通过 `buildah images` 可以查看当前环境中的镜像。推送镜像到外部 Registry 也十分安全方便:
|
||||
|
||||
```bash
|
||||
|
||||
# 查看本地构建的镜像
|
||||
$ buildah images
|
||||
|
||||
# 推送镜像到 Docker Hub(注意需要先登录)
|
||||
$ buildah push my-hello-image:latest docker://docker.io/username/my-hello-image:latest
|
||||
```
|
||||
|
||||
结合其无需特权和灵活脚本的优点,Buildah 正变得越来越受到构建和分发 OCI 镜像的用户喜爱。
|
||||
|
||||
@@ -24,20 +24,17 @@ Skopeo 最大的特点是其可以在“不将镜像拉取到本地”的情况
|
||||
```bash
|
||||
$ sudo dnf install -y skopeo
|
||||
```
|
||||
|
||||
在 Ubuntu/Debian 中:
|
||||
|
||||
```bash
|
||||
$ sudo apt-get update
|
||||
$ sudo apt-get -y install skopeo
|
||||
```
|
||||
|
||||
如果是 macOS 环境,可以通过 Homebrew 安装:
|
||||
|
||||
```bash
|
||||
$ brew install skopeo
|
||||
```
|
||||
|
||||
### 基础用法示例
|
||||
|
||||
#### 1. 远程检查镜像
|
||||
@@ -47,7 +44,6 @@ $ brew install skopeo
|
||||
```bash
|
||||
$ skopeo inspect docker://docker.io/library/alpine:latest
|
||||
```
|
||||
|
||||
这个命令会返回一段 JSON 格式的数据,其中包含了诸如镜像摘要(Digest)、创建时间、架构(Architecture)、标签(Tags)等丰富信息。在自动化的工具和系统审查环境中,这是一个不可或缺的利器。
|
||||
|
||||
#### 2. 同步与复制镜像
|
||||
@@ -59,13 +55,11 @@ $ skopeo inspect docker://docker.io/library/alpine:latest
|
||||
```bash
|
||||
$ skopeo copy docker://docker.io/library/alpine:latest docker://registry.example.com/library/alpine:latest
|
||||
```
|
||||
|
||||
又或者,你可以将远程镜像拉取到本地,只为了检查其拆解后的格式,比如将镜像解压到本地某个目录下以 OCI 规范存放:
|
||||
|
||||
```bash
|
||||
$ skopeo copy docker://docker.io/library/alpine:latest oci:alpine-oci
|
||||
```
|
||||
|
||||
如果我们要将本地的某个目录下的打包好的镜像再次推向 Registry 或转换为其它存储类型也是完全支持的,诸如:
|
||||
- `docker://` 远端 Registry
|
||||
- `docker-archive:` / `docker-daemon:` Docker 对应的归档文件或本地守护进程
|
||||
|
||||
@@ -56,7 +56,6 @@ Kubernetes 作为一个容器编排系统,为了屏蔽底层不同容器运行
|
||||
安装完 containerd 和 nerdctl 后,你可以体验到几乎与 Docker 完全一致的命令行:
|
||||
|
||||
```bash
|
||||
|
||||
# 启动一个 nginx 容器
|
||||
$ nerdctl run -d -p 8080:80 --name my-nginx nginx:alpine
|
||||
|
||||
@@ -66,5 +65,4 @@ $ nerdctl ps
|
||||
# 查看本地镜像
|
||||
$ nerdctl images
|
||||
```
|
||||
|
||||
对于那些希望在生产服务器上剥离 Docker 庞大体积,但又想要保留类似 Docker 方便的命令行体验的用户,`containerd` + `nerdctl` 是一个极佳的组合。
|
||||
|
||||
Reference in New Issue
Block a user