Add Docker Buildx

Signed-off-by: Kang HuaiShuai <khs1994@khs1994.com>
pull/432/head
Kang HuaiShuai 2019-11-05 21:50:05 +08:00
parent fadf84bb69
commit eb274b16f6
No known key found for this signature in database
GPG Key ID: 0A380828B1C243A7
8 changed files with 69 additions and 215 deletions

View File

@ -27,6 +27,6 @@ jobs:
PCIT_GIT_URL: github.com/docker-practice/vuepress
PCIT_KEEP_HISTORY: "1"
PCIT_LOCAL_DIR: .vuepress/dist
PCIT_MESSAGE: Sync from yeasy/docker-practice@${{github.sha}} by PCIT
PCIT_MESSAGE: Sync from yeasy/docker_practice@${{github.sha}} by PCIT
PCIT_TARGET_BRANCH: master
PCIT_USERNAME: khs1994

View File

@ -3,7 +3,7 @@ module.exports = {
base: '/',
themeConfig: {
docsRepo: 'yeasy/docker_practice',
docsDir: '/',
docsDir: '/vuepress',
editLinks: true,
nav: [{
text: ' Docker',
@ -186,9 +186,6 @@ module.exports = {
'/image/multistage-builds/',
'/image/multistage-builds/laravel',
'/image/manifest',
'/image/buildx_multi-arch-images',
'/image/buildkit',
'/image/buildx',
]
},{
title: "操作容器",
@ -262,6 +259,16 @@ module.exports = {
'security/summary',
],
},
{
title: "Docker Buildx",
collapsable: false,
children: [
"buildx/",
"buildx/buildkit",
"buildx/buildx",
"buildx/multi-arch-images",
],
},
{
title: "Etcd",
collapsable:false,

View File

@ -42,9 +42,6 @@
* [Dockerfile ](image/multistage-builds/README.md)
* [ Laravel ](image/multistage-builds/laravel.md)
* [ Docker ](image/manifest.md)
* [使 buildx Docker ](image/buildx_multi-arch-images.md)
* [Docker v18.09 使 BuildKit ](image/buildkit.md)
* [Docker v19.03 使 BuildKit ](image/buildx.md)
* [](image/other.md)
* [](image/internal.md)
* [](container/README.md)
@ -75,6 +72,10 @@
* [](advanced_network/example.md)
* [](advanced_network/config_file.md)
* [](advanced_network/ptp.md)
* [Docker Buildx](buildx/README.md)
* [BuildKit](buildx/buildkit.md)
* [使 buildx ](buildx/buildx.md)
* [使 buildx Docker ](buildx/multi-arch-images.md)
* [Docker Compose](compose/README.md)
* [](compose/introduction.md)
* [](compose/install.md)

5
buildx/README.md 100644
View File

@ -0,0 +1,5 @@
# Docker Buildx
Docker Buildx docker CLI docker [Moby BuildKit](buildkit.md) docker build
> Docker v19.03+

View File

@ -1,4 +1,4 @@
## 使 `BuildKit`
# 使 `BuildKit`
**BuildKit** https://github.com/moby/buildkit 开源。
@ -6,31 +6,11 @@
**docker-compose build BuildKit**
Docker CE 18.09 使 `BuildKit` `Dockerfile` Docker
## `Dockerfile`
### `BuildKit`
`BuildKit` 使 `Dockerfile`
`BuildKit` ****
LinuxmacOS
```bash
$ export DOCKER_BUILDKIT=1
```
Windows
```powershell
$ set $env:DOCKER_BUILDKIT=1
```
> 使
### `Dockerfile`
`BuildKit` 使
#### `RUN --mount=type=cache`
### `RUN --mount=type=cache`
使 `Go` `go mod``Node.js` `npm`
@ -112,7 +92,7 @@ RUN --mount=type=cache,target=/tmp/dist,from=builder,source=/app/dist \
|`from` | |
|`source` | |
#### `RUN --mount=type=bind`
### `RUN --mount=type=bind`
@ -122,7 +102,7 @@ RUN --mount=type=bind,from=php:alpine,source=/usr/local/bin/docker-php-entrypoin
cat /docker-php-entrypoint
```
#### `RUN --mount=type=tmpfs`
### `RUN --mount=type=tmpfs`
`tmpfs`
@ -132,9 +112,9 @@ RUN --mount=type=tmpfs,target=/temp \
mount | grep /temp
```
#### `RUN --mount=type=secret`
### `RUN --mount=type=secret`
()
```docker
# syntax = docker/dockerfile:experimental
@ -146,7 +126,7 @@ RUN --mount=type=secret,id=aws,target=/root/.aws/credentials \
$ docker build -t test --secret id=aws,src=$HOME/.aws/credentials .
```
#### `RUN --mount=type=ssh`
### `RUN --mount=type=ssh`
`ssh`
@ -165,14 +145,6 @@ $ ssh-add ~/.ssh/id_rsa
$ docker build -t test --ssh default=$SSH_AUTH_SOCK .
```
###
```bash
$ docker builder prune
```
###
##
* https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/experimental.md

33
buildx/buildx.md 100644
View File

@ -0,0 +1,33 @@
# 使 Buildx
## Buildx
`buildx` 使
Linux/macOS
```bash
$ export DOCKER_CLI_EXPERIMENTAL=enabled
```
Windows
```bash
$ set $env:DOCKER_CLI_EXPERIMENTAL=enabled
```
## 使
使 `docker buildx build`
```bash
$ docker buildx build .
[+] Building 8.4s (23/32)
=> ...
```
Buildx 使 [BuildKit ](buildkit.md) [Buildkit](buildkit.md)
##
* https://docs.docker.com/engine/reference/commandline/buildx/

View File

@ -1,26 +1,8 @@
# 使 buildx Docker
Docker 使使 [`$ docker manifest`](manifest.md)
Docker 使使 [`$ docker manifest`](../image/manifest.md)
Docker 19.03+ 使 `$ docker buildx build` 使 `BuildKit`
`--platform` Docker
##
`buildx` 使
Linux/macOS
```bash
$ export DOCKER_CLI_EXPERIMENTAL=enabled
```
Windows
```bash
$ set $env:DOCKER_CLI_EXPERIMENTAL=enabled
```
Docker 19.03+ 使 `$ docker buildx build` 使 `BuildKit` `--platform` Docker
## `builder`
@ -33,7 +15,9 @@ $ docker run --rm --privileged docker/binfmt:820fdd95a9972a5308930a2bdfb8573dd44
Docker `builder` `--platform` `builder`
```bash
$ docker buildx create --name mybuilder
# $ docker buildx create --name mybuilder
$ docker buildx create --name=mybuilder --driver docker-container --driver-opt image=dockerpracticesig/buildkit:master
$ docker buildx use mybuilder
```

View File

@ -1,148 +0,0 @@
## 使 `Buildx`
**BuildKit** https://github.com/moby/buildkit 开源。
**使Docker Hub Docker 18.09BuildKit 使使 BuildKit 使 Dockerfile Dockerfile.buildkit**
Docker CE 19.03+ 使 `BuildKit` `Dockerfile` Docker
### `Dockerfile`
`BuildKit` 使使 `BuildKit` **** 使 `$ docker buildx build` Docker
#### `RUN --mount=type=cache`
使 `Go` `go mod``Node.js` `npm`
`npm`
```docker
FROM node:alpine as builder
WORKDIR /app
COPY package.json /app/
RUN npm i --registry=https://registry.npm.taobao.org \
&& rm -rf ~/.npm
COPY src /app/src
RUN npm run build
FROM nginx:alpine
COPY --from=builder /app/dist /app/dist
```
使 `dist` `package.json` `RUN npm i && rm -rf ~/.npm`
**** `node_modules` `node_modules` `node_modules`
`BuildKit` `RUN --mount=type=cache`
```docker
FROM node:alpine as builder
WORKDIR /app
COPY package.json /app/
RUN --mount=type=cache,target=/app/node_modules,id=my_app_npm_module,sharing=locked \
--mount=type=cache,target=/root/.npm,id=npm_cache \
npm i --registry=https://registry.npm.taobao.org
COPY src /app/src
RUN --mount=type=cache,target=/app/node_modules,id=my_app_npm_module,sharing=locked \
# --mount=type=cache,target=/app/dist,id=my_app_dist,sharing=locked \
npm run build
FROM nginx:alpine
# COPY --from=builder /app/dist /app/dist
# from source 使 RUN
RUN --mount=type=cache,target=/tmp/dist,from=builder,source=/app/dist \
# --mount=type=cache,target/tmp/dist,from=my_app_dist,sharing=locked \
mkdir -p /app/dist && cp -r /tmp/dist/* /app/dist
```
`RUN` `id` `my_app_npm_module` `/app/node_modules`
`RUN` `node_modules` `node_modules`
`RUN` `from` `builder` `source`
`Dockerfile` `--mount=type=cache,...`
|Option |Description|
|---------------------|-----------|
|`id` | `id` 便|
|`target` () | |
|`ro`,`readonly` | |
|`sharing` | `shared` `private` `locked` `sharing` 使 `BuildKit` 使 `id``shared` `private` 使使`locked` 使|
|`from` | |
|`source` | |
#### `RUN --mount=type=bind`
```docker
RUN --mount=type=bind,from=php:alpine,source=/usr/local/bin/docker-php-entrypoint,target=/docker-php-entrypoint \
cat /docker-php-entrypoint
```
#### `RUN --mount=type=tmpfs`
`tmpfs`
```docker
RUN --mount=type=tmpfs,target=/temp \
mount | grep /temp
```
#### `RUN --mount=type=secret`
```docker
RUN --mount=type=secret,id=aws,target=/root/.aws/credentials \
cat /root/.aws/credentials
```
```bash
$ docker buildx build -t test --secret id=aws,src=$HOME/.aws/credentials .
```
#### `RUN --mount=type=ssh`
`ssh`
```docker
FROM alpine
RUN apk add --no-cache openssh-client
RUN mkdir -p -m 0700 ~/.ssh && ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
RUN --mount=type=ssh ssh git@gitlab.com | tee /hello
```
```bash
$ eval $(ssh-agent)
$ ssh-add ~/.ssh/id_rsa
(Input your passphrase here)
$ docker buildx build -t test --ssh default=$SSH_AUTH_SOCK .
```
###
```bash
$ docker builder prune
```
###
* https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/experimental.md