Compare commits
51 Commits
cc6510d0b2
...
english
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc0f1223a0 | ||
|
|
dad6b9f022 | ||
|
|
e049bf2741 | ||
|
|
e59b50b43b | ||
|
|
8888612782 | ||
|
|
aa431b9a79 | ||
|
|
500325b7c8 | ||
|
|
cba52767b7 | ||
|
|
dc3a1c92d5 | ||
|
|
2ae8979c5c | ||
|
|
41633ecf24 | ||
|
|
48bcb9470b | ||
|
|
d47f565e83 | ||
|
|
b54b5b0a0f | ||
|
|
6c8e710c53 | ||
|
|
27f495466d | ||
|
|
cc8c36b1a3 | ||
|
|
f4e21a70b1 | ||
|
|
a2cdfdfded | ||
|
|
3b0f3c0cb2 | ||
|
|
37581d3016 | ||
|
|
49fd7a94da | ||
|
|
0a8887957e | ||
|
|
3356aa627f | ||
|
|
f20936e0af | ||
|
|
247bbcdc59 | ||
|
|
efdc3de9e0 | ||
|
|
42bb1bd1a1 | ||
|
|
c5935658bb | ||
|
|
bc6d6c85e3 | ||
|
|
ff7d5976a7 | ||
|
|
3a3939686c | ||
|
|
1a966e2979 | ||
|
|
a7d3a8291f | ||
|
|
6f9a5cca90 | ||
|
|
a5b762c2ce | ||
|
|
3cdde73798 | ||
|
|
e9213ea244 | ||
|
|
2b6e28d6a9 | ||
|
|
0699e96e36 | ||
|
|
2069a436e1 | ||
|
|
7b808e4d3d | ||
|
|
a071218f77 | ||
|
|
c9ebe3da2b | ||
|
|
941e01623c | ||
|
|
d00b6e1911 | ||
|
|
3b959abf68 | ||
|
|
8280d40922 | ||
|
|
1c1d81bd49 | ||
|
|
4f48fc2066 | ||
|
|
3974a2de24 |
@@ -1,22 +0,0 @@
|
||||
// https://code.visualstudio.com/docs/remote/devcontainerjson-reference
|
||||
|
||||
{
|
||||
"image": "yeasy/docker_practice:latest",
|
||||
"mounts": [
|
||||
"source=dp-code-remote-cache,target=/root/.vscode-server,type=volume"
|
||||
],
|
||||
"settings": {
|
||||
"terminal.integrated.shell.linux": "/bin/sh"
|
||||
},
|
||||
"forwardPorts": [
|
||||
4000
|
||||
],
|
||||
"runArgs": [
|
||||
"--cap-add=SYS_ADMIN"
|
||||
],
|
||||
"postStartCommand": [
|
||||
"sh",
|
||||
"-cx",
|
||||
"pwd ; cd /workspaces/docker_practice ; mkdir -p ${PWD}/node_modules; mkdir -p ${PWD}/_book; mount --bind /srv/gitbook/node_modules ${PWD}/node_modules ; mount --bind /mnt ${PWD}/_book"
|
||||
]
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
echo
|
||||
echo
|
||||
echo "Please open your browser: 127.0.0.1:4000"
|
||||
echo
|
||||
echo "欢迎加入 QQ 群:【 145983035 】 分享 Docker 资源,交流 Docker 技术"
|
||||
echo
|
||||
echo
|
||||
|
||||
exec nginx -g "daemon off;"
|
||||
|
Before Width: | Height: | Size: 445 KiB |
|
Before Width: | Height: | Size: 54 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 704 KiB |
|
Before Width: | Height: | Size: 5.2 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 118 KiB |
|
Before Width: | Height: | Size: 77 KiB |
|
Before Width: | Height: | Size: 101 KiB |
|
Before Width: | Height: | Size: 660 KiB |
|
Before Width: | Height: | Size: 291 KiB |
|
Before Width: | Height: | Size: 101 KiB |
|
Before Width: | Height: | Size: 88 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 217 KiB |
|
Before Width: | Height: | Size: 67 KiB |
|
Before Width: | Height: | Size: 153 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 8.2 KiB |
|
Before Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 136 KiB |
39
.github/CODEOWNERS
vendored
@@ -1,39 +0,0 @@
|
||||
* @yeasy @khs1994
|
||||
/.github/* @khs1994
|
||||
/.travis/* @khs1994
|
||||
/.vuepress/* @khs1994
|
||||
/advanced_network/* @yeasy @khs1994
|
||||
/appendix/* @yeasy @khs1994
|
||||
/archive/* @khs1994
|
||||
/basic_concept/* @yeasy @khs1994
|
||||
/buildx/* @khs1994
|
||||
/cases/* @yeasy @khs1994
|
||||
/cloud/* @khs1994
|
||||
/compose/* @yeasy @khs1994
|
||||
/container/* @yeasy @khs1994
|
||||
/coreos/* @khs1994
|
||||
/data_management/* @khs1994
|
||||
/etcd/* @khs1994
|
||||
/IDE/* @khs1994
|
||||
/image/* @yeasy @khs1994
|
||||
/install/* @khs1994
|
||||
/introduction/* @yeasy @khs1994
|
||||
/kubernetes/* @yeasy @khs1994
|
||||
/network/* @yeasy @khs1994
|
||||
/opensource/* @khs1994
|
||||
/repository/* @khs1994
|
||||
/security/* @yeasy @khs1994
|
||||
/underly/* @yeasy @khs1994
|
||||
/.drone.yml @khs1994
|
||||
/.editorconfig/ @khs1994
|
||||
/.gitattributes @khs1994
|
||||
/.gitignore @khs1994
|
||||
/_config.yml @yeasy @khs1994
|
||||
/book.json @yeasy @khs1994
|
||||
/CHANGELOG.md @yeasy @khs1994
|
||||
/CONTRIBUTING.md @yeasy @khs1994
|
||||
/docker-compose.yml @khs1994
|
||||
/manifest @khs1994
|
||||
/package.json @khs1994
|
||||
/README.md @yeasy @khs1994
|
||||
/SUMMARY.md @yeasy @khs1994
|
||||
13
.github/FUNDING.yml
vendored
@@ -1,13 +0,0 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: yeasy
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
8
.github/ISSUE_TEMPLATE/Bug_report.md
vendored
@@ -21,11 +21,11 @@ about: Create a report to help us improve
|
||||
* [x] Others (Pls describe below)
|
||||
|
||||
### Docker Version
|
||||
<!--如果你的 Docker 版本低于 20.10 请尽可能升级到该版本,保留你的 Docker 版本,其他选项删除-->
|
||||
<!--if Docker version under 20.10, please upgrade Docker to 20.10-->
|
||||
<!--如果你的 Docker 版本低于 19.03 请尽可能升级到该版本,保留你的 Docker 版本,其他选项删除-->
|
||||
<!--if Docker version under 19.03, please upgrade Docker to 19.03-->
|
||||
|
||||
* [x] Test (v20.10)
|
||||
* [x] Stable (v20.10)
|
||||
* [x] Edge (v19.03)
|
||||
* [x] Stable (v19.03)
|
||||
* [x] 1.13.0 or Before
|
||||
|
||||
### Problem Description
|
||||
|
||||
8
.github/ISSUE_TEMPLATE/Custom.md
vendored
@@ -21,11 +21,11 @@ about: Create a issue about Docker
|
||||
* [x] Others (Pls describe below)
|
||||
|
||||
### Docker Version
|
||||
<!--如果你的 Docker 版本低于 20.10 请尽可能升级到该版本,保留你的 Docker 版本,其他选项删除-->
|
||||
<!--if Docker version under 20.10, please upgrade Docker to 20.10-->
|
||||
<!--如果你的 Docker 版本低于 19.03 请尽可能升级到该版本,保留你的 Docker 版本,其他选项删除-->
|
||||
<!--if Docker version under 19.03, please upgrade Docker to 19.03-->
|
||||
|
||||
* [x] Test (v20.10)
|
||||
* [x] Stable (v20.10)
|
||||
* [x] Edge (v19.03)
|
||||
* [x] Stable (v19.03)
|
||||
* [x] 1.13.0 or Before
|
||||
|
||||
### Problem Description
|
||||
|
||||
4
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -3,7 +3,7 @@
|
||||
See [CONTRIBUTING](CONTRIBUTING.md) for contribution guidelines.
|
||||
-->
|
||||
|
||||
**Proposed changes (Mandatory)**
|
||||
### Proposed changes (Mandatory)
|
||||
|
||||
<!--
|
||||
Tell us what you did and why:
|
||||
@@ -13,7 +13,7 @@
|
||||
And details in other paragraphs.
|
||||
-->
|
||||
|
||||
**Fix issues (Optional)**
|
||||
### Fix issues (Optional)
|
||||
|
||||
<!--
|
||||
Tell us what issues you fixed, e.g., fix #123
|
||||
|
||||
65
.github/workflows/check-link.yml
vendored
@@ -1,65 +0,0 @@
|
||||
name: Check link
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
check-link:
|
||||
name: check-link
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4.1.1
|
||||
# search Issues :-(
|
||||
- run: |
|
||||
docker run -i --rm \
|
||||
-v $PWD:/mnt:ro \
|
||||
dkhamsing/awesome_bot \
|
||||
--white-list "localhost","0.0.0.0",\
|
||||
"server","example.com","docker",\
|
||||
"docker.domain.com","YourIP","register",\
|
||||
"172.16.238.100","172.16.238.101","172.16.238.102",\
|
||||
"192.168.199.100",\
|
||||
"github.com/settings",\
|
||||
"github.com/docker/compose/releases/download",\
|
||||
"github.com/etcd-io/etcd/releases/download",\
|
||||
"github.com/tianon/gosu/releases/download",\
|
||||
"github.com/yeasy/docker_practice",\
|
||||
"github.com/AliyunContainerService/k8s-for-docker-desktop/raw",\
|
||||
"dl-cdn.alpinelinux.org/alpine/edge/testing",\
|
||||
"www.w3.org/1999/xhtml",\
|
||||
"cr.console.aliyun.com",\
|
||||
"cloud.tencent.com",\
|
||||
"nodejs.org/dist/",\
|
||||
"c.163.com/hub",\
|
||||
"drone.yeasy.com",\
|
||||
"docs.docker.com",\
|
||||
"dockerhub.azk8s.cn",\
|
||||
"reg-mirror.qiniu.com",\
|
||||
"registry.docker-cn.com",\
|
||||
"mirror.ccs.tencentyun.com",\
|
||||
"vuepress.mirror.docker-practice.com",\
|
||||
"mc.qcloudimg.com/static/img",\
|
||||
"www.daocloud.io/mirror",\
|
||||
"download.docker.com",\
|
||||
"www.ubuntu.com",\
|
||||
"archive.ubuntu.com",\
|
||||
"security.ubuntu.com/ubuntu",\
|
||||
"nginx.com",\
|
||||
"img.shields.io/github/release/yeasy/docker_practice",\
|
||||
"launchpad.net",\
|
||||
"www.w3.org/1999",\
|
||||
"chat.freenode.net",\
|
||||
"en.wikipedia.org/wiki/UnionFS",\
|
||||
"product.china-pub.com",\
|
||||
"union-click.jd.com",\
|
||||
"x.x.x.x/base",\
|
||||
"x.x.x.x:9090",\
|
||||
"yeasy.gitbooks.io",\
|
||||
"download.fastgit.org",\
|
||||
"www.aliyun.com" \
|
||||
--allow-dupe \
|
||||
--skip-save-results \
|
||||
-t 10 \
|
||||
`find . \( -path "./mesos" -o -path "./swarm_mode" \) -prune -o -name "*.md" -exec ls {} \;`
|
||||
name: check-link
|
||||
timeout-minutes: 25
|
||||
150
.github/workflows/ci.yaml
vendored
@@ -1,156 +1,18 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash --noprofile --norc -exo pipefail {0}
|
||||
name: CI
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
name: Build GitBook
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4.1.1
|
||||
- name: Build Gitbook
|
||||
- uses: actions/checkout@master
|
||||
with:
|
||||
fetch-depth: 2
|
||||
- name: Build
|
||||
uses: docker://yeasy/docker_practice
|
||||
with:
|
||||
args: build
|
||||
- name: Build Gitbook Docker Image
|
||||
if: github.repository == 'docker-practice/docker_practice'
|
||||
run: |
|
||||
sudo chmod -R 777 _book
|
||||
echo "FROM nginx:alpine" >> Dockerfile
|
||||
echo "COPY _book /usr/share/nginx/html" >> Dockerfile
|
||||
echo "COPY .docker/docker-entrypoint.sh /" >> Dockerfile
|
||||
echo "ENTRYPOINT [\"/docker-entrypoint.sh\"]" >> Dockerfile
|
||||
|
||||
export VCS_REF=`git rev-parse --short HEAD`
|
||||
|
||||
docker build \
|
||||
-t dockerpracticesig/docker_practice \
|
||||
-t dockerpracticesig/docker_practice:gitbook \
|
||||
--label org.opencontainers.image.revision=$VCS_REF \
|
||||
--label org.opencontainers.image.source="https://github.com/yeasy/docker_practice" \
|
||||
--label maintainer="https://github.com/docker-practice" \
|
||||
.
|
||||
|
||||
docker run -d --rm -p 4000:80 dockerpracticesig/docker_practice
|
||||
|
||||
sleep 5
|
||||
|
||||
echo "::group::Test"
|
||||
curl 127.0.0.1:4000
|
||||
echo "::endgroup::"
|
||||
|
||||
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
|
||||
docker push dockerpracticesig/docker_practice
|
||||
docker push dockerpracticesig/docker_practice:gitbook
|
||||
env:
|
||||
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}
|
||||
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}}
|
||||
- name: Upload Gitbook dist
|
||||
uses: docker://pcit/pages
|
||||
if: github.repository == 'docker-practice/docker_practice'
|
||||
env:
|
||||
PCIT_EMAIL: khs1994@khs1994.com
|
||||
PCIT_GIT_TOKEN: ${{ secrets.PCIT_GIT_TOKEN }}
|
||||
PCIT_GIT_URL: github.com/docker-practice/zh-cn
|
||||
PCIT_KEEP_HISTORY: "true"
|
||||
PCIT_LOCAL_DIR: _book
|
||||
PCIT_MESSAGE: Build from yeasy/docker_practice@${{github.sha}}
|
||||
PCIT_TARGET_BRANCH: master
|
||||
PCIT_USERNAME: khs1994
|
||||
- name: vuepress
|
||||
run: |
|
||||
export NODE_OPTIONS=--openssl-legacy-provider
|
||||
sudo rm -rf _book
|
||||
npm i
|
||||
|
||||
git clone https://github.com/docker-practice/.vuepress .vuepress2
|
||||
cp -r .vuepress2/. .vuepress/
|
||||
rm -rf .vuepress2
|
||||
find . \( -path "./mesos" -o -path "./swarm_mode" -o -path "./node_modules" -o -path "./.vuepress" -o -path "./_book" -o -path "./CHANGELOG.md" -o -path "./CONTRIBUTING.md" \) -prune -o -name "*.md" -exec sed -i 'N;2a\<AdSenseTitle/>\n' {} \;
|
||||
|
||||
npx vuepress --version
|
||||
|
||||
npm run vuepress:build
|
||||
echo "vuepress.mirror.docker-practice.com" > .vuepress/dist/CNAME
|
||||
|
||||
cp -r _images .vuepress/dist
|
||||
cp -r advanced_network/_images .vuepress/dist/advanced_network
|
||||
cp -r appendix/_images .vuepress/dist/appendix
|
||||
cp -r cases/ci/drone/_images .vuepress/dist/cases/ci/drone
|
||||
cp -r cases/os/_images .vuepress/dist/cases/os
|
||||
cp -r cloud/_images .vuepress/dist/cloud
|
||||
cp -r data_management/_images .vuepress/dist/data_management
|
||||
cp -r etcd/_images .vuepress/dist/etcd
|
||||
cp -r image/_images .vuepress/dist/image
|
||||
cp -r install/_images .vuepress/dist/install
|
||||
cp -r introduction/_images .vuepress/dist/introduction
|
||||
cp -r kubernetes/_images .vuepress/dist/kubernetes
|
||||
cp -r underly/_images .vuepress/dist/underly
|
||||
|
||||
echo "include: [_images]" > .vuepress/dist/_config.yml
|
||||
- name: Upload Vuepress dist
|
||||
uses: docker://pcit/pages
|
||||
if: github.repository == 'docker-practice/docker_practice'
|
||||
env:
|
||||
PCIT_EMAIL: khs1994@khs1994.com
|
||||
PCIT_GIT_TOKEN: ${{ secrets.PCIT_GIT_TOKEN }}
|
||||
PCIT_GIT_URL: github.com/docker-practice/vuepress
|
||||
PCIT_KEEP_HISTORY: "true"
|
||||
PCIT_LOCAL_DIR: .vuepress/dist
|
||||
PCIT_MESSAGE: Build from yeasy/docker_practice@${{github.sha}}
|
||||
PCIT_TARGET_BRANCH: master
|
||||
PCIT_USERNAME: khs1994
|
||||
# - name: Set coding.net CNAME
|
||||
# run: |
|
||||
# echo "vuepress.mirror.docker-practice.com" > .vuepress/dist/CNAME
|
||||
# - name: Upload Vuepress dist to coding.net
|
||||
# uses: docker://pcit/pages
|
||||
# if: github.repository == 'docker-practice/docker_practice'
|
||||
# env:
|
||||
# PCIT_EMAIL: khs1994@khs1994.com
|
||||
# PCIT_GIT_TOKEN: ${{ secrets.CODING_GIT_TOKEN }}
|
||||
# PCIT_GIT_URL: e.coding.net/dpsigs/docker_practice
|
||||
# PCIT_KEEP_HISTORY: "true"
|
||||
# PCIT_LOCAL_DIR: .vuepress/dist
|
||||
# PCIT_MESSAGE: Build from yeasy/docker_practice@${{github.sha}}
|
||||
# PCIT_TARGET_BRANCH: master
|
||||
# PCIT_USERNAME: ptt0xjqzbke3
|
||||
- name: Build vuepress docker image
|
||||
if: github.repository == 'docker-practice/docker_practice'
|
||||
run: |
|
||||
sudo rm -rf .vuepress/dist/.git
|
||||
|
||||
echo "FROM nginx:alpine" > Dockerfile
|
||||
echo "COPY .vuepress/dist /usr/share/nginx/html" >> Dockerfile
|
||||
echo "COPY .docker/docker-entrypoint.sh /" >> Dockerfile
|
||||
echo "ENTRYPOINT [\"/docker-entrypoint.sh\"]" >> Dockerfile
|
||||
|
||||
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
|
||||
|
||||
VCS_REF=`git rev-parse --short HEAD`
|
||||
|
||||
docker build -t dockerpracticesig/docker_practice:vuepress \
|
||||
--label org.opencontainers.image.revision=$VCS_REF \
|
||||
--label org.opencontainers.image.source="https://github.com/yeasy/docker_practice" \
|
||||
--label maintainer="https://github.com/docker-practice" \
|
||||
.
|
||||
|
||||
docker push dockerpracticesig/docker_practice:vuepress
|
||||
|
||||
docker run -it --rm -d -p 4001:80 dockerpracticesig/docker_practice:vuepress
|
||||
|
||||
sleep 5
|
||||
|
||||
echo "::group::Test"
|
||||
curl 127.0.0.1:4001
|
||||
echo "::endgroup::"
|
||||
env:
|
||||
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}
|
||||
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}}
|
||||
|
||||
8
.gitignore
vendored
@@ -6,12 +6,4 @@ _book/
|
||||
*.swp
|
||||
*.edx
|
||||
.DS_Store
|
||||
|
||||
node_modules/
|
||||
package-lock.json
|
||||
|
||||
docker-compose.override.yml
|
||||
|
||||
# Editor configs
|
||||
.obsidian/
|
||||
.vscode/
|
||||
|
||||
53
.travis.yml
Normal file
@@ -0,0 +1,53 @@
|
||||
language: bash
|
||||
|
||||
services:
|
||||
- docker
|
||||
|
||||
before_install:
|
||||
- openssl aes-256-cbc -K $encrypted_6cc8cff04075_key -iv $encrypted_6cc8cff04075_iv
|
||||
-in .travis/id_rsa.enc -out ~/.ssh/id_rsa -d
|
||||
- chmod 600 ~/.ssh/id_rsa
|
||||
- export TZ='Asia/Shanghai'
|
||||
- date
|
||||
- git config --global user.name "khs1994"
|
||||
- git config --global user.email "khs1994@khs1994.com"
|
||||
|
||||
script:
|
||||
- docker run -it --rm -v $PWD:/srv/gitbook-src yeasy/docker_practice build
|
||||
|
||||
after_success:
|
||||
- sudo chmod -R 777 _book
|
||||
|
||||
- echo "FROM nginx:alpine" >> Dockerfile
|
||||
- echo "COPY _book /usr/share/nginx/html" >> Dockerfile
|
||||
|
||||
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
|
||||
|
||||
- docker build -t dockerpracticesig/docker_practice:us-en .
|
||||
- docker run -dit --rm -p 4000:80 dockerpracticesig/docker_practice:us-en
|
||||
|
||||
- sleep 5
|
||||
- curl 127.0.0.1:4000
|
||||
|
||||
- docker push dockerpracticesig/docker_practice:us-en
|
||||
|
||||
- cd _book
|
||||
- git init
|
||||
- git remote add origin "$DEPLOY_REPO"
|
||||
- git add .
|
||||
- COMMIT=`date "+%F %T"`
|
||||
- git commit -m "Travis CI Site updated $COMMIT"
|
||||
- git push -f origin master:"$DEPLOY_BRANCH"
|
||||
|
||||
env:
|
||||
global:
|
||||
- DEPLOY_BRANCH: master
|
||||
- DEPLOY_REPO: git@github.com:docker-practice/us-en.git
|
||||
|
||||
addons:
|
||||
ssh_known_hosts:
|
||||
- github.com
|
||||
|
||||
branches:
|
||||
only:
|
||||
- english
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM node:14.4.0-alpine
|
||||
FROM node:alpine
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
|
||||
@@ -8,8 +8,8 @@ COPY book.json book.json
|
||||
|
||||
COPY docker-entrypoint.sh /usr/local/bin/
|
||||
|
||||
RUN set -x && apk add --no-cache \
|
||||
tzdata bash \
|
||||
RUN apk add --no-cache \
|
||||
tzdata \
|
||||
&& npm install -g gitbook-cli \
|
||||
&& gitbook install \
|
||||
&& ln -s /usr/local/bin/docker-entrypoint.sh / \
|
||||
|
||||
@@ -13,11 +13,9 @@ cp -a . /srv/gitbook
|
||||
cd /srv/gitbook
|
||||
|
||||
main(){
|
||||
if [ "$1" = build ];then
|
||||
gitbook build && cp -a _book $srcDir && echo $START && date "+%F %T" && exit 0
|
||||
else
|
||||
if [ "$1" = build ];then gitbook build && cp -a _book $srcDir && echo $START && date "+%F %T" && exit 0; fi
|
||||
exec gitbook serve
|
||||
fi
|
||||
exit 0
|
||||
}
|
||||
|
||||
main $1 $2 $3
|
||||
|
||||
BIN
.travis/id_rsa.enc
Normal file
3
.vuepress/.gitignore
vendored
@@ -1,3 +0,0 @@
|
||||
/*
|
||||
!.gitignore
|
||||
!config.js
|
||||
@@ -1,462 +0,0 @@
|
||||
const { config } = require('vuepress-theme-hope')
|
||||
|
||||
module.exports = config({
|
||||
title: 'Docker 从入门到实践',
|
||||
base: '/',
|
||||
head: [['script', {}, `
|
||||
var _hmt = _hmt || [];
|
||||
(function() {
|
||||
var hm = document.createElement("script");
|
||||
hm.src = "//hm.baidu.com/hm.js?81a3490c9cd141dbcf6d00bc18b6edae";
|
||||
var s = document.getElementsByTagName("script")[0];
|
||||
s.parentNode.insertBefore(hm, s);
|
||||
})();
|
||||
`],
|
||||
[
|
||||
'script', {}, `
|
||||
(function(){
|
||||
var bp = document.createElement('script');
|
||||
var curProtocol = window.location.protocol.split(':')[0];
|
||||
if (curProtocol === 'https') {
|
||||
bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
|
||||
}
|
||||
else {
|
||||
bp.src = 'http://push.zhanzhang.baidu.com/push.js';
|
||||
}
|
||||
var s = document.getElementsByTagName("script")[0];
|
||||
s.parentNode.insertBefore(bp, s);
|
||||
})();
|
||||
`
|
||||
]
|
||||
],
|
||||
plugins: {
|
||||
// sitemap: {
|
||||
// hostname: 'https://vuepress.mirror.docker-practice.com'
|
||||
// },
|
||||
// 'git-log': {
|
||||
// additionalArgs: '--no-merge',
|
||||
// onlyFirstAndLastCommit: true,
|
||||
// },
|
||||
},
|
||||
locales: {
|
||||
"/": {
|
||||
lang: "zh-CN"
|
||||
}
|
||||
},
|
||||
themeConfig: {
|
||||
blog: false,
|
||||
// comment: false,
|
||||
comment: {
|
||||
type: "disable", // 使用 Valine
|
||||
appId: "...", // your appId
|
||||
appKey: "...", // your appKey
|
||||
},
|
||||
pageInfo: [
|
||||
// 'author',
|
||||
'reading-time',
|
||||
'word',
|
||||
],
|
||||
footer: {
|
||||
content: "Made with <a target='_blank' href='https://github.com/vuepress-theme-hope/vuepress-theme-hope'>vuepress-theme-hope</a>",
|
||||
display: true,
|
||||
copyright: false,
|
||||
},
|
||||
searchPlaceholder: 'Search',
|
||||
repo: 'yeasy/docker_practice',
|
||||
repoLabel: 'GitHub',
|
||||
repoDisplay: true,
|
||||
hostname: 'https://vuepress.mirror.docker-practice.com',
|
||||
// author: 'yeasy',
|
||||
mdEnhance: {
|
||||
lineNumbers: true,
|
||||
},
|
||||
git: {
|
||||
contributor: false,
|
||||
},
|
||||
themeColor: {
|
||||
blue: '#2196f3',
|
||||
// red: '#f26d6d',
|
||||
// green: '#3eaf7c',
|
||||
// orange: '#fb9b5f'
|
||||
},
|
||||
locales: {
|
||||
"/": {
|
||||
lang: "zh-CN"
|
||||
}
|
||||
},
|
||||
|
||||
darkmode: 'auto-switch',
|
||||
|
||||
//
|
||||
|
||||
showAds: true,
|
||||
|
||||
docsRepo: 'yeasy/docker_practice',
|
||||
docsDir: '/',
|
||||
docsBranch: 'master',
|
||||
editLinks: true,
|
||||
nav: [
|
||||
{
|
||||
text: '微信交流群',
|
||||
link: 'https://docker_practice.gitee.io/pic/dpsig-wechat.jpg',
|
||||
},
|
||||
{
|
||||
text: '小程序',
|
||||
link: 'https://docker_practice.gitee.io/pic/dp-wechat-miniprogram.jpg',
|
||||
},
|
||||
{
|
||||
text: '安装 Docker',
|
||||
link: '/install/',
|
||||
},
|
||||
{
|
||||
text: 'Docker 入门',
|
||||
link: '/'
|
||||
},
|
||||
{
|
||||
text: 'Docker 实战',
|
||||
link: '/cases/os/'
|
||||
},
|
||||
{
|
||||
text: 'CI/CD',
|
||||
link: '/cases/ci/'
|
||||
},
|
||||
{
|
||||
text: 'Compose',
|
||||
link: '/compose/',
|
||||
},
|
||||
{
|
||||
text: 'Kubernetes',
|
||||
link: '/kubernetes/',
|
||||
},
|
||||
{
|
||||
text: "云计算",
|
||||
link: "/cloud/",
|
||||
},
|
||||
// {
|
||||
// text: 'GitHub',
|
||||
// link: 'https://github.com/yeasy/docker_practice'
|
||||
// },
|
||||
// {
|
||||
// text: '捐赠',
|
||||
// link: ''
|
||||
// },
|
||||
{
|
||||
text: '云服务器99/元首年特惠',
|
||||
link: 'https://cloud.tencent.com/act/cps/redirect?redirect=1062&cps_key=3a5255852d5db99dcd5da4c72f05df61&from=console'
|
||||
},
|
||||
// {
|
||||
// text: '语言',
|
||||
// items: [{
|
||||
// text: 'English',
|
||||
// link: ''
|
||||
// }]
|
||||
// }
|
||||
],
|
||||
sidebar: {
|
||||
'/cloud/': [
|
||||
'intro',
|
||||
'tencentCloud',
|
||||
'alicloud',
|
||||
'aws',
|
||||
'summary',
|
||||
],
|
||||
'/kubernetes/': [
|
||||
'intro',
|
||||
'concepts',
|
||||
'design',
|
||||
{
|
||||
title: "部署 Kubernetes",
|
||||
collapsable: true,
|
||||
children: [
|
||||
"setup/",
|
||||
"setup/kubeadm",
|
||||
"setup/docker-desktop",
|
||||
"setup/systemd",
|
||||
"setup/dashboard",
|
||||
]
|
||||
},
|
||||
{
|
||||
title: "Kubernetes 命令行 kubectl",
|
||||
collapsable: true,
|
||||
children: [
|
||||
'kubectl/'
|
||||
]
|
||||
}
|
||||
],
|
||||
'/compose/': [
|
||||
'introduction',
|
||||
'v2',
|
||||
'install',
|
||||
'usage',
|
||||
'commands',
|
||||
'compose_file',
|
||||
'django',
|
||||
'rails',
|
||||
'wordpress',
|
||||
'lnmp',
|
||||
],
|
||||
'/install/': [
|
||||
'ubuntu',
|
||||
'debian',
|
||||
'fedora',
|
||||
'centos',
|
||||
'raspberry-pi',
|
||||
// 'offline',
|
||||
'mac',
|
||||
'windows',
|
||||
'mirror',
|
||||
'experimental',
|
||||
],
|
||||
'/cases/os/': [
|
||||
{
|
||||
title: "操作系统",
|
||||
collapsable: false,
|
||||
children: [
|
||||
'busybox',
|
||||
'alpine',
|
||||
'debian',
|
||||
'centos',
|
||||
'summary',
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "在 IDE 中使用 Docker",
|
||||
collapsable: false,
|
||||
children: [
|
||||
'/ide/',
|
||||
'/ide/vsCode',
|
||||
],
|
||||
},
|
||||
],
|
||||
'/cases/ci/': [
|
||||
'actions/',
|
||||
{
|
||||
title: "Drone",
|
||||
collapsable: true,
|
||||
children: [
|
||||
'drone/',
|
||||
'drone/install'
|
||||
]
|
||||
},
|
||||
],
|
||||
'/': [
|
||||
'/',
|
||||
'/CHANGELOG',
|
||||
'/CONTRIBUTING',
|
||||
{
|
||||
title: "Docker 简介",
|
||||
collapsable: false,
|
||||
children: [
|
||||
'introduction/',
|
||||
'introduction/what',
|
||||
'introduction/why',
|
||||
]
|
||||
}, {
|
||||
title: "基本概念",
|
||||
collapsable: false,
|
||||
children: [
|
||||
'basic_concept/',
|
||||
'basic_concept/image',
|
||||
'basic_concept/container',
|
||||
'basic_concept/repository'
|
||||
]
|
||||
},
|
||||
{
|
||||
title: "使用镜像",
|
||||
collapsable: false,
|
||||
children: [
|
||||
'image/',
|
||||
'image/pull',
|
||||
'image/list',
|
||||
'image/rm',
|
||||
'image/commit',
|
||||
'image/build',
|
||||
'image/other.md',
|
||||
'image/internal.md',
|
||||
]
|
||||
},
|
||||
{
|
||||
title: 'Dockerfile',
|
||||
collapsable: true,
|
||||
children: [
|
||||
"image/dockerfile/",
|
||||
'image/dockerfile/copy',
|
||||
'image/dockerfile/add',
|
||||
'image/dockerfile/cmd',
|
||||
'image/dockerfile/entrypoint',
|
||||
'image/dockerfile/env',
|
||||
'image/dockerfile/arg',
|
||||
'image/dockerfile/volume',
|
||||
'image/dockerfile/expose',
|
||||
'image/dockerfile/workdir',
|
||||
'image/dockerfile/user',
|
||||
'image/dockerfile/healthcheck',
|
||||
'image/dockerfile/label',
|
||||
'image/dockerfile/shell',
|
||||
'image/dockerfile/onbuild',
|
||||
'image/dockerfile/references',
|
||||
'image/multistage-builds/',
|
||||
'image/multistage-builds/laravel',
|
||||
'image/manifest',
|
||||
]
|
||||
}, {
|
||||
title: "操作容器",
|
||||
collapsable: false,
|
||||
children: [
|
||||
'container/',
|
||||
'container/run',
|
||||
'container/daemon',
|
||||
'container/stop',
|
||||
'container/attach_exec',
|
||||
'container/import_export',
|
||||
'container/rm',
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Docker 仓库",
|
||||
collapsable: false,
|
||||
children: [
|
||||
'repository/',
|
||||
'repository/dockerhub',
|
||||
'repository/registry',
|
||||
'repository/registry_auth',
|
||||
'repository/nexus3_registry',
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "数据管理",
|
||||
collapsable: false,
|
||||
children: [
|
||||
'data_management/',
|
||||
'data_management/volume',
|
||||
'data_management/bind-mounts',
|
||||
],
|
||||
}, {
|
||||
title: "使用网络",
|
||||
collapsable: false,
|
||||
children: [
|
||||
'network/',
|
||||
'network/port_mapping',
|
||||
'network/linking',
|
||||
'network/dns',
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "高级网络配置",
|
||||
collapsable: true,
|
||||
children: [
|
||||
'advanced_network/',
|
||||
'advanced_network/quick_guide',
|
||||
'advanced_network/access_control',
|
||||
'advanced_network/port_mapping',
|
||||
'advanced_network/bridge',
|
||||
'advanced_network/example',
|
||||
'advanced_network/config_file',
|
||||
'advanced_network/ptp',
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Swarm mode",
|
||||
collapsable: true,
|
||||
children: [
|
||||
'swarm_mode/',
|
||||
'swarm_mode/overview',
|
||||
'swarm_mode/create',
|
||||
'swarm_mode/deploy',
|
||||
'swarm_mode/stack',
|
||||
'swarm_mode/secret',
|
||||
'swarm_mode/config',
|
||||
'swarm_mode/rolling_update',
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "安全",
|
||||
collapsable: true,
|
||||
children: [
|
||||
'security/',
|
||||
'security/kernel_ns',
|
||||
'security/control_group',
|
||||
'security/daemon_sec',
|
||||
'security/kernel_capability',
|
||||
'security/other_feature',
|
||||
'security/summary',
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "底层实现",
|
||||
collapsable: true,
|
||||
children: [
|
||||
'underly/',
|
||||
'underly/arch',
|
||||
'underly/namespace',
|
||||
'underly/cgroups',
|
||||
'underly/ufs',
|
||||
'underly/container_format',
|
||||
'underly/network',
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Docker Buildx",
|
||||
collapsable: false,
|
||||
children: [
|
||||
"buildx/",
|
||||
"buildx/buildkit",
|
||||
"buildx/buildx",
|
||||
"buildx/multi-arch-images",
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Etcd",
|
||||
collapsable: true,
|
||||
children: [
|
||||
'etcd/',
|
||||
'etcd/intro',
|
||||
'etcd/install',
|
||||
'etcd/cluster',
|
||||
'etcd/etcdctl',
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Fedora CoreOS",
|
||||
collapsable: true,
|
||||
children: [
|
||||
'coreos/',
|
||||
'coreos/intro',
|
||||
'coreos/install',
|
||||
],
|
||||
},
|
||||
'podman/',
|
||||
'appendix/faq/',
|
||||
{
|
||||
title: "热门镜像介绍",
|
||||
collapsable: true,
|
||||
children: [
|
||||
'appendix/repo/',
|
||||
'appendix/repo/ubuntu',
|
||||
'appendix/repo/centos',
|
||||
'appendix/repo/nginx',
|
||||
'appendix/repo/php',
|
||||
'appendix/repo/nodejs',
|
||||
'appendix/repo/mysql',
|
||||
'appendix/repo/wordpress',
|
||||
'appendix/repo/mongodb',
|
||||
'appendix/repo/redis',
|
||||
'appendix/repo/minio',
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Docker 命令",
|
||||
collapsable: true,
|
||||
children: [
|
||||
'appendix/command/',
|
||||
'appendix/command/docker',
|
||||
'appendix/command/dockerd',
|
||||
]
|
||||
},
|
||||
'appendix/best_practices',
|
||||
'appendix/debug',
|
||||
'appendix/resources',
|
||||
],
|
||||
},
|
||||
}
|
||||
});
|
||||
25
CHANGELOG.md
@@ -1,32 +1,13 @@
|
||||
# 修订记录
|
||||
|
||||
* 1.4.0 2026-01-11
|
||||
* 全面支持 Docker Engine v29 新版本
|
||||
* 更新 Docker Compose 至 v2.40.x
|
||||
* 更新 Kubernetes 相关章节至 1.35 版本
|
||||
* BuildKit 已成为默认稳定构建器,移除实验特性说明
|
||||
* 新增 Docker Scout、Docker Init 相关内容
|
||||
* 更新镜像加速器配置
|
||||
* 添加 CentOS EOL 警告,推荐使用 Rocky Linux/AlmaLinux
|
||||
* 扩充安全章节和底层架构章节内容
|
||||
|
||||
* 1.3.0 2021-12-31
|
||||
* 全面支持 Docker v20.10 新版本
|
||||
* 新增 Docker Compose v2
|
||||
* Docker Hub 自动构建转为付费功能
|
||||
|
||||
* 1.2.0 2020-12-20
|
||||
* 错误修复
|
||||
## 主要修订记录
|
||||
|
||||
* 1.1.0 2019-12-31
|
||||
* 全面支持 Docker v19.03 新版本
|
||||
* 全面支持 v19.x 新版本
|
||||
* 增加 `BuildKit`
|
||||
* 增加 `docker buildx` 命令使用说明
|
||||
* 增加 `docker manifest` 命令使用说明
|
||||
* 移除 `Ubuntu 14.04` `Debian 8` `Debian 7`
|
||||
|
||||
* 1.0.0: 2018-12-31
|
||||
* 全面支持 Docker v18.x 新版本
|
||||
* 全面支持 v18.x 新版本
|
||||
* 添加如何调试 Docker
|
||||
* 错误修正
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# 如何贡献
|
||||
## 如何贡献项目
|
||||
|
||||
领取或创建新的 [Issue](https://github.com/yeasy/docker_practice/issues),如 [issue 235](https://github.com/yeasy/docker_practice/issues/235),添加自己为 `Assignee`。
|
||||
|
||||
|
||||
104
README.md
@@ -1,78 +1,64 @@
|
||||
# Docker — 从入门到实践
|
||||
# Docker — 从入门到实践(英文版)
|
||||
|
||||
[](https://github.com/yeasy/docker_practice) [](https://github.com/yeasy/docker_practice/releases) [](https://github.com/docker/docker-ce) [][1]
|
||||
[](https://github.com/yeasy/docker_practice) [](https://travis-ci.org/yeasy/docker_practice) [](https://github.com/yeasy/docker_practice/releases) [](https://github.com/docker/docker-ce) [](https://union-click.jd.com/jdc?e=&p=AyIGZRtYFAcXBFIZWR0yEgRQH1kXAhs3EUQDS10iXhBeGlcJDBkNXg9JHU4YDk5ER1xOGRNLGEEcVV8BXURFUFdfC0RVU1JRUy1OVxUBFwNXGVscMlVYLlAaXAV1Z1JHA0dWEHVXZTliY1QLWStaJQAWB10fXhwKEDdlG1wlUHzf462DsLMO0%2F%2BUjp2VIgZlG18RBBcCUBlbEAoTBWUcWxwySVI7HAhBBxEOBUgOFQYQUGUraxYyIjdVK1glQHxXUEhYEVEUUFQcC0IHGgRRSAgVARAPAhsLFgNCDl0ZWiUAEwZREg%3D%3D&t=W1dCFFlQCxxKQgFHREkdSVJKSQVJHFRXFk9FUlpGQUpLCVBaTFhbXQtWVmpSWRtYEAYQBVUS)
|
||||
|
||||
**v1.4.3**
|
||||
**v1.1.0**
|
||||
|
||||
| 语言 | 构建状态 | - |
|
||||
| :------------- | :------------- | :--- |
|
||||
| [zh-hans](https://github.com/yeasy/docker_practice) | [](https://travis-ci.org/yeasy/docker_practice)| [阅读](https://docker_practice.gitee.io/zh-cn) |
|
||||
| [us-en](https://github.com/yeasy/docker_practice/tree/english) | [](https://travis-ci.org/yeasy/docker_practice)| [阅读](https://docker_practice.gitee.io/us-en) |
|
||||
| [zh-hant](https://github.com/yeasy/docker_practice/tree/zh-Hant) | [](https://travis-ci.org/yeasy/docker_practice)| [阅读](https://docker_practice.gitee.io/zh_hant) |
|
||||
|
||||
[Docker](https://www.docker.com) 是个划时代的开源项目,它彻底释放了计算虚拟化的威力,极大提高了应用的维护效率,降低了云计算应用开发的成本!使用 Docker,可以让应用的部署、测试和分发都变得前所未有的高效和轻松!
|
||||
|
||||
无论是应用开发者、运维人员、还是其他信息技术从业人员,都有必要认识和掌握 Docker,节约有限的生命。
|
||||
|
||||
本书既适用于具备基础 Linux 知识的 Docker 初学者,也希望可供理解原理和实现的高级用户参考。同时,书中给出的实践案例,可供在进行实际部署时借鉴。
|
||||
本书既适用于具备基础 Linux 知识的 Docker 初学者,也希望可供理解原理和实现的高级用户参考。同时,书中给出的实践案例,可供在进行实际部署时借鉴。前六章为基础内容,供用户理解 Docker 的基本概念和操作;7 ~ 9 章介绍包括数据管理、网络等高级操作;第 10 ~ 13 章介绍了容器生态中的几个核心项目;14、15 章讨论了关于 Docker 安全和实现技术等高级话题。后续章节则分别介绍包括 Etcd、CoreOS、Kubernetes、Mesos、容器云等相关热门开源项目。最后,还展示了使用容器技术的典型的应用场景和实践案例。
|
||||
|
||||
## 内容特色
|
||||
* 在线阅读:[docker-practice.com](https://docker-practice.com/),[GitBook](https://yeasy.gitbooks.io/docker_practice/content/),[Github](https://github.com/yeasy/docker_practice/blob/master/SUMMARY.md),[GitBook 国内镜像](https://docker_practice.gitee.io/zh-cn),[GitBook 英文版国内镜像](https://docker_practice.gitee.io/us_en),[国内镜像](https://github.com/yeasy/docker_practice/wiki/%E9%A1%B9%E7%9B%AE%E5%9B%BD%E5%86%85%E9%95%9C%E5%83%8F)
|
||||
* 下载:[pdf](https://github.com/yeasy/docker_practice/wiki/%E4%B8%8B%E8%BD%BD),[epub](https://github.com/yeasy/docker_practice/wiki/%E4%B8%8B%E8%BD%BD)
|
||||
* [离线阅读 `$ docker run -it --rm -p 4000:80 dockerpracticesig/docker_practice`](https://github.com/yeasy/docker_practice/wiki/%E7%A6%BB%E7%BA%BF%E9%98%85%E8%AF%BB%E5%8A%9F%E8%83%BD%E8%AF%A6%E8%A7%A3)
|
||||
* [英文翻译](https://github.com/yeasy/docker_practice/issues/363)
|
||||
|
||||
* **系统全面**:前六章为基础内容,帮助深入理解 Docker 的基本概念(镜像、容器、仓库)和核心操作。
|
||||
* **进阶实战**:7 ~ 9 章涵盖数据管理、网络配置、Dockerfile 最佳实践等高级操作。
|
||||
* **生态深度**:10 ~ 12 章介绍 Kubernetes、Etcd 等容器生态核心项目。
|
||||
* **安全实现**:13、14 章深入讨论 Docker 安全机制与底层实现技术。
|
||||
* **广泛扩展**:涵盖 Fedora CoreOS、容器云等热门开源项目,并展示典型的应用场景和实践案例。
|
||||
|
||||
## 阅读方式
|
||||
|
||||
### 在线阅读
|
||||
> 推荐访问官方 GitBook,体验最佳。
|
||||
|
||||
* **GitBook**: [yeasy.gitbook.io/docker_practice](https://yeasy.gitbook.io/docker_practice/)
|
||||
* **GitHub**: [github.com/yeasy/docker_practice](https://github.com/yeasy/docker_practice/blob/master/SUMMARY.md)
|
||||
* **Mirror**: [docker-practice.com](https://vuepress.mirror.docker-practice.com/)
|
||||
|
||||
### 本地阅读
|
||||
|
||||
#### 方式 1:Docker 镜像(推荐)
|
||||
无需安装任何依赖,一条命令即可启动。
|
||||
|
||||
```bash
|
||||
docker run -it --rm -p 4000:80 ccr.ccs.tencentyun.com/dockerpracticesig/docker_practice:vuepress
|
||||
```
|
||||
启动后访问 [http://localhost:4000](http://localhost:4000)。
|
||||
[详情参考](https://github.com/yeasy/docker_practice/wiki/%E7%A6%BB%E7%BA%BF%E9%98%85%E8%AF%BB%E5%8A%9F%E8%83%BD%E8%AF%A6%E8%A7%A3)
|
||||
|
||||
#### 方式 2:本地构建(HonKit)
|
||||
适合想要修改内容或深度定制的读者。需要安装 Node.js 环境。
|
||||
|
||||
```bash
|
||||
npm install
|
||||
npx honkit serve
|
||||
```
|
||||
启动后访问 [http://localhost:4000](http://localhost:4000)。
|
||||
|
||||
## 社区交流
|
||||
|
||||
欢迎加入 Docker 技术交流群,分享 Docker 资源,交流 Docker 技术。
|
||||
|
||||
* **GitHub Discussions**:[点击前往](https://github.com/yeasy/docker_practice/discussions)(技术问答、交流)
|
||||
* **GitHub Issues**:[提交 Bug](https://github.com/yeasy/docker_practice/issues/new/choose)(内容错误、建议)
|
||||
|
||||
> **交流 QQ 群**(部分已满,建议优先使用 GitHub Discussions):
|
||||
> * 341410255 (I), 419042067 (II), 210028779 (III), 483702734 (IV), 460598761 (V)
|
||||
> * 581983671 (VI), 252403484 (VII), 544818750 (VIII), 571502246 (IX), 145983035 (X)
|
||||
|
||||
## 参与贡献
|
||||
|
||||
欢迎 [参与项目维护](CONTRIBUTING.md)。
|
||||
Docker 自身仍在快速发展中,生态环境也在蓬勃成长。建议初学者使用最新稳定版本的 Docker 进行学习实践。欢迎 [参与项目维护](CONTRIBUTING.md)。
|
||||
|
||||
* [修订记录](CHANGELOG.md)
|
||||
* [贡献者名单](https://github.com/yeasy/docker_practice/graphs/contributors)
|
||||
|
||||
## 微信小程序
|
||||
|
||||
<p align="center">
|
||||
<img width="200" src="https://user-images.githubusercontent.com/16733187/49682252-3ac4c500-faec-11e8-86ab-eafe0139be6b.jpg">
|
||||
</p>
|
||||
|
||||
<p align="center"><strong>微信扫码 随时随地阅读~</strong></p>
|
||||
|
||||
## 技术交流
|
||||
|
||||
欢迎加入 Docker 技术交流 QQ 群,分享 Docker 资源,交流 Docker 技术。
|
||||
|
||||
* QQ 群 I (已满):341410255
|
||||
* QQ 群 II (已满):419042067
|
||||
* QQ 群 III (已满):210028779
|
||||
* QQ 群 IV (已满):483702734
|
||||
* QQ 群 V (已满):460598761
|
||||
* QQ 群 VI (已满):581983671
|
||||
* QQ 群 VII (已满):252403484
|
||||
* QQ 群 VIII(已满):544818750
|
||||
* QQ 群 IX (已满):571502246
|
||||
* QQ 群 X (可加):145983035
|
||||
|
||||
>如果有问题,请通过 [Issues](https://github.com/yeasy/docker_practice/issues/new/choose) 来提出。
|
||||
|
||||
## 进阶学习
|
||||
|
||||
[][1]
|
||||
[](https://union-click.jd.com/jdc?e=&p=AyIGZRtYFAcXBFIZWR0yEgRQH1kXAhs3EUQDS10iXhBeGlcJDBkNXg9JHU4YDk5ER1xOGRNLGEEcVV8BXURFUFdfC0RVU1JRUy1OVxUBFwNXGVscMlVYLlAaXAV1Z1JHA0dWEHVXZTliY1QLWStaJQAWB10fXhwKEDdlG1wlUHzf462DsLMO0%2F%2BUjp2VIgZlG18RBBcCUBlbEAoTBWUcWxwySVI7HAhBBxEOBUgOFQYQUGUraxYyIjdVK1glQHxXUEhYEVEUUFQcC0IHGgRRSAgVARAPAhsLFgNCDl0ZWiUAEwZREg%3D%3D&t=W1dCFFlQCxxKQgFHREkdSVJKSQVJHFRXFk9FUlpGQUpLCVBaTFhbXQtWVmpSWRtYEAYQBVUS)
|
||||
|
||||
《[Docker 技术入门与实战][1]》已更新到第 4 版,讲解最新容器技术栈知识,欢迎大家阅读并反馈建议。
|
||||
《[Docker 技术入门与实战](https://union-click.jd.com/jdc?e=&p=AyIGZRtYFAcXBFIZWR0yEgRQH1kXAhs3EUQDS10iXhBeGlcJDBkNXg9JHU4YDk5ER1xOGRNLGEEcVV8BXURFUFdfC0RVU1JRUy1OVxUBFwNXGVscMlVYLlAaXAV1Z1JHA0dWEHVXZTliY1QLWStaJQAWB10fXhwKEDdlG1wlUHzf462DsLMO0%2F%2BUjp2VIgZlG18RBBcCUBlbEAoTBWUcWxwySVI7HAhBBxEOBUgOFQYQUGUraxYyIjdVK1glQHxXUEhYEVEUUFQcC0IHGgRRSAgVARAPAhsLFgNCDl0ZWiUAEwZREg%3D%3D&t=W1dCFFlQCxxKQgFHREkdSVJKSQVJHFRXFk9FUlpGQUpLCVBaTFhbXQtWVmpSWRtYEAYQBVUS)》第三版已经面世,介绍最新的容器技术栈,欢迎大家阅读使用并反馈建议。
|
||||
|
||||
* [京东图书][1]
|
||||
* [天猫图书](https://detail.tmall.com/item.htm?id=997383773726&skuId=6143496614475)
|
||||
* [京东图书](https://union-click.jd.com/jdc?e=&p=AyIGZRtYFAcXBFIZWR0yEgRQH1kXAhs3EUQDS10iXhBeGlcJDBkNXg9JHU4YDk5ER1xOGRNLGEEcVV8BXURFUFdfC0RVU1JRUy1OVxUBFwNXGVscMlVYLlAaXAV1Z1JHA0dWEHVXZTliY1QLWStaJQAWB10fXhwKEDdlG1wlUHzf462DsLMO0%2F%2BUjp2VIgZlG18RBBcCUBlbEAoTBWUcWxwySVI7HAhBBxEOBUgOFQYQUGUraxYyIjdVK1glQHxXUEhYEVEUUFQcC0IHGgRRSAgVARAPAhsLFgNCDl0ZWiUAEwZREg%3D%3D&t=W1dCFFlQCxxKQgFHREkdSVJKSQVJHFRXFk9FUlpGQUpLCVBaTFhbXQtWVmpSWRtYEAYQBVUS)
|
||||
* [China-Pub](http://product.china-pub.com/8052127)
|
||||
|
||||
## 鼓励项目
|
||||
|
||||
@@ -81,5 +67,3 @@ npx honkit serve
|
||||
</p>
|
||||
|
||||
<p align="center"><strong>欢迎鼓励项目一杯 coffee~</strong></p>
|
||||
|
||||
[1]: https://item.jd.com/10200902362001.html
|
||||
|
||||
264
SUMMARY.md
@@ -1,159 +1,155 @@
|
||||
# [Docker — 从入门到实践](https://github.com/yeasy/docker_practice/blob/master/SUMMARY.md)
|
||||
# [Docker — 从入门到实践(英文版)](https://github.com/yeasy/docker_practice/blob/english/SUMMARY.md)
|
||||
|
||||
* [前言](README.md)
|
||||
* [修订记录](CHANGELOG.md)
|
||||
* [如何贡献](CONTRIBUTING.md)
|
||||
* [Docker 简介](introduction/README.md)
|
||||
* [什么是 Docker](introduction/what.md)
|
||||
* [为什么要用 Docker](introduction/why.md)
|
||||
* [基本概念](basic_concept/README.md)
|
||||
* [镜像](basic_concept/image.md)
|
||||
* [容器](basic_concept/container.md)
|
||||
* [仓库](basic_concept/repository.md)
|
||||
* [安装 Docker](install/README.md)
|
||||
* [README](README.md)
|
||||
* [CHANGELOG](CHANGELOG.md)
|
||||
* [CONTRIBUTING](CONTRIBUTING.md)
|
||||
* [Introduction](introduction/README.md)
|
||||
* [What is Docker](introduction/what.md)
|
||||
* [Why Docker](introduction/why.md)
|
||||
* [Basic concept](basic_concept/README.md)
|
||||
* [Image](basic_concept/image.md)
|
||||
* [Container](basic_concept/container.md)
|
||||
* [Repository](basic_concept/repository.md)
|
||||
* [Get Docker](install/README.md)
|
||||
* [Ubuntu](install/ubuntu.md)
|
||||
* [Debian](install/debian.md)
|
||||
* [Fedora](install/fedora.md)
|
||||
* [CentOS](install/centos.md)
|
||||
* [Raspberry Pi](install/raspberry-pi.md)
|
||||
* [Linux 离线安装](install/offline.md)
|
||||
* [macOS](install/mac.md)
|
||||
* [Windows 10/11](install/windows.md)
|
||||
* [镜像加速器](install/mirror.md)
|
||||
* [开启实验特性](install/experimental.md)
|
||||
* [使用镜像](image/README.md)
|
||||
* [获取镜像](image/pull.md)
|
||||
* [列出镜像](image/list.md)
|
||||
* [删除本地镜像](image/rm.md)
|
||||
* [利用 commit 理解镜像构成](image/commit.md)
|
||||
* [使用 Dockerfile 定制镜像](image/build.md)
|
||||
* [Dockerfile 指令详解](image/dockerfile/README.md)
|
||||
* [COPY 复制文件](image/dockerfile/copy.md)
|
||||
* [ADD 更高级的复制文件](image/dockerfile/add.md)
|
||||
* [CMD 容器启动命令](image/dockerfile/cmd.md)
|
||||
* [ENTRYPOINT 入口点](image/dockerfile/entrypoint.md)
|
||||
* [ENV 设置环境变量](image/dockerfile/env.md)
|
||||
* [ARG 构建参数](image/dockerfile/arg.md)
|
||||
* [VOLUME 定义匿名卷](image/dockerfile/volume.md)
|
||||
* [EXPOSE 暴露端口](image/dockerfile/expose.md)
|
||||
* [WORKDIR 指定工作目录](image/dockerfile/workdir.md)
|
||||
* [USER 指定当前用户](image/dockerfile/user.md)
|
||||
* [HEALTHCHECK 健康检查](image/dockerfile/healthcheck.md)
|
||||
* [ONBUILD 为他人作嫁衣裳](image/dockerfile/onbuild.md)
|
||||
* [LABEL 为镜像添加元数据](image/dockerfile/label.md)
|
||||
* [SHELL 指令](image/dockerfile/shell.md)
|
||||
* [参考文档](image/dockerfile/references.md)
|
||||
* [Dockerfile 多阶段构建](image/multistage-builds/README.md)
|
||||
* [实战多阶段构建 Laravel 镜像](image/multistage-builds/laravel.md)
|
||||
* [其它制作镜像的方式](image/other.md)
|
||||
* [实现原理](image/internal.md)
|
||||
* [操作容器](container/README.md)
|
||||
* [启动](container/run.md)
|
||||
* [守护态运行](container/daemon.md)
|
||||
* [终止](container/stop.md)
|
||||
* [进入容器](container/attach_exec.md)
|
||||
* [导出和导入](container/import_export.md)
|
||||
* [删除](container/rm.md)
|
||||
* [访问仓库](repository/README.md)
|
||||
* [Windows PC](install/windows.md)
|
||||
* [Mirror](install/mirror.md)
|
||||
* [Image](image/README.md)
|
||||
* [pull](image/pull.md)
|
||||
* [list](image/list.md)
|
||||
* [Delete](image/rm.md)
|
||||
* [commit](image/commit.md)
|
||||
* [Dockerfile](image/build.md)
|
||||
* [Dockerfile reference](image/dockerfile/README.md)
|
||||
* [COPY](image/dockerfile/copy.md)
|
||||
* [ADD](image/dockerfile/add.md)
|
||||
* [CMD](image/dockerfile/cmd.md)
|
||||
* [ENTRYPOINT](image/dockerfile/entrypoint.md)
|
||||
* [ENV](image/dockerfile/env.md)
|
||||
* [ARG](image/dockerfile/arg.md)
|
||||
* [VOLUME](image/dockerfile/volume.md)
|
||||
* [EXPOSE](image/dockerfile/expose.md)
|
||||
* [WORKDIR](image/dockerfile/workdir.md)
|
||||
* [USER](image/dockerfile/user.md)
|
||||
* [HEALTHCHECK](image/dockerfile/healthcheck.md)
|
||||
* [ONBUILD](image/dockerfile/onbuild.md)
|
||||
* [References](image/dockerfile/references.md)
|
||||
* [Multistage builds](image/multistage-builds/README.md)
|
||||
* [Multistage builds Laravel](image/multistage-builds/laravel.md)
|
||||
* [manifest](image/manifest.md)
|
||||
* [BuildKit](image/buildkit.md)
|
||||
* [Other](image/other.md)
|
||||
* [Internal](image/internal.md)
|
||||
* [Container](container/README.md)
|
||||
* [run](container/run.md)
|
||||
* [Daemon](container/daemon.md)
|
||||
* [stop](container/stop.md)
|
||||
* [exec](container/attach_exec.md)
|
||||
* [Import and export](container/import_export.md)
|
||||
* [Delete](container/rm.md)
|
||||
* [Repository](repository/README.md)
|
||||
* [Docker Hub](repository/dockerhub.md)
|
||||
* [私有仓库](repository/registry.md)
|
||||
* [私有仓库高级配置](repository/registry_auth.md)
|
||||
* [Docker Registry](repository/registry.md)
|
||||
* [Docker Registry TLS](repository/registry_auth.md)
|
||||
* [Nexus 3](repository/nexus3_registry.md)
|
||||
* [数据管理](data_management/README.md)
|
||||
* [数据卷](data_management/volume.md)
|
||||
* [挂载主机目录](data_management/bind-mounts.md)
|
||||
* [网络配置](network/README.md)
|
||||
* [配置 DNS](network/dns.md)
|
||||
* [外部访问容器](network/port_mapping.md)
|
||||
* [Docker Buildx](buildx/README.md)
|
||||
* [BuildKit](buildx/buildkit.md)
|
||||
* [使用 buildx 构建镜像](buildx/buildx.md)
|
||||
* [使用 buildx 构建多种系统架构支持的 Docker 镜像](buildx/multi-arch-images.md)
|
||||
* [Data management](data_management/README.md)
|
||||
* [Volumes](data_management/volume.md)
|
||||
* [Bind mounts](data_management/bind-mounts.md)
|
||||
* [Network](network/README.md)
|
||||
* [Port mapping](network/port_mapping.md)
|
||||
* [Linking](network/linking.md)
|
||||
* [DNS](network/dns.md)
|
||||
* [Advanced network](advanced_network/README.md)
|
||||
* [Guide](advanced_network/quick_guide.md)
|
||||
* [Access control](advanced_network/access_control.md)
|
||||
* [Port mapping](advanced_network/port_mapping.md)
|
||||
* [docker0](advanced_network/docker0.md)
|
||||
* [Bridge](advanced_network/bridge.md)
|
||||
* [Example](advanced_network/example.md)
|
||||
* [Config](advanced_network/config_file.md)
|
||||
* [PTP](advanced_network/ptp.md)
|
||||
* [Docker Compose](compose/README.md)
|
||||
* [简介](compose/introduction.md)
|
||||
* [安装与卸载](compose/install.md)
|
||||
* [使用](compose/usage.md)
|
||||
* [命令说明](compose/commands.md)
|
||||
* [Compose 模板文件](compose/compose_file.md)
|
||||
* [实战 Django](compose/django.md)
|
||||
* [实战 Rails](compose/rails.md)
|
||||
* [实战 WordPress](compose/wordpress.md)
|
||||
* [实战 LNMP](compose/lnmp.md)
|
||||
* [Introduction](compose/introduction.md)
|
||||
* [Install](compose/install.md)
|
||||
* [Usage](compose/usage.md)
|
||||
* [Commands](compose/commands.md)
|
||||
* [Compose file reference](compose/compose_file.md)
|
||||
* [Django](compose/django.md)
|
||||
* [Rails](compose/rails.md)
|
||||
* [WordPress](compose/wordpress.md)
|
||||
* [Docker Swarm](swarm/README.md)
|
||||
* [Swarm mode](swarm_mode/README.md)
|
||||
* [基本概念](swarm_mode/overview.md)
|
||||
* [创建 Swarm 集群](swarm_mode/create.md)
|
||||
* [部署服务](swarm_mode/deploy.md)
|
||||
* [使用 compose 文件](swarm_mode/stack.md)
|
||||
* [管理密钥](swarm_mode/secret.md)
|
||||
* [管理配置信息](swarm_mode/config.md)
|
||||
* [滚动升级](swarm_mode/rolling_update.md)
|
||||
* [安全](security/README.md)
|
||||
* [内核命名空间](security/kernel_ns.md)
|
||||
* [控制组](security/control_group.md)
|
||||
* [服务端防护](security/daemon_sec.md)
|
||||
* [内核能力机制](security/kernel_capability.md)
|
||||
* [其它安全特性](security/other_feature.md)
|
||||
* [总结](security/summary.md)
|
||||
* [底层实现](underly/README.md)
|
||||
* [基本架构](underly/arch.md)
|
||||
* [命名空间](underly/namespace.md)
|
||||
* [控制组](underly/cgroups.md)
|
||||
* [联合文件系统](underly/ufs.md)
|
||||
* [容器格式](underly/container_format.md)
|
||||
* [网络](underly/network.md)
|
||||
* [Etcd 项目](etcd/README.md)
|
||||
* [简介](etcd/intro.md)
|
||||
* [安装](etcd/install.md)
|
||||
* [集群](etcd/cluster.md)
|
||||
* [使用 etcdctl](etcd/etcdctl.md)
|
||||
* [Fedora CoreOS](coreos/README.md)
|
||||
* [简介](coreos/intro.md)
|
||||
* [安装](coreos/install.md)
|
||||
* [Kubernetes - 开源容器编排引擎](kubernetes/README.md)
|
||||
* [简介](kubernetes/intro.md)
|
||||
* [基本概念](kubernetes/concepts.md)
|
||||
* [架构设计](kubernetes/design.md)
|
||||
* [部署 Kubernetes](kubernetes/setup/README.md)
|
||||
* [使用 kubeadm 部署 kubernetes(CRI 使用 containerd)](kubernetes/setup/kubeadm.md)
|
||||
* [在 Docker Desktop 使用](kubernetes/setup/docker-desktop.md)
|
||||
* [一步步部署 kubernetes 集群](kubernetes/setup/systemd.md)
|
||||
* [部署 Dashboard](kubernetes/setup/dashboard.md)
|
||||
* [Kubernetes 命令行 kubectl](kubernetes/kubectl/README.md)
|
||||
* [容器与云计算](cloud/README.md)
|
||||
* [简介](cloud/intro.md)
|
||||
* [腾讯云](cloud/tencentCloud.md)
|
||||
* [阿里云](cloud/alicloud.md)
|
||||
* [亚马逊云](cloud/aws.md)
|
||||
* [小结](cloud/summary.md)
|
||||
* [实战案例 - 操作系统](cases/os/README.md)
|
||||
* [Overview](swarm_mode/overview.md)
|
||||
* [Create](swarm_mode/create.md)
|
||||
* [Deploy](swarm_mode/deploy.md)
|
||||
* [Stack](swarm_mode/stack.md)
|
||||
* [Secret](swarm_mode/secret.md)
|
||||
* [Config](swarm_mode/config.md)
|
||||
* [Rolling update](swarm_mode/rolling_update.md)
|
||||
* [Security](security/README.md)
|
||||
* [namespace](security/kernel_ns.md)
|
||||
* [cgroups](security/control_group.md)
|
||||
* [Daemon sec](security/daemon_sec.md)
|
||||
* [Kernel capability](security/kernel_capability.md)
|
||||
* [Other feature](security/other_feature.md)
|
||||
* [SUMMARY](security/summary.md)
|
||||
* [Underly](underly/README.md)
|
||||
* [Arch](underly/arch.md)
|
||||
* [namespace](underly/namespace.md)
|
||||
* [cgroups](underly/cgroups.md)
|
||||
* [ufs](underly/ufs.md)
|
||||
* [Container format](underly/container_format.md)
|
||||
* [Network](underly/network.md)
|
||||
* [Etcd](etcd/README.md)
|
||||
* [Introduction](etcd/intro.md)
|
||||
* [Install](etcd/install.md)
|
||||
* [Cluster](etcd/cluster.md)
|
||||
* [etcdctl](etcd/etcdctl.md)
|
||||
* [CoreOS](coreos/README.md)
|
||||
* [Introduction](coreos/intro.md)
|
||||
* [Tools](coreos/intro_tools.md)
|
||||
* [Kubernetes](kubernetes/README.md)
|
||||
* [Introduction](kubernetes/intro.md)
|
||||
* [Quick start](kubernetes/quickstart.md)
|
||||
* [Concepts](kubernetes/concepts.md)
|
||||
* [kubectl](kubernetes/kubectl.md)
|
||||
* [Design](kubernetes/design.md)
|
||||
* [Cloud](cloud/README.md)
|
||||
* [Introduction](cloud/intro.md)
|
||||
* [AWS](cloud/aws.md)
|
||||
* [Tencent Cloud](cloud/tencentCloud.md)
|
||||
* [Alibaba Cloud](cloud/alicloud.md)
|
||||
* [SUMMARY](cloud/summary.md)
|
||||
* [OS](cases/os/README.md)
|
||||
* [Busybox](cases/os/busybox.md)
|
||||
* [Alpine](cases/os/alpine.md)
|
||||
* [Debian Ubuntu](cases/os/debian.md)
|
||||
* [CentOS Fedora](cases/os/centos.md)
|
||||
* [本章小结](cases/os/summary.md)
|
||||
* [实战案例 - CI/CD](cases/ci/README.md)
|
||||
* [SUMMARY](cases/os/summary.md)
|
||||
* [CI/CD](cases/ci/README.md)
|
||||
* [GitHub Actions](cases/ci/actions/README.md)
|
||||
* [Drone](cases/ci/drone/README.md)
|
||||
* [部署 Drone](cases/ci/drone/install.md)
|
||||
* [在 IDE 中使用 Docker](ide/README.md)
|
||||
* [VS Code](ide/vsCode.md)
|
||||
* [podman - 下一代 Linux 容器工具](podman/README.md)
|
||||
* [附录](appendix/README.md)
|
||||
* [附录一:常见问题总结](appendix/faq/README.md)
|
||||
* [附录二:热门镜像介绍](appendix/repo/README.md)
|
||||
* [Install Drone](cases/ci/drone/install.md)
|
||||
* [Travis CI](cases/ci/travis/README.md)
|
||||
* [Docker Open Source](opensource/README.md)
|
||||
* [LinuxKit](opensource/linuxkit.md)
|
||||
* [Appendix](appendix/README.md)
|
||||
* [FAQ](appendix/faq/README.md)
|
||||
* [Sample Docker Image](appendix/repo/README.md)
|
||||
* [Ubuntu](appendix/repo/ubuntu.md)
|
||||
* [CentOS](appendix/repo/centos.md)
|
||||
* [Nginx](appendix/repo/nginx.md)
|
||||
* [PHP](appendix/repo/php.md)
|
||||
* [Node.js](appendix/repo/nodejs.md)
|
||||
* [MySQL](appendix/repo/mysql.md)
|
||||
* [WordPress](appendix/repo/wordpress.md)
|
||||
* [MongoDB](appendix/repo/mongodb.md)
|
||||
* [Redis](appendix/repo/redis.md)
|
||||
* [Minio](appendix/repo/minio.md)
|
||||
* [附录三:Docker 命令查询](appendix/command/README.md)
|
||||
* [客户端命令 - docker](appendix/command/docker.md)
|
||||
* [服务端命令 - dockerd](appendix/command/dockerd.md)
|
||||
* [附录四:Dockerfile 最佳实践](appendix/best_practices.md)
|
||||
* [附录五:如何调试 Docker](appendix/debug.md)
|
||||
* [附录六:资源链接](appendix/resources.md)
|
||||
* [Node.js](appendix/repo/nodejs.md)
|
||||
* [Docker commands](appendix/command/README.md)
|
||||
* [Docker debug](appendix/debug.md)
|
||||
* [Resources](appendix/resources.md)
|
||||
|
||||
BIN
_images/docker_primer3.png
Normal file
|
After Width: | Height: | Size: 52 KiB |
|
Before Width: | Height: | Size: 97 KiB |
15
advanced_network/README.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# 高级网络配置
|
||||
|
||||
>注意:本章属于 `Docker` 高级配置,如果您是初学者,您可以暂时跳过本章节,直接学习 [Docker Compose](../compose) 一节。
|
||||
|
||||
本章将介绍 Docker 的一些高级网络配置和选项。
|
||||
|
||||
当 Docker 启动时,会自动在主机上创建一个 `docker0` 虚拟网桥,实际上是 Linux 的一个 bridge,可以理解为一个软件交换机。它会在挂载到它的网口之间进行转发。
|
||||
|
||||
同时,Docker 随机分配一个本地未占用的私有网段(在 [RFC1918](https://tools.ietf.org/html/rfc1918) 中定义)中的一个地址给 `docker0` 接口。比如典型的 `172.17.42.1`,掩码为 `255.255.0.0`。此后启动的容器内的网口也会自动分配一个同一网段(`172.17.0.0/16`)的地址。
|
||||
|
||||
当创建一个 Docker 容器的时候,同时会创建了一对 `veth pair` 接口(当数据包发送到一个接口时,另外一个接口也可以收到相同的数据包)。这对接口一端在容器内,即 `eth0`;另一端在本地并被挂载到 `docker0` 网桥,名称以 `veth` 开头(例如 `vethAQI2QT`)。通过这种方式,主机可以跟容器通信,容器之间也可以相互通信。Docker 就创建了在主机和所有容器之间一个虚拟共享网络。
|
||||
|
||||

|
||||
|
||||
接下来的部分将介绍在一些场景中,Docker 所有的网络定制配置。以及通过 Linux 命令来调整、补充、甚至替换 Docker 默认的网络配置。
|
||||
|
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 48 KiB |
55
advanced_network/access_control.md
Normal file
@@ -0,0 +1,55 @@
|
||||
## 容器访问控制
|
||||
容器的访问控制,主要通过 Linux 上的 `iptables` 防火墙来进行管理和实现。`iptables` 是 Linux 上默认的防火墙软件,在大部分发行版中都自带。
|
||||
|
||||
### 容器访问外部网络
|
||||
容器要想访问外部网络,需要本地系统的转发支持。在Linux 系统中,检查转发是否打开。
|
||||
|
||||
```bash
|
||||
$sysctl net.ipv4.ip_forward
|
||||
net.ipv4.ip_forward = 1
|
||||
```
|
||||
如果为 0,说明没有开启转发,则需要手动打开。
|
||||
```bash
|
||||
$sysctl -w net.ipv4.ip_forward=1
|
||||
```
|
||||
如果在启动 Docker 服务的时候设定 `--ip-forward=true`, Docker 就会自动设定系统的 `ip_forward` 参数为 1。
|
||||
|
||||
### 容器之间访问
|
||||
容器之间相互访问,需要两方面的支持。
|
||||
* 容器的网络拓扑是否已经互联。默认情况下,所有容器都会被连接到 `docker0` 网桥上。
|
||||
* 本地系统的防火墙软件 -- `iptables` 是否允许通过。
|
||||
|
||||
#### 访问所有端口
|
||||
当启动 Docker 服务(即 dockerd)的时候,默认会添加一条转发策略到本地主机 iptables 的 FORWARD 链上。策略为通过(`ACCEPT`)还是禁止(`DROP`)取决于配置`--icc=true`(缺省值)还是 `--icc=false`。当然,如果手动指定 `--iptables=false` 则不会添加 `iptables` 规则。
|
||||
|
||||
可见,默认情况下,不同容器之间是允许网络互通的。如果为了安全考虑,可以在 `/etc/docker/daemon.json` 文件中配置 `{"icc": false}` 来禁止它。
|
||||
|
||||
#### 访问指定端口
|
||||
在通过 `-icc=false` 关闭网络访问后,还可以通过 `--link=CONTAINER_NAME:ALIAS` 选项来访问容器的开放端口。
|
||||
|
||||
例如,在启动 Docker 服务时,可以同时使用 `icc=false --iptables=true` 参数来关闭允许相互的网络访问,并让 Docker 可以修改系统中的 `iptables` 规则。
|
||||
|
||||
此时,系统中的 `iptables` 规则可能是类似
|
||||
```bash
|
||||
$ sudo iptables -nL
|
||||
...
|
||||
Chain FORWARD (policy ACCEPT)
|
||||
target prot opt source destination
|
||||
DROP all -- 0.0.0.0/0 0.0.0.0/0
|
||||
...
|
||||
```
|
||||
|
||||
之后,启动容器(`docker run`)时使用 `--link=CONTAINER_NAME:ALIAS` 选项。Docker 会在 `iptable` 中为 两个容器分别添加一条 `ACCEPT` 规则,允许相互访问开放的端口(取决于 `Dockerfile` 中的 `EXPOSE` 指令)。
|
||||
|
||||
当添加了 `--link=CONTAINER_NAME:ALIAS` 选项后,添加了 `iptables` 规则。
|
||||
```bash
|
||||
$ sudo iptables -nL
|
||||
...
|
||||
Chain FORWARD (policy ACCEPT)
|
||||
target prot opt source destination
|
||||
ACCEPT tcp -- 172.17.0.2 172.17.0.3 tcp spt:80
|
||||
ACCEPT tcp -- 172.17.0.3 172.17.0.2 tcp dpt:80
|
||||
DROP all -- 0.0.0.0/0 0.0.0.0/0
|
||||
```
|
||||
|
||||
注意:`--link=CONTAINER_NAME:ALIAS` 中的 `CONTAINER_NAME` 目前必须是 Docker 分配的名字,或使用 `--name` 参数指定的名字。主机名则不会被识别。
|
||||
45
advanced_network/bridge.md
Normal file
@@ -0,0 +1,45 @@
|
||||
## 自定义网桥
|
||||
|
||||
除了默认的 `docker0` 网桥,用户也可以指定网桥来连接各个容器。
|
||||
|
||||
在启动 Docker 服务的时候,使用 `-b BRIDGE`或`--bridge=BRIDGE` 来指定使用的网桥。
|
||||
|
||||
如果服务已经运行,那需要先停止服务,并删除旧的网桥。
|
||||
|
||||
```bash
|
||||
$ sudo systemctl stop docker
|
||||
$ sudo ip link set dev docker0 down
|
||||
$ sudo brctl delbr docker0
|
||||
```
|
||||
|
||||
然后创建一个网桥 `bridge0`。
|
||||
|
||||
```bash
|
||||
$ sudo brctl addbr bridge0
|
||||
$ sudo ip addr add 192.168.5.1/24 dev bridge0
|
||||
$ sudo ip link set dev bridge0 up
|
||||
```
|
||||
|
||||
查看确认网桥创建并启动。
|
||||
|
||||
```bash
|
||||
$ ip addr show bridge0
|
||||
4: bridge0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state UP group default
|
||||
link/ether 66:38:d0:0d:76:18 brd ff:ff:ff:ff:ff:ff
|
||||
inet 192.168.5.1/24 scope global bridge0
|
||||
valid_lft forever preferred_lft forever
|
||||
```
|
||||
|
||||
在 Docker 配置文件 `/etc/docker/daemon.json` 中添加如下内容,即可将 Docker 默认桥接到创建的网桥上。
|
||||
|
||||
```json
|
||||
{
|
||||
"bridge": "bridge0",
|
||||
}
|
||||
```
|
||||
|
||||
启动 Docker 服务。
|
||||
|
||||
新建一个容器,可以看到它已经桥接到了 `bridge0` 上。
|
||||
|
||||
可以继续用 `brctl show` 命令查看桥接的信息。另外,在容器中可以使用 `ip addr` 和 `ip route` 命令来查看 IP 地址配置和路由信息。
|
||||
5
advanced_network/config_file.md
Normal file
@@ -0,0 +1,5 @@
|
||||
## 编辑网络配置文件
|
||||
|
||||
Docker 1.2.0 开始支持在运行中的容器里编辑 `/etc/hosts`, `/etc/hostname` 和 `/etc/resolv.conf` 文件。
|
||||
|
||||
但是这些修改是临时的,只在运行的容器中保留,容器终止或重启后并不会被保存下来,也不会被 `docker commit` 提交。
|
||||
37
advanced_network/docker0.md
Normal file
@@ -0,0 +1,37 @@
|
||||
## 配置 docker0 网桥
|
||||
|
||||
Docker 服务默认会创建一个 `docker0` 网桥(其上有一个 `docker0` 内部接口),它在内核层连通了其他的物理或虚拟网卡,这就将所有容器和本地主机都放到同一个物理网络。
|
||||
|
||||
Docker 默认指定了 `docker0` 接口 的 IP 地址和子网掩码,让主机和容器之间可以通过网桥相互通信,它还给出了 MTU(接口允许接收的最大传输单元),通常是 1500 Bytes,或宿主主机网络路由上支持的默认值。这些值都可以在服务启动的时候进行配置。
|
||||
|
||||
* `--bip=CIDR` IP 地址加掩码格式,例如 192.168.1.5/24
|
||||
* `--mtu=BYTES` 覆盖默认的 Docker mtu 配置
|
||||
|
||||
也可以在配置文件中配置 DOCKER_OPTS,然后重启服务。
|
||||
|
||||
由于目前 Docker 网桥是 Linux 网桥,用户可以使用 `brctl show` 来查看网桥和端口连接信息。
|
||||
|
||||
```bash
|
||||
$ sudo brctl show
|
||||
bridge name bridge id STP enabled interfaces
|
||||
docker0 8000.3a1d7362b4ee no veth65f9
|
||||
vethdda6
|
||||
```
|
||||
*注:`brctl` 命令在 Debian、Ubuntu 中可以使用 `sudo apt-get install bridge-utils` 来安装。
|
||||
|
||||
|
||||
每次创建一个新容器的时候,Docker 从可用的地址段中选择一个空闲的 IP 地址分配给容器的 eth0 端口。使用本地主机上 `docker0` 接口的 IP 作为所有容器的默认网关。
|
||||
|
||||
```bash
|
||||
$ sudo docker run -i -t --rm base /bin/bash
|
||||
$ ip addr show eth0
|
||||
24: eth0: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
|
||||
link/ether 32:6f:e0:35:57:91 brd ff:ff:ff:ff:ff:ff
|
||||
inet 172.17.0.3/16 scope global eth0
|
||||
valid_lft forever preferred_lft forever
|
||||
inet6 fe80::306f:e0ff:fe35:5791/64 scope link
|
||||
valid_lft forever preferred_lft forever
|
||||
$ ip route
|
||||
default via 172.17.42.1 dev eth0
|
||||
172.17.0.0/16 dev eth0 proto kernel scope link src 172.17.0.3
|
||||
```
|
||||
8
advanced_network/example.md
Normal file
@@ -0,0 +1,8 @@
|
||||
## 工具和示例
|
||||
在介绍自定义网络拓扑之前,你可能会对一些外部工具和例子感兴趣:
|
||||
|
||||
### pipework
|
||||
Jérôme Petazzoni 编写了一个叫 [pipework](https://github.com/jpetazzo/pipework) 的 shell 脚本,可以帮助用户在比较复杂的场景中完成容器的连接。
|
||||
|
||||
### playground
|
||||
Brandon Rhodes 创建了一个提供完整的 Docker 容器网络拓扑管理的 [Python库](https://github.com/brandon-rhodes/fopnp/tree/m/playground),包括路由、NAT 防火墙;以及一些提供 HTTP, SMTP, POP, IMAP, Telnet, SSH, FTP 的服务器。
|
||||
1
advanced_network/how_connect.md
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
57
advanced_network/port_mapping.md
Normal file
@@ -0,0 +1,57 @@
|
||||
## 映射容器端口到宿主主机的实现
|
||||
|
||||
默认情况下,容器可以主动访问到外部网络的连接,但是外部网络无法访问到容器。
|
||||
|
||||
### 容器访问外部实现
|
||||
|
||||
容器所有到外部网络的连接,源地址都会被 NAT 成本地系统的 IP 地址。这是使用 `iptables` 的源地址伪装操作实现的。
|
||||
|
||||
查看主机的 NAT 规则。
|
||||
|
||||
```bash
|
||||
$ sudo iptables -t nat -nL
|
||||
...
|
||||
Chain POSTROUTING (policy ACCEPT)
|
||||
target prot opt source destination
|
||||
MASQUERADE all -- 172.17.0.0/16 !172.17.0.0/16
|
||||
...
|
||||
```
|
||||
|
||||
其中,上述规则将所有源地址在 `172.17.0.0/16` 网段,目标地址为其他网段(外部网络)的流量动态伪装为从系统网卡发出。MASQUERADE 跟传统 SNAT 的好处是它能动态从网卡获取地址。
|
||||
|
||||
### 外部访问容器实现
|
||||
|
||||
容器允许外部访问,可以在 `docker run` 时候通过 `-p` 或 `-P` 参数来启用。
|
||||
|
||||
不管用那种办法,其实也是在本地的 `iptable` 的 nat 表中添加相应的规则。
|
||||
|
||||
使用 `-P` 时:
|
||||
|
||||
```bash
|
||||
$ iptables -t nat -nL
|
||||
...
|
||||
Chain DOCKER (2 references)
|
||||
target prot opt source destination
|
||||
DNAT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:49153 to:172.17.0.2:80
|
||||
```
|
||||
|
||||
使用 `-p 80:80` 时:
|
||||
|
||||
```bash
|
||||
$ iptables -t nat -nL
|
||||
Chain DOCKER (2 references)
|
||||
target prot opt source destination
|
||||
DNAT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 to:172.17.0.2:80
|
||||
```
|
||||
|
||||
注意:
|
||||
|
||||
* 这里的规则映射了 `0.0.0.0`,意味着将接受主机来自所有接口的流量。用户可以通过 `-p IP:host_port:container_port` 或 `-p IP::port` 来指定允许访问容器的主机上的 IP、接口等,以制定更严格的规则。
|
||||
|
||||
* 如果希望永久绑定到某个固定的 IP 地址,可以在 Docker 配置文件 `/etc/docker/daemon.json` 中添加如下内容。
|
||||
|
||||
```json
|
||||
{
|
||||
"ip": "0.0.0.0"
|
||||
}
|
||||
```
|
||||
45
advanced_network/ptp.md
Normal file
@@ -0,0 +1,45 @@
|
||||
## 示例:创建一个点到点连接
|
||||
默认情况下,Docker 会将所有容器连接到由 `docker0` 提供的虚拟子网中。
|
||||
|
||||
用户有时候需要两个容器之间可以直连通信,而不用通过主机网桥进行桥接。
|
||||
|
||||
解决办法很简单:创建一对 `peer` 接口,分别放到两个容器中,配置成点到点链路类型即可。
|
||||
|
||||
首先启动 2 个容器:
|
||||
```bash
|
||||
$ docker run -i -t --rm --net=none base /bin/bash
|
||||
root@1f1f4c1f931a:/#
|
||||
$ docker run -i -t --rm --net=none base /bin/bash
|
||||
root@12e343489d2f:/#
|
||||
```
|
||||
|
||||
找到进程号,然后创建网络命名空间的跟踪文件。
|
||||
```bash
|
||||
$ docker inspect -f '{{.State.Pid}}' 1f1f4c1f931a
|
||||
2989
|
||||
$ docker inspect -f '{{.State.Pid}}' 12e343489d2f
|
||||
3004
|
||||
$ sudo mkdir -p /var/run/netns
|
||||
$ sudo ln -s /proc/2989/ns/net /var/run/netns/2989
|
||||
$ sudo ln -s /proc/3004/ns/net /var/run/netns/3004
|
||||
```
|
||||
|
||||
创建一对 `peer` 接口,然后配置路由
|
||||
```bash
|
||||
$ sudo ip link add A type veth peer name B
|
||||
|
||||
$ sudo ip link set A netns 2989
|
||||
$ sudo ip netns exec 2989 ip addr add 10.1.1.1/32 dev A
|
||||
$ sudo ip netns exec 2989 ip link set A up
|
||||
$ sudo ip netns exec 2989 ip route add 10.1.1.2/32 dev A
|
||||
|
||||
$ sudo ip link set B netns 3004
|
||||
$ sudo ip netns exec 3004 ip addr add 10.1.1.2/32 dev B
|
||||
$ sudo ip netns exec 3004 ip link set B up
|
||||
$ sudo ip netns exec 3004 ip route add 10.1.1.1/32 dev B
|
||||
```
|
||||
现在这 2 个容器就可以相互 ping 通,并成功建立连接。点到点链路不需要子网和子网掩码。
|
||||
|
||||
此外,也可以不指定 `--net=none` 来创建点到点链路。这样容器还可以通过原先的网络来通信。
|
||||
|
||||
利用类似的办法,可以创建一个只跟主机通信的容器。但是一般情况下,更推荐使用 `--icc=false` 来关闭容器之间的通信。
|
||||
26
advanced_network/quick_guide.md
Normal file
@@ -0,0 +1,26 @@
|
||||
## 快速配置指南
|
||||
|
||||
下面是一个跟 Docker 网络相关的命令列表。
|
||||
|
||||
其中有些命令选项只有在 Docker 服务启动的时候才能配置,而且不能马上生效。
|
||||
|
||||
* `-b BRIDGE` 或 `--bridge=BRIDGE` 指定容器挂载的网桥
|
||||
* `--bip=CIDR` 定制 docker0 的掩码
|
||||
* `-H SOCKET...` 或 `--host=SOCKET...` Docker 服务端接收命令的通道
|
||||
* `--icc=true|false` 是否支持容器之间进行通信
|
||||
* `--ip-forward=true|false` 请看下文容器之间的通信
|
||||
* `--iptables=true|false` 是否允许 Docker 添加 iptables 规则
|
||||
* `--mtu=BYTES` 容器网络中的 MTU
|
||||
|
||||
下面2个命令选项既可以在启动服务时指定,也可以在启动容器时指定。在 Docker 服务启动的时候指定则会成为默认值,后面执行 `docker run` 时可以覆盖设置的默认值。
|
||||
|
||||
* `--dns=IP_ADDRESS...` 使用指定的DNS服务器
|
||||
* `--dns-search=DOMAIN...` 指定DNS搜索域
|
||||
|
||||
最后这些选项只有在 `docker run` 执行时使用,因为它是针对容器的特性内容。
|
||||
|
||||
* `-h HOSTNAME` 或 `--hostname=HOSTNAME` 配置容器主机名
|
||||
* `--link=CONTAINER_NAME:ALIAS` 添加到另一个容器的连接
|
||||
* `--net=bridge|none|container:NAME_or_ID|host` 配置容器的桥接模式
|
||||
* `-p SPEC` 或 `--publish=SPEC` 映射容器端口到宿主主机
|
||||
* `-P or --publish-all=true|false` 映射容器所有端口到宿主主机
|
||||
@@ -1,344 +1 @@
|
||||
# Dockerfile 最佳实践
|
||||
|
||||
本附录是笔者对 Docker 官方文档中 [Best practices for writing Dockerfiles](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/) 的理解与翻译。
|
||||
|
||||
## 一般性的指南和建议
|
||||
|
||||
### 容器应该是短暂的
|
||||
|
||||
通过 `Dockerfile` 构建的镜像所启动的容器应该尽可能短暂(生命周期短)。「短暂」意味着可以停止和销毁容器,并且创建一个新容器并部署好所需的设置和配置工作量应该是极小的。
|
||||
|
||||
### 使用 `.dockerignore` 文件
|
||||
|
||||
使用 `Dockerfile` 构建镜像时最好是将 `Dockerfile` 放置在一个新建的空目录下。然后将构建镜像所需要的文件添加到该目录中。为了提高构建镜像的效率,你可以在目录下新建一个 `.dockerignore` 文件来指定要忽略的文件和目录。`.dockerignore` 文件的排除模式语法和 Git 的 `.gitignore` 文件相似。
|
||||
|
||||
### 使用多阶段构建
|
||||
|
||||
在 `Docker 17.05` 以上版本中,你可以使用 [多阶段构建](../image/multistage-builds.md) 来减少所构建镜像的大小。
|
||||
|
||||
### 避免安装不必要的包
|
||||
|
||||
为了降低复杂性、减少依赖、减小文件大小、节约构建时间,你应该避免安装任何不必要的包。例如,不要在数据库镜像中包含一个文本编辑器。
|
||||
|
||||
### 一个容器只运行一个进程
|
||||
|
||||
应该保证在一个容器中只运行一个进程。将多个应用解耦到不同容器中,保证了容器的横向扩展和复用。例如 web 应用应该包含三个容器:web应用、数据库、缓存。
|
||||
|
||||
如果容器互相依赖,你可以使用 [Docker 自定义网络](../network/README.md) 来把这些容器连接起来。
|
||||
|
||||
### 镜像层数尽可能少
|
||||
|
||||
你需要在 `Dockerfile` 可读性(也包括长期的可维护性)和减少层数之间做一个平衡。
|
||||
|
||||
### 将多行参数排序
|
||||
|
||||
将多行参数按字母顺序排序(比如要安装多个包时)。这可以帮助你避免重复包含同一个包,更新包列表时也更容易。也便于 `PRs` 阅读和审查。建议在反斜杠符号 `\` 之前添加一个空格,以增加可读性。
|
||||
|
||||
下面是来自 `buildpack-deps` 镜像的例子:
|
||||
|
||||
```docker
|
||||
RUN apt-get update && apt-get install -y \
|
||||
bzr \
|
||||
cvs \
|
||||
git \
|
||||
mercurial \
|
||||
subversion
|
||||
```
|
||||
|
||||
### 构建缓存
|
||||
|
||||
在镜像的构建过程中,Docker 会遍历 `Dockerfile` 文件中的指令,然后按顺序执行。在执行每条指令之前,Docker 都会在缓存中查找是否已经存在可重用的镜像,如果有就使用现存的镜像,不再重复创建。如果你不想在构建过程中使用缓存,你可以在 `docker build` 命令中使用 `--no-cache=true` 选项。
|
||||
|
||||
但是,如果你想在构建的过程中使用缓存,你得明白什么时候会,什么时候不会找到匹配的镜像,遵循的基本规则如下:
|
||||
|
||||
* 从一个基础镜像开始(`FROM` 指令指定),下一条指令将和该基础镜像的所有子镜像进行匹配,检查这些子镜像被创建时使用的指令是否和被检查的指令完全一样。如果不是,则缓存失效。
|
||||
* 在大多数情况下,只需要简单地对比 `Dockerfile` 中的指令和子镜像。然而,有些指令需要更多的检查和解释。
|
||||
* 对于 `ADD` 和 `COPY` 指令,镜像中对应文件的内容也会被检查,每个文件都会计算出一个校验和。文件的最后修改时间和最后访问时间不会纳入校验。在缓存的查找过程中,会将这些校验和和已存在镜像中的文件校验和进行对比。如果文件有任何改变,比如内容和元数据,则缓存失效。
|
||||
* 除了 `ADD` 和 `COPY` 指令,缓存匹配过程不会查看临时容器中的文件来决定缓存是否匹配。例如,当执行完 `RUN apt-get -y update` 指令后,容器中一些文件被更新,但 Docker 不会检查这些文件。这种情况下,只有指令字符串本身被用来匹配缓存。
|
||||
|
||||
一旦缓存失效,所有后续的 `Dockerfile` 指令都将产生新的镜像,缓存不会被使用。
|
||||
|
||||
## Dockerfile 指令
|
||||
|
||||
下面针对 `Dockerfile` 中各种指令的最佳编写方式给出建议。
|
||||
|
||||
### FROM
|
||||
|
||||
尽可能使用当前官方仓库作为你构建镜像的基础。推荐使用 [Alpine](https://hub.docker.com/_/alpine/) 镜像,因为它被严格控制并保持最小尺寸(目前小于 5 MB),但它仍然是一个完整的发行版。
|
||||
|
||||
### LABEL
|
||||
|
||||
你可以给镜像添加标签来帮助组织镜像、记录许可信息、辅助自动化构建等。每个标签一行,由 `LABEL` 开头加上一个或多个标签对。下面的示例展示了各种不同的可能格式。`#` 开头的行是注释内容。
|
||||
|
||||
>注意:如果你的字符串中包含空格,必须将字符串放入引号中或者对空格使用转义。如果字符串内容本身就包含引号,必须对引号使用转义。
|
||||
|
||||
```docker
|
||||
# Set one or more individual labels
|
||||
LABEL com.example.version="0.0.1-beta"
|
||||
|
||||
LABEL vendor="ACME Incorporated"
|
||||
|
||||
LABEL com.example.release-date="2015-02-12"
|
||||
|
||||
LABEL com.example.version.is-production=""
|
||||
```
|
||||
|
||||
一个镜像可以包含多个标签,但建议将多个标签放入到一个 `LABEL` 指令中。
|
||||
|
||||
```docker
|
||||
# Set multiple labels at once, using line-continuation characters to break long lines
|
||||
LABEL vendor=ACME\ Incorporated \
|
||||
com.example.is-beta= \
|
||||
com.example.is-production="" \
|
||||
com.example.version="0.0.1-beta" \
|
||||
com.example.release-date="2015-02-12"
|
||||
```
|
||||
|
||||
关于标签可以接受的键值对,参考 [Understanding object labels](https://docs.docker.com/config/labels-custom-metadata/)。关于查询标签信息,参考 [Managing labels on objects](https://docs.docker.com/config/labels-custom-metadata/)。
|
||||
|
||||
### RUN
|
||||
|
||||
为了保持 `Dockerfile` 文件的可读性,可理解性,以及可维护性,建议将长的或复杂的 `RUN` 指令用反斜杠 `\` 分割成多行。
|
||||
|
||||
#### apt-get
|
||||
|
||||
`RUN` 指令最常见的用法是安装包用的 `apt-get`。因为 `RUN apt-get` 指令会安装包,所以有几个问题需要注意。
|
||||
|
||||
不要使用 `RUN apt-get upgrade` 或 `dist-upgrade`,因为许多基础镜像中的「必须」包不会在一个非特权容器中升级。如果基础镜像中的某个包过时了,你应该联系它的维护者。如果你确定某个特定的包,比如 `foo`,需要升级,使用 `apt-get install -y foo` 就行,该指令会自动升级 `foo` 包。
|
||||
|
||||
永远将 `RUN apt-get update` 和 `apt-get install` 组合成一条 `RUN` 声明,例如:
|
||||
|
||||
```docker
|
||||
RUN apt-get update && apt-get install -y \
|
||||
package-bar \
|
||||
package-baz \
|
||||
package-foo
|
||||
```
|
||||
|
||||
将 `apt-get update` 放在一条单独的 `RUN` 声明中会导致缓存问题以及后续的 `apt-get install` 失败。比如,假设你有一个 `Dockerfile` 文件:
|
||||
|
||||
```docker
|
||||
FROM ubuntu:24.04
|
||||
|
||||
RUN apt-get update
|
||||
|
||||
RUN apt-get install -y curl
|
||||
```
|
||||
|
||||
构建镜像后,所有的层都在 Docker 的缓存中。假设你后来又修改了其中的 `apt-get install` 添加了一个包:
|
||||
|
||||
```docker
|
||||
FROM ubuntu:24.04
|
||||
|
||||
RUN apt-get update
|
||||
|
||||
RUN apt-get install -y curl nginx
|
||||
```
|
||||
|
||||
Docker 发现修改后的 `RUN apt-get update` 指令和之前的完全一样。所以,`apt-get update` 不会执行,而是使用之前的缓存镜像。因为 `apt-get update` 没有运行,后面的 `apt-get install` 可能安装的是过时的 `curl` 和 `nginx` 版本。
|
||||
|
||||
使用 `RUN apt-get update && apt-get install -y` 可以确保你的 Dockerfiles 每次安装的都是包的最新的版本,而且这个过程不需要进一步的编码或额外干预。这项技术叫作 `cache busting`。你也可以显示指定一个包的版本号来达到 `cache-busting`,这就是所谓的固定版本,例如:
|
||||
|
||||
```docker
|
||||
RUN apt-get update && apt-get install -y \
|
||||
package-bar \
|
||||
package-baz \
|
||||
package-foo=1.3.*
|
||||
```
|
||||
|
||||
固定版本会迫使构建过程检索特定的版本,而不管缓存中有什么。这项技术也可以减少因所需包中未预料到的变化而导致的失败。
|
||||
|
||||
下面是一个 `RUN` 指令的示例模板,展示了所有关于 `apt-get` 的建议。
|
||||
|
||||
```docker
|
||||
RUN apt-get update && apt-get install -y \
|
||||
aufs-tools \
|
||||
automake \
|
||||
build-essential \
|
||||
curl \
|
||||
dpkg-sig \
|
||||
libcap-dev \
|
||||
libsqlite3-dev \
|
||||
mercurial \
|
||||
reprepro \
|
||||
ruby1.9.1 \
|
||||
ruby1.9.1-dev \
|
||||
s3cmd=1.1.* \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
```
|
||||
|
||||
其中 `s3cmd` 指令指定了一个版本号 `1.1.*`。如果之前的镜像使用的是更旧的版本,指定新的版本会导致 `apt-get update` 缓存失效并确保安装的是新版本。
|
||||
|
||||
另外,清理掉 apt 缓存 `var/lib/apt/lists` 可以减小镜像大小。因为 `RUN` 指令的开头为 `apt-get update`,包缓存总是会在 `apt-get install` 之前刷新。
|
||||
|
||||
> 注意:官方的 Debian 和 Ubuntu 镜像会自动运行 apt-get clean,所以不需要显式的调用 apt-get clean。
|
||||
|
||||
### CMD
|
||||
|
||||
`CMD` 指令用于执行目标镜像中包含的软件,可以包含参数。`CMD` 大多数情况下都应该以 `CMD ["executable", "param1", "param2"...]` 的形式使用。因此,如果创建镜像的目的是为了部署某个服务(比如 `Apache`),你可能会执行类似于 `CMD ["apache2", "-DFOREGROUND"]` 形式的命令。我们建议任何服务镜像都使用这种形式的命令。
|
||||
|
||||
多数情况下,`CMD` 都需要一个交互式的 `shell` (bash, Python, perl 等),例如 `CMD ["perl", "-de0"]`,或者 `CMD ["PHP", "-a"]`。使用这种形式意味着,当你执行类似 `docker run -it python` 时,你会进入一个准备好的 `shell` 中。`CMD` 应该在极少的情况下才能以 `CMD ["param", "param"]` 的形式与 `ENTRYPOINT` 协同使用,除非你和你的镜像使用者都对 `ENTRYPOINT` 的工作方式十分熟悉。
|
||||
|
||||
### EXPOSE
|
||||
|
||||
`EXPOSE` 指令用于指定容器将要监听的端口。因此,你应该为你的应用程序使用常见的端口。例如,提供 `Apache` web 服务的镜像应该使用 `EXPOSE 80`,而提供 `MongoDB` 服务的镜像使用 `EXPOSE 27017`。
|
||||
|
||||
对于外部访问,用户可以在执行 `docker run` 时使用一个标志来指示如何将指定的端口映射到所选择的端口。
|
||||
|
||||
### ENV
|
||||
|
||||
为了方便新程序运行,你可以使用 `ENV` 来为容器中安装的程序更新 `PATH` 环境变量。例如使用 `ENV PATH /usr/local/nginx/bin:$PATH` 来确保 `CMD ["nginx"]` 能正确运行。
|
||||
|
||||
`ENV` 指令也可用于为你想要容器化的服务提供必要的环境变量,比如 Postgres 需要的 `PGDATA`。
|
||||
|
||||
最后,`ENV` 也能用于设置常见的版本号,比如下面的示例:
|
||||
|
||||
```docker
|
||||
ENV PG_MAJOR 9.3
|
||||
|
||||
ENV PG_VERSION 9.3.4
|
||||
|
||||
RUN curl -SL http://example.com/postgres-$PG_VERSION.tar.xz | tar -xJC /usr/src/postgress && …
|
||||
|
||||
ENV PATH /usr/local/postgres-$PG_MAJOR/bin:$PATH
|
||||
```
|
||||
|
||||
类似于程序中的常量,这种方法可以让你只需改变 `ENV` 指令来自动的改变容器中的软件版本。
|
||||
|
||||
### ADD 和 COPY
|
||||
|
||||
虽然 `ADD` 和 `COPY` 功能类似,但一般优先使用 `COPY`。因为它比 `ADD` 更透明。`COPY` 只支持简单将本地文件拷贝到容器中,而 `ADD` 有一些并不明显的功能(比如本地 tar 提取和远程 URL 支持)。因此,`ADD` 的最佳用例是将本地 tar 文件自动提取到镜像中,例如 `ADD rootfs.tar.xz`。
|
||||
|
||||
如果你的 `Dockerfile` 有多个步骤需要使用上下文中不同的文件。单独 `COPY` 每个文件,而不是一次性的 `COPY` 所有文件,这将保证每个步骤的构建缓存只在特定的文件变化时失效。例如:
|
||||
|
||||
```docker
|
||||
COPY requirements.txt /tmp/
|
||||
|
||||
RUN pip install --requirement /tmp/requirements.txt
|
||||
|
||||
COPY . /tmp/
|
||||
```
|
||||
|
||||
如果将 `COPY . /tmp/` 放置在 `RUN` 指令之前,只要 `.` 目录中任何一个文件变化,都会导致后续指令的缓存失效。
|
||||
|
||||
为了让镜像尽量小,最好不要使用 `ADD` 指令从远程 URL 获取包,而是使用 `curl` 和 `wget`。这样你可以在文件提取完之后删掉不再需要的文件来避免在镜像中额外添加一层。比如尽量避免下面的用法:
|
||||
|
||||
```docker
|
||||
ADD http://example.com/big.tar.xz /usr/src/things/
|
||||
|
||||
RUN tar -xJf /usr/src/things/big.tar.xz -C /usr/src/things
|
||||
|
||||
RUN make -C /usr/src/things all
|
||||
```
|
||||
|
||||
而是应该使用下面这种方法:
|
||||
|
||||
```docker
|
||||
RUN mkdir -p /usr/src/things \
|
||||
&& curl -SL http://example.com/big.tar.xz \
|
||||
| tar -xJC /usr/src/things \
|
||||
&& make -C /usr/src/things all
|
||||
```
|
||||
|
||||
上面使用的管道操作,所以没有中间文件需要删除。
|
||||
|
||||
对于其他不需要 `ADD` 的自动提取功能的文件或目录,你应该使用 `COPY`。
|
||||
|
||||
### ENTRYPOINT
|
||||
|
||||
`ENTRYPOINT` 的最佳用处是设置镜像的主命令,允许将镜像当成命令本身来运行(用 `CMD` 提供默认选项)。
|
||||
|
||||
例如,下面的示例镜像提供了命令行工具 `s3cmd`:
|
||||
|
||||
```docker
|
||||
ENTRYPOINT ["s3cmd"]
|
||||
|
||||
CMD ["--help"]
|
||||
```
|
||||
|
||||
现在直接运行该镜像创建的容器会显示命令帮助:
|
||||
|
||||
```bash
|
||||
$ docker run s3cmd
|
||||
```
|
||||
|
||||
或者提供正确的参数来执行某个命令:
|
||||
|
||||
```bash
|
||||
$ docker run s3cmd ls s3://mybucket
|
||||
```
|
||||
|
||||
这样镜像名可以当成命令行的参考。
|
||||
|
||||
`ENTRYPOINT` 指令也可以结合一个辅助脚本使用,和前面命令行风格类似,即使启动工具需要不止一个步骤。
|
||||
|
||||
例如,`Postgres` 官方镜像使用下面的脚本作为 `ENTRYPOINT`:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
if [ "$1" = 'postgres' ]; then
|
||||
chown -R postgres "$PGDATA"
|
||||
|
||||
if [ -z "$(ls -A "$PGDATA")" ]; then
|
||||
gosu postgres initdb
|
||||
fi
|
||||
|
||||
exec gosu postgres "$@"
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
```
|
||||
|
||||
>注意:该脚本使用了 Bash 的内置命令 exec,所以最后运行的进程就是容器的 PID 为 1 的进程。这样,进程就可以接收到任何发送给容器的 Unix 信号了。
|
||||
|
||||
该辅助脚本被拷贝到容器,并在容器启动时通过 `ENTRYPOINT` 执行:
|
||||
|
||||
```docker
|
||||
COPY ./docker-entrypoint.sh /
|
||||
|
||||
ENTRYPOINT ["/docker-entrypoint.sh"]
|
||||
```
|
||||
|
||||
该脚本可以让用户用几种不同的方式和 `Postgres` 交互。
|
||||
|
||||
你可以很简单地启动 `Postgres`:
|
||||
|
||||
```bash
|
||||
$ docker run postgres
|
||||
```
|
||||
|
||||
也可以执行 `Postgres` 并传递参数:
|
||||
|
||||
```bash
|
||||
$ docker run postgres postgres --help
|
||||
```
|
||||
|
||||
最后,你还可以启动另外一个完全不同的工具,比如 `Bash`:
|
||||
|
||||
```bash
|
||||
$ docker run --rm -it postgres bash
|
||||
```
|
||||
|
||||
### VOLUME
|
||||
|
||||
`VOLUME` 指令用于暴露任何数据库存储文件,配置文件,或容器创建的文件和目录。强烈建议使用 `VOLUME` 来管理镜像中的可变部分和用户可以改变的部分。
|
||||
|
||||
### USER
|
||||
|
||||
如果某个服务不需要特权执行,建议使用 `USER` 指令切换到非 root 用户。先在 `Dockerfile` 中使用类似 `RUN groupadd -r postgres && useradd -r -g postgres postgres` 的指令创建用户和用户组。
|
||||
|
||||
>注意:在镜像中,用户和用户组每次被分配的 UID/GID 都是不确定的,下次重新构建镜像时被分配到的 UID/GID 可能会不一样。如果要依赖确定的 UID/GID,你应该显式的指定一个 UID/GID。
|
||||
|
||||
你应该避免使用 `sudo`,因为它不可预期的 TTY 和信号转发行为可能造成的问题比它能解决的问题还多。如果你真的需要和 `sudo` 类似的功能(例如,以 root 权限初始化某个守护进程,以非 root 权限执行它),你可以使用 [gosu](https://github.com/tianon/gosu)。
|
||||
|
||||
最后,为了减少层数和复杂度,避免频繁地使用 `USER` 来回切换用户。
|
||||
|
||||
### WORKDIR
|
||||
|
||||
为了清晰性和可靠性,你应该总是在 `WORKDIR` 中使用绝对路径。另外,你应该使用 `WORKDIR` 来替代类似于 `RUN cd ... && do-something` 的指令,后者难以阅读、排错和维护。
|
||||
|
||||
## 官方镜像示例
|
||||
|
||||
这些官方镜像的 Dockerfile 都是参考典范:https://github.com/docker-library/docs
|
||||
# [Best practices for writing Dockerfiles](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/)
|
||||
|
||||
@@ -10,4 +10,120 @@ Docker 命令有两大类,客户端命令和服务端命令。前者是主要
|
||||
|
||||
可以通过 `man docker` 或 `docker help` 来查看这些命令。
|
||||
|
||||
接下来的小节对这两个命令进行介绍。
|
||||
## 客户端命令选项
|
||||
|
||||
* `--config=""`:指定客户端配置文件,默认为 `~/.docker`;
|
||||
* `-D=true|false`:是否使用 debug 模式。默认不开启;
|
||||
* `-H, --host=[]`:指定命令对应 Docker 守护进程的监听接口,可以为 unix 套接字 `unix:///path/to/socket`,文件句柄 `fd://socketfd` 或 tcp 套接字 `tcp://[host[:port]]`,默认为 `unix:///var/run/docker.sock`;
|
||||
* `-l, --log-level="debug|info|warn|error|fatal"`:指定日志输出级别;
|
||||
* `--tls=true|false`:是否对 Docker 守护进程启用 TLS 安全机制,默认为否;
|
||||
* `--tlscacert=/.docker/ca.pem`:TLS CA 签名的可信证书文件路径;
|
||||
* `--tlscert=/.docker/cert.pem`:TLS 可信证书文件路径;
|
||||
* `--tlscert=/.docker/key.pem`:TLS 密钥文件路径;
|
||||
* `--tlsverify=true|false`:启用 TLS 校验,默认为否。
|
||||
|
||||
## dockerd 命令选项
|
||||
|
||||
* `--api-cors-header=""`:CORS 头部域,默认不允许 CORS,要允许任意的跨域访问,可以指定为 "*";
|
||||
* `--authorization-plugin=""`:载入认证的插件;
|
||||
* `-b=""`:将容器挂载到一个已存在的网桥上。指定为 `none` 时则禁用容器的网络,与 `--bip` 选项互斥;
|
||||
* `--bip=""`:让动态创建的 `docker0` 网桥采用给定的 CIDR 地址; 与 `-b` 选项互斥;
|
||||
* `--cgroup-parent=""`:指定 cgroup 的父组,默认 fs cgroup 驱动为 `/docker`,systemd cgroup 驱动为 `system.slice`;
|
||||
* `--cluster-store=""`:构成集群(如 `Swarm`)时,集群键值数据库服务地址;
|
||||
* `--cluster-advertise=""`:构成集群时,自身的被访问地址,可以为 `host:port` 或 `interface:port`;
|
||||
* `--cluster-store-opt=""`:构成集群时,键值数据库的配置选项;
|
||||
* `--config-file="/etc/docker/daemon.json"`:daemon 配置文件路径;
|
||||
* `--containerd=""`:containerd 文件的路径;
|
||||
* `-D, --debug=true|false`:是否使用 Debug 模式。缺省为 false;
|
||||
* `--default-gateway=""`:容器的 IPv4 网关地址,必须在网桥的子网段内;
|
||||
* `--default-gateway-v6=""`:容器的 IPv6 网关地址;
|
||||
* `--default-ulimit=[]`:默认的 ulimit 值;
|
||||
* `--disable-legacy-registry=true|false`:是否允许访问旧版本的镜像仓库服务器;
|
||||
* `--dns=""`:指定容器使用的 DNS 服务器地址;
|
||||
* `--dns-opt=""`:DNS 选项;
|
||||
* `--dns-search=[]`:DNS 搜索域;
|
||||
* `--exec-opt=[]`:运行时的执行选项;
|
||||
* `--exec-root=""`:容器执行状态文件的根路径,默认为 `/var/run/docker`;
|
||||
* `--fixed-cidr=""`:限定分配 IPv4 地址范围;
|
||||
* `--fixed-cidr-v6=""`:限定分配 IPv6 地址范围;
|
||||
* `-G, --group=""`:分配给 unix 套接字的组,默认为 `docker`;
|
||||
* `-g, --graph=""`:Docker 运行时的根路径,默认为 `/var/lib/docker`;
|
||||
* `-H, --host=[]`:指定命令对应 Docker daemon 的监听接口,可以为 unix 套接字 `unix:///path/to/socket`,文件句柄 `fd://socketfd` 或 tcp 套接字 `tcp://[host[:port]]`,默认为 `unix:///var/run/docker.sock`;
|
||||
* `--icc=true|false`:是否启用容器间以及跟 daemon 所在主机的通信。默认为 true。
|
||||
* `--insecure-registry=[]`:允许访问给定的非安全仓库服务;
|
||||
* `--ip=""`:绑定容器端口时候的默认 IP 地址。缺省为 `0.0.0.0`;
|
||||
* `--ip-forward=true|false`:是否检查启动在 Docker 主机上的启用 IP 转发服务,默认开启。注意关闭该选项将不对系统转发能力进行任何检查修改;
|
||||
* `--ip-masq=true|false`:是否进行地址伪装,用于容器访问外部网络,默认开启;
|
||||
* `--iptables=true|false`:是否允许 Docker 添加 iptables 规则。缺省为 true;
|
||||
* `--ipv6=true|false`:是否启用 IPv6 支持,默认关闭;
|
||||
* `-l, --log-level="debug|info|warn|error|fatal"`:指定日志输出级别;
|
||||
* `--label="[]"`:添加指定的键值对标注;
|
||||
* `--log-driver="json-file|syslog|journald|gelf|fluentd|awslogs|splunk|etwlogs|gcplogs|none"`:指定日志后端驱动,默认为 `json-file`;
|
||||
* `--log-opt=[]`:日志后端的选项;
|
||||
* `--mtu=VALUE`:指定容器网络的 `mtu`;
|
||||
* `-p=""`:指定 daemon 的 PID 文件路径。缺省为 `/var/run/docker.pid`;
|
||||
* `--raw-logs`:输出原始,未加色彩的日志信息;
|
||||
* `--registry-mirror=<scheme>://<host>`:指定 `docker pull` 时使用的注册服务器镜像地址;
|
||||
* `-s, --storage-driver=""`:指定使用给定的存储后端;
|
||||
* `--selinux-enabled=true|false`:是否启用 SELinux 支持。缺省值为 false。SELinux 目前尚不支持 overlay 存储驱动;
|
||||
* `--storage-opt=[]`:驱动后端选项;
|
||||
* `--tls=true|false`:是否对 Docker daemon 启用 TLS 安全机制,默认为否;
|
||||
* `--tlscacert=/.docker/ca.pem`:TLS CA 签名的可信证书文件路径;
|
||||
* `--tlscert=/.docker/cert.pem`:TLS 可信证书文件路径;
|
||||
* `--tlscert=/.docker/key.pem`:TLS 密钥文件路径;
|
||||
* `--tlsverify=true|false`:启用 TLS 校验,默认为否;
|
||||
* `--userland-proxy=true|false`:是否使用用户态代理来实现容器间和出容器的回环通信,默认为 true;
|
||||
* `--userns-remap=default|uid:gid|user:group|user|uid`:指定容器的用户命名空间,默认是创建新的 UID 和 GID 映射到容器内进程。
|
||||
|
||||
## 客户端命令
|
||||
|
||||
可以通过 `docker COMMAND --help` 来查看这些命令的具体用法。
|
||||
|
||||
* `attach`:依附到一个正在运行的容器中;
|
||||
* `build`:从一个 Dockerfile 创建一个镜像;
|
||||
* `commit`:从一个容器的修改中创建一个新的镜像;
|
||||
* `cp`:在容器和本地宿主系统之间复制文件中;
|
||||
* `create`:创建一个新容器,但并不运行它;
|
||||
* `diff`:检查一个容器内文件系统的修改,包括修改和增加;
|
||||
* `events`:从服务端获取实时的事件;
|
||||
* `exec`:在运行的容器内执行命令;
|
||||
* `export`:导出容器内容为一个 `tar` 包;
|
||||
* `history`:显示一个镜像的历史信息;
|
||||
* `images`:列出存在的镜像;
|
||||
* `import`:导入一个文件(典型为 `tar` 包)路径或目录来创建一个本地镜像;
|
||||
* `info`:显示一些相关的系统信息;
|
||||
* `inspect`:显示一个容器的具体配置信息;
|
||||
* `kill`:关闭一个运行中的容器 (包括进程和所有相关资源);
|
||||
* `load`:从一个 tar 包中加载一个镜像;
|
||||
* `login`:注册或登录到一个 Docker 的仓库服务器;
|
||||
* `logout`:从 Docker 的仓库服务器登出;
|
||||
* `logs`:获取容器的 log 信息;
|
||||
* `network`:管理 Docker 的网络,包括查看、创建、删除、挂载、卸载等;
|
||||
* `node`:管理 swarm 集群中的节点,包括查看、更新、删除、提升/取消管理节点等;
|
||||
* `pause`:暂停一个容器中的所有进程;
|
||||
* `port`:查找一个 nat 到一个私有网口的公共口;
|
||||
* `ps`:列出主机上的容器;
|
||||
* `pull`:从一个Docker的仓库服务器下拉一个镜像或仓库;
|
||||
* `push`:将一个镜像或者仓库推送到一个 Docker 的注册服务器;
|
||||
* `rename`:重命名一个容器;
|
||||
* `restart`:重启一个运行中的容器;
|
||||
* `rm`:删除给定的若干个容器;
|
||||
* `rmi`:删除给定的若干个镜像;
|
||||
* `run`:创建一个新容器,并在其中运行给定命令;
|
||||
* `save`:保存一个镜像为 tar 包文件;
|
||||
* `search`:在 Docker index 中搜索一个镜像;
|
||||
* `service`:管理 Docker 所启动的应用服务,包括创建、更新、删除等;
|
||||
* `start`:启动一个容器;
|
||||
* `stats`:输出(一个或多个)容器的资源使用统计信息;
|
||||
* `stop`:终止一个运行中的容器;
|
||||
* `swarm`:管理 Docker swarm 集群,包括创建、加入、退出、更新等;
|
||||
* `tag`:为一个镜像打标签;
|
||||
* `top`:查看一个容器中的正在运行的进程信息;
|
||||
* `unpause`:将一个容器内所有的进程从暂停状态中恢复;
|
||||
* `update`:更新指定的若干容器的配置信息;
|
||||
* `version`:输出 Docker 的版本信息;
|
||||
* `volume`:管理 Docker volume,包括查看、创建、删除等;
|
||||
* `wait`:阻塞直到一个容器终止,然后输出它的退出符。
|
||||
|
||||
## 一张图总结 Docker 的命令
|
||||

|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
# 客户端命令 - docker
|
||||
|
||||
## 客户端命令选项
|
||||
|
||||
* `--config=""`:指定客户端配置文件,默认为 `~/.docker`;
|
||||
* `-D=true|false`:是否使用 debug 模式。默认不开启;
|
||||
* `-H, --host=[]`:指定命令对应 Docker 守护进程的监听接口,可以为 unix 套接字 `unix:///path/to/socket`,文件句柄 `fd://socketfd` 或 tcp 套接字 `tcp://[host[:port]]`,默认为 `unix:///var/run/docker.sock`;
|
||||
* `-l, --log-level="debug|info|warn|error|fatal"`:指定日志输出级别;
|
||||
* `--tls=true|false`:是否对 Docker 守护进程启用 TLS 安全机制,默认为否;
|
||||
* `--tlscacert=/.docker/ca.pem`:TLS CA 签名的可信证书文件路径;
|
||||
* `--tlscert=/.docker/cert.pem`:TLS 可信证书文件路径;
|
||||
* `--tlscert=/.docker/key.pem`:TLS 密钥文件路径;
|
||||
* `--tlsverify=true|false`:启用 TLS 校验,默认为否。
|
||||
|
||||
## 客户端命令
|
||||
|
||||
可以通过 `docker COMMAND --help` 来查看这些命令的具体用法。
|
||||
|
||||
* `attach`:依附到一个正在运行的容器中;
|
||||
* `build`:从一个 Dockerfile 创建一个镜像;
|
||||
* `commit`:从一个容器的修改中创建一个新的镜像;
|
||||
* `cp`:在容器和本地宿主系统之间复制文件中;
|
||||
* `create`:创建一个新容器,但并不运行它;
|
||||
* `diff`:检查一个容器内文件系统的修改,包括修改和增加;
|
||||
* `events`:从服务端获取实时的事件;
|
||||
* `exec`:在运行的容器内执行命令;
|
||||
* `export`:导出容器内容为一个 `tar` 包;
|
||||
* `history`:显示一个镜像的历史信息;
|
||||
* `images`:列出存在的镜像;
|
||||
* `import`:导入一个文件(典型为 `tar` 包)路径或目录来创建一个本地镜像;
|
||||
* `info`:显示一些相关的系统信息;
|
||||
* `inspect`:显示一个容器的具体配置信息;
|
||||
* `kill`:关闭一个运行中的容器 (包括进程和所有相关资源);
|
||||
* `load`:从一个 tar 包中加载一个镜像;
|
||||
* `login`:注册或登录到一个 Docker 的仓库服务器;
|
||||
* `logout`:从 Docker 的仓库服务器登出;
|
||||
* `logs`:获取容器的 log 信息;
|
||||
* `network`:管理 Docker 的网络,包括查看、创建、删除、挂载、卸载等;
|
||||
* `node`:管理 swarm 集群中的节点,包括查看、更新、删除、提升/取消管理节点等;
|
||||
* `pause`:暂停一个容器中的所有进程;
|
||||
* `port`:查找一个 nat 到一个私有网口的公共口;
|
||||
* `ps`:列出主机上的容器;
|
||||
* `pull`:从一个Docker的仓库服务器下拉一个镜像或仓库;
|
||||
* `push`:将一个镜像或者仓库推送到一个 Docker 的注册服务器;
|
||||
* `rename`:重命名一个容器;
|
||||
* `restart`:重启一个运行中的容器;
|
||||
* `rm`:删除给定的若干个容器;
|
||||
* `rmi`:删除给定的若干个镜像;
|
||||
* `run`:创建一个新容器,并在其中运行给定命令;
|
||||
* `save`:保存一个镜像为 tar 包文件;
|
||||
* `search`:在 Docker index 中搜索一个镜像;
|
||||
* `service`:管理 Docker 所启动的应用服务,包括创建、更新、删除等;
|
||||
* `start`:启动一个容器;
|
||||
* `stats`:输出(一个或多个)容器的资源使用统计信息;
|
||||
* `stop`:终止一个运行中的容器;
|
||||
* `swarm`:管理 Docker swarm 集群,包括创建、加入、退出、更新等;
|
||||
* `tag`:为一个镜像打标签;
|
||||
* `top`:查看一个容器中的正在运行的进程信息;
|
||||
* `unpause`:将一个容器内所有的进程从暂停状态中恢复;
|
||||
* `update`:更新指定的若干容器的配置信息;
|
||||
* `version`:输出 Docker 的版本信息;
|
||||
* `volume`:管理 Docker volume,包括查看、创建、删除等;
|
||||
* `wait`:阻塞直到一个容器终止,然后输出它的退出符。
|
||||
|
||||
## 一张图总结 Docker 的命令
|
||||
|
||||

|
||||
|
||||
## 参考
|
||||
|
||||
* [官方文档](https://docs.docker.com/engine/reference/commandline/cli/)
|
||||
@@ -1,58 +0,0 @@
|
||||
# 服务端命令(dockerd)
|
||||
|
||||
## dockerd 命令选项
|
||||
|
||||
* `--api-cors-header=""`:CORS 头部域,默认不允许 CORS,要允许任意的跨域访问,可以指定为 "*";
|
||||
* `--authorization-plugin=""`:载入认证的插件;
|
||||
* `-b=""`:将容器挂载到一个已存在的网桥上。指定为 `none` 时则禁用容器的网络,与 `--bip` 选项互斥;
|
||||
* `--bip=""`:让动态创建的 `docker0` 网桥采用给定的 CIDR 地址; 与 `-b` 选项互斥;
|
||||
* `--cgroup-parent=""`:指定 cgroup 的父组,默认 fs cgroup 驱动为 `/docker`,systemd cgroup 驱动为 `system.slice`;
|
||||
* `--cluster-store=""`:构成集群(如 `Swarm`)时,集群键值数据库服务地址;
|
||||
* `--cluster-advertise=""`:构成集群时,自身的被访问地址,可以为 `host:port` 或 `interface:port`;
|
||||
* `--cluster-store-opt=""`:构成集群时,键值数据库的配置选项;
|
||||
* `--config-file="/etc/docker/daemon.json"`:daemon 配置文件路径;
|
||||
* `--containerd=""`:containerd 文件的路径;
|
||||
* `-D, --debug=true|false`:是否使用 Debug 模式。缺省为 false;
|
||||
* `--default-gateway=""`:容器的 IPv4 网关地址,必须在网桥的子网段内;
|
||||
* `--default-gateway-v6=""`:容器的 IPv6 网关地址;
|
||||
* `--default-ulimit=[]`:默认的 ulimit 值;
|
||||
* `--disable-legacy-registry=true|false`:是否允许访问旧版本的镜像仓库服务器;
|
||||
* `--dns=""`:指定容器使用的 DNS 服务器地址;
|
||||
* `--dns-opt=""`:DNS 选项;
|
||||
* `--dns-search=[]`:DNS 搜索域;
|
||||
* `--exec-opt=[]`:运行时的执行选项;
|
||||
* `--exec-root=""`:容器执行状态文件的根路径,默认为 `/var/run/docker`;
|
||||
* `--fixed-cidr=""`:限定分配 IPv4 地址范围;
|
||||
* `--fixed-cidr-v6=""`:限定分配 IPv6 地址范围;
|
||||
* `-G, --group=""`:分配给 unix 套接字的组,默认为 `docker`;
|
||||
* `-g, --graph=""`:Docker 运行时的根路径,默认为 `/var/lib/docker`;
|
||||
* `-H, --host=[]`:指定命令对应 Docker daemon 的监听接口,可以为 unix 套接字 `unix:///path/to/socket`,文件句柄 `fd://socketfd` 或 tcp 套接字 `tcp://[host[:port]]`,默认为 `unix:///var/run/docker.sock`;
|
||||
* `--icc=true|false`:是否启用容器间以及跟 daemon 所在主机的通信。默认为 true。
|
||||
* `--insecure-registry=[]`:允许访问给定的非安全仓库服务;
|
||||
* `--ip=""`:绑定容器端口时候的默认 IP 地址。缺省为 `0.0.0.0`;
|
||||
* `--ip-forward=true|false`:是否检查启动在 Docker 主机上的启用 IP 转发服务,默认开启。注意关闭该选项将不对系统转发能力进行任何检查修改;
|
||||
* `--ip-masq=true|false`:是否进行地址伪装,用于容器访问外部网络,默认开启;
|
||||
* `--iptables=true|false`:是否允许 Docker 添加 iptables 规则。缺省为 true;
|
||||
* `--ipv6=true|false`:是否启用 IPv6 支持,默认关闭;
|
||||
* `-l, --log-level="debug|info|warn|error|fatal"`:指定日志输出级别;
|
||||
* `--label="[]"`:添加指定的键值对标注;
|
||||
* `--log-driver="json-file|syslog|journald|gelf|fluentd|awslogs|splunk|etwlogs|gcplogs|none"`:指定日志后端驱动,默认为 `json-file`;
|
||||
* `--log-opt=[]`:日志后端的选项;
|
||||
* `--mtu=VALUE`:指定容器网络的 `mtu`;
|
||||
* `-p=""`:指定 daemon 的 PID 文件路径。缺省为 `/var/run/docker.pid`;
|
||||
* `--raw-logs`:输出原始,未加色彩的日志信息;
|
||||
* `--registry-mirror=<scheme>://<host>`:指定 `docker pull` 时使用的注册服务器镜像地址;
|
||||
* `-s, --storage-driver=""`:指定使用给定的存储后端;
|
||||
* `--selinux-enabled=true|false`:是否启用 SELinux 支持。缺省值为 false。SELinux 目前尚不支持 overlay 存储驱动;
|
||||
* `--storage-opt=[]`:驱动后端选项;
|
||||
* `--tls=true|false`:是否对 Docker daemon 启用 TLS 安全机制,默认为否;
|
||||
* `--tlscacert=/.docker/ca.pem`:TLS CA 签名的可信证书文件路径;
|
||||
* `--tlscert=/.docker/cert.pem`:TLS 可信证书文件路径;
|
||||
* `--tlscert=/.docker/key.pem`:TLS 密钥文件路径;
|
||||
* `--tlsverify=true|false`:启用 TLS 校验,默认为否;
|
||||
* `--userland-proxy=true|false`:是否使用用户态代理来实现容器间和出容器的回环通信,默认为 true;
|
||||
* `--userns-remap=default|uid:gid|user:group|user|uid`:指定容器的用户命名空间,默认是创建新的 UID 和 GID 映射到容器内进程。
|
||||
|
||||
## 参考
|
||||
|
||||
* [官方文档](https://docs.docker.com/engine/reference/commandline/dockerd/)
|
||||
@@ -21,8 +21,8 @@ $ sudo kill -SIGHUP $(pidof dockerd)
|
||||
## 检查内核日志
|
||||
|
||||
```bash
|
||||
$ sudo dmesg |grep dockerd
|
||||
$ sudo dmesg |grep runc
|
||||
$ sudo dmesag |grep dockerd
|
||||
$ sudo dmesag |grep runc
|
||||
```
|
||||
|
||||
## Docker 不响应时处理
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# 附录一:常见问题总结
|
||||
# 常见问题总结
|
||||
|
||||
## 镜像相关
|
||||
|
||||
@@ -12,22 +12,27 @@
|
||||
|
||||
### 本地的镜像文件都存放在哪里?
|
||||
|
||||
答:与 Docker 相关的本地资源默认存放在 `/var/lib/docker/` 目录下,以 `overlay2` 文件系统为例,其中 `containers` 目录存放容器信息,`image` 目录存放镜像信息,`overlay2` 目录下存放具体的镜像层文件。
|
||||
答:与 Docker 相关的本地资源默认存放在 `/var/lib/docker/` 目录下,以 `aufs` 文件系统为例,其中 `container` 目录存放容器信息,`graph` 目录存放镜像信息,`aufs` 目录下存放具体的镜像层文件。
|
||||
|
||||
### 构建 Docker 镜像应该遵循哪些原则?
|
||||
|
||||
答:整体原则上,尽量保持镜像功能的明确和内容的精简,要点包括
|
||||
|
||||
* 尽量选取满足需求但较小的基础系统镜像,例如大部分时候可以选择 `alpine` 镜像,仅有不足六兆大小;
|
||||
* 尽量选取满足需求但较小的基础系统镜像,例如大部分时候可以选择 debian:wheezy 或 debian:stretch 镜像,仅有不足百兆大小;
|
||||
|
||||
* 清理编译生成文件、安装包的缓存等临时文件;
|
||||
|
||||
* 安装各个软件时候要指定准确的版本号,并避免引入不需要的依赖;
|
||||
|
||||
* 从安全角度考虑,应用要尽量使用系统的库和依赖;
|
||||
|
||||
* 如果安装应用时候需要配置一些特殊的环境变量,在安装后要还原不需要保持的变量值;
|
||||
|
||||
* 使用 Dockerfile 创建镜像时候要添加 .dockerignore 文件或使用干净的工作目录。
|
||||
|
||||
更多内容请查看 [Dockerfile 最佳实践](../best_practices.md)
|
||||
|
||||
### 碰到网络问题,无法 pull 镜像,命令行指定 http\_proxy 无效?
|
||||
### 碰到网络问题,无法 pull 镜像,命令行指定 http_proxy 无效?
|
||||
|
||||
答:在 Docker 配置文件中添加 `export http_proxy="http://<PROXY_HOST>:<PROXY_PORT>"`,之后重启 Docker 服务即可。
|
||||
|
||||
@@ -47,19 +52,11 @@
|
||||
|
||||
### 如何获取某个容器的 PID 信息?
|
||||
|
||||
答:可以使用
|
||||
|
||||
```bash
|
||||
docker inspect --format '{{ .State.Pid }}' <CONTAINER ID or NAME>
|
||||
```
|
||||
答:可以使用 `docker inspect --format '{{ .State.Pid }}' <CONTAINER ID or NAME>` 命令。
|
||||
|
||||
### 如何获取某个容器的 IP 地址?
|
||||
|
||||
答:可以使用
|
||||
|
||||
```bash
|
||||
docker inspect --format '{{ .NetworkSettings.IPAddress }}' <CONTAINER ID or NAME>
|
||||
```
|
||||
答:可以使用 `docker inspect --format '{{ .NetworkSettings.IPAddress }}' <CONTAINER ID or NAME>` 命令
|
||||
|
||||
### 如何给容器指定一个固定 IP 地址,而不是每次重启容器 IP 地址都会变?
|
||||
|
||||
@@ -80,15 +77,16 @@ $ docker run --network=my-net --ip=172.25.3.3 -itd --name=my-container busybox
|
||||
答:
|
||||
|
||||
* 创建镜像时 `Dockerfile` 要通过 `EXPOSE` 指定正确的开放端口;
|
||||
|
||||
* 容器启动时指定 `PublishAllPort = true`。
|
||||
|
||||
### 可以在一个容器中同时运行多个应用进程么?
|
||||
|
||||
答:一般并不推荐在同一个容器内运行多个应用进程。如果有类似需求,可以通过一些额外的进程管理机制,比如 `supervisord` 来管理所运行的进程。可以参考 https://docs.docker.com/config/containers/multi-service\_container/ 。
|
||||
答:一般并不推荐在同一个容器内运行多个应用进程。如果有类似需求,可以通过一些额外的进程管理机制,比如 `supervisord` 来管理所运行的进程。可以参考 https://docs.docker.com/config/containers/multi-service_container/ 。
|
||||
|
||||
### 如何控制容器占用系统资源(CPU、内存)的份额?
|
||||
|
||||
答:在使用 `docker create` 命令创建容器或使用 `docker run` 创建并启动容器的时候,可以使用 -c|--cpu-shares\[=0] 参数来调整容器使用 CPU 的权重;使用 -m|--memory\[=MEMORY] 参数来调整容器使用内存的大小。
|
||||
答:在使用 `docker create` 命令创建容器或使用 `docker run` 创建并启动容器的时候,可以使用 -c|--cpu-shares[=0] 参数来调整容器使用 CPU 的权重;使用 -m|--memory[=MEMORY] 参数来调整容器使用内存的大小。
|
||||
|
||||
## 仓库相关
|
||||
|
||||
@@ -104,13 +102,14 @@ $ docker run --network=my-net --ip=172.25.3.3 -itd --name=my-container busybox
|
||||
|
||||
答:使用 `systemd` 的系统(如 Ubuntu 16.04、Centos 等)的配置文件在 `/etc/docker/daemon.json`。
|
||||
|
||||
|
||||
### 如何更改 Docker 的默认存储位置?
|
||||
|
||||
答:Docker 的默认存储位置是 `/var/lib/docker`,如果希望将 Docker 的本地文件存储到其他分区,可以使用 Linux 软连接的方式来完成,或者在启动 daemon 时通过 `-g` 参数指定,或者修改配置文件 `/etc/docker/daemon.json` 的 "data-root" 项 。可以使用 `docker system info | grep "Root Dir"` 查看当前使用的存储位置。
|
||||
|
||||
例如,如下操作将默认存储位置迁移到 /storage/docker。
|
||||
|
||||
```
|
||||
```sh
|
||||
[root@s26 ~]# df -h
|
||||
Filesystem Size Used Avail Use% Mounted on
|
||||
/dev/mapper/VolGroup-lv_root 50G 5.3G 42G 12% /
|
||||
@@ -132,7 +131,9 @@ lrwxrwxrwx. 1 root root 15 11月 17 13:43 docker -> /storage/docker
|
||||
答:这是因为系统默认没有开启对内存和 swap 使用的统计功能,引入该功能会带来性能的下降。要开启该功能,可以采取如下操作:
|
||||
|
||||
* 编辑 `/etc/default/grub` 文件(Ubuntu 系统为例),配置 `GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"`
|
||||
|
||||
* 更新 grub:`$ sudo update-grub`
|
||||
|
||||
* 重启系统,即可。
|
||||
|
||||
## Docker 与虚拟化
|
||||
@@ -140,9 +141,8 @@ lrwxrwxrwx. 1 root root 15 11月 17 13:43 docker -> /storage/docker
|
||||
### Docker 与 LXC(Linux Container)有何不同?
|
||||
|
||||
答:LXC 利用 Linux 上相关技术实现了容器。Docker 则在如下的几个方面进行了改进:
|
||||
|
||||
* 移植性:通过抽象容器配置,容器可以实现从一个平台移植到另一个平台;
|
||||
* 镜像系统:基于 OverlayFS 的镜像系统为容器的分发带来了很多的便利,同时共同的镜像层只需要存储一份,实现高效率的存储;
|
||||
* 镜像系统:基于 AUFS 的镜像系统为容器的分发带来了很多的便利,同时共同的镜像层只需要存储一份,实现高效率的存储;
|
||||
* 版本管理:类似于Git的版本管理理念,用户可以更方便的创建、管理镜像文件;
|
||||
* 仓库系统:仓库系统大大降低了镜像的分发和管理的成本;
|
||||
* 周边工具:各种现有工具(配置管理、云平台)对 Docker 的支持,以及基于 Docker的 PaaS、CI 等系统,让 Docker 的应用更加方便和多样化。
|
||||
@@ -152,6 +152,7 @@ lrwxrwxrwx. 1 root root 15 11月 17 13:43 docker -> /storage/docker
|
||||
答:两者的定位完全不同。
|
||||
|
||||
* Vagrant 类似 Boot2Docker(一款运行 Docker 的最小内核),是一套虚拟机的管理环境。Vagrant 可以在多种系统上和虚拟机软件中运行,可以在 Windows,Mac 等非 Linux 平台上为 Docker 提供支持,自身具有较好的包装性和移植性。
|
||||
|
||||
* 原生的 Docker 自身只能运行在 Linux 平台上,但启动和运行的性能都比虚拟机要快,往往更适合快速开发和部署应用的场景。
|
||||
|
||||
简单说:Vagrant 适合用来管理虚拟机,而 Docker 适合用来管理应用环境。
|
||||
|
||||
@@ -1,32 +1,20 @@
|
||||
# [CentOS](https://hub.docker.com/_/centos)
|
||||
## [CentOS](https://hub.docker.com/_/centos)
|
||||
|
||||
## 基本信息
|
||||
### 基本信息
|
||||
|
||||
[CentOS](https://en.wikipedia.org/wiki/CentOS) 是流行的 Linux 发行版,其软件包大多跟 RedHat 系列保持一致。
|
||||
|
||||
> ⚠️ **重要提示**:CentOS 8 已于 2021 年 12 月 31 日停止维护(EOL),CentOS 7 将于 2024 年 6 月 30 日结束支持。Docker Hub 上的 CentOS 官方镜像**已停止更新**。
|
||||
>
|
||||
> 对于新项目,建议使用以下替代方案:
|
||||
> - [Rocky Linux](https://hub.docker.com/_/rockylinux):CentOS 创始人发起的社区驱动项目
|
||||
> - [AlmaLinux](https://hub.docker.com/_/almalinux):由 CloudLinux 支持的企业级发行版
|
||||
> - [CentOS Stream](https://hub.docker.com/r/centos/centos):RHEL 的上游开发分支
|
||||
该仓库位于 `https://hub.docker.com/_/centos` ,提供了 CentOS 从 5 ~ 7 各个版本的镜像。
|
||||
|
||||
该仓库位于 `https://hub.docker.com/_/centos`,提供了 CentOS 从 5 ~ 8 各个版本的镜像(仅供参考,不再更新)。
|
||||
### 使用方法
|
||||
|
||||
## 使用方法
|
||||
|
||||
使用 Rocky Linux 替代(推荐):
|
||||
默认会启动一个最小化的 CentOS 环境。
|
||||
|
||||
```bash
|
||||
$ docker run --name rocky -it rockylinux:9 bash
|
||||
$ docker run --name centos -it centos bash
|
||||
bash-4.2#
|
||||
```
|
||||
|
||||
使用旧版 CentOS 7(仅用于遗留系统):
|
||||
|
||||
```bash
|
||||
$ docker run --name centos -it centos:7 bash
|
||||
```
|
||||
|
||||
## Dockerfile
|
||||
### Dockerfile
|
||||
|
||||
请到 https://github.com/docker-library/docs/tree/master/centos 查看。
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
# minio
|
||||
|
||||
**MinIO** 是一个基于 Apache License v2.0 开源协议的对象存储服务。它兼容亚马逊 S3 云存储服务接口,非常适合于存储大容量非结构化的数据,例如图片、视频、日志文件、备份数据和容器/虚拟机镜像等,而一个对象文件可以是任意大小,从几 kb 到最大 5T 不等。
|
||||
|
||||
MinIO 是一个非常轻量的服务,可以很简单的和其他应用的结合,类似 NodeJS, Redis 或者 MySQL。
|
||||
|
||||
[官方文档](https://docs.min.io/)
|
||||
|
||||
## 简单使用
|
||||
|
||||
测试、开发环境下不考虑数据存储的情况下可以使用下面的命令快速开启服务。
|
||||
|
||||
```bash
|
||||
$ docker run -d -p 9000:9000 -p 9090:9090 minio/minio server /data --console-address ':9090'
|
||||
```
|
||||
|
||||
## 离线部署
|
||||
|
||||
许多生产环境是一般是没有公网资源的,这就需要从有公网资源的服务器上把镜像导出,然后导入到需要运行镜像的内网服务器。
|
||||
|
||||
### 导出镜像
|
||||
|
||||
在有公网资源的服务器上下载好`minio/minio`镜像
|
||||
|
||||
```bash
|
||||
$ docker save -o minio.tar minio/minio:latest
|
||||
```
|
||||
|
||||
> 使用docker save 的时候,也可以使用image id 来导出,但是那样导出的时候,就会丢失原来的镜像名称,推荐,还是使用镜像名字+tag来导出镜像
|
||||
|
||||
### 导入镜像
|
||||
|
||||
把压缩文件复制到内网服务器上,使用下面的命令导入镜像
|
||||
|
||||
```bash
|
||||
$ docker load minio.tar
|
||||
```
|
||||
|
||||
### 运行 minio
|
||||
|
||||
- 把 `/mnt/data` 改成要替换的数据目录
|
||||
- 替换 `MINIO_ROOT_USER` 的值
|
||||
- 替换 `MINIO_ROOT_PASSWORD` 的值
|
||||
- 替换 name,minio1(可选)
|
||||
- 如果 9000、9090 端口冲突,替换端口前面的如 `9009:9000`
|
||||
|
||||
```bash
|
||||
$ sudo docker run -d -p 9000:9000 -p 9090:9090 --name minio1 \
|
||||
-e "MINIO_ROOT_USER=改成自己需要的" \
|
||||
-e "MINIO_ROOT_PASSWORD=改成自己需要的" \
|
||||
-v /mnt/data:/data \
|
||||
--restart=always \
|
||||
minio/minio server /data --console-address ':9090'
|
||||
```
|
||||
|
||||
### 访问 web 管理页面
|
||||
|
||||
http://x.x.x.x:9090
|
||||
@@ -1,12 +1,12 @@
|
||||
# [MongoDB](https://hub.docker.com/_/mongo/)
|
||||
## [MongoDB](https://hub.docker.com/_/mongo/)
|
||||
|
||||
## 基本信息
|
||||
### 基本信息
|
||||
|
||||
[MongoDB](https://en.wikipedia.org/wiki/MongoDB) 是开源的 NoSQL 数据库实现。
|
||||
|
||||
该仓库位于 `https://hub.docker.com/_/mongo/` ,提供了 MongoDB 2.x ~ 4.x 各个版本的镜像。
|
||||
|
||||
## 使用方法
|
||||
### 使用方法
|
||||
|
||||
默认会在 `27017` 端口启动数据库。
|
||||
|
||||
@@ -14,31 +14,21 @@
|
||||
$ docker run --name mongo -d mongo
|
||||
```
|
||||
|
||||
使用其他应用连接到容器,首先创建网络
|
||||
```bash
|
||||
$ docker network create my-mongo-net
|
||||
```
|
||||
使用其他应用连接到容器,可以用
|
||||
|
||||
然后启动 MongoDB 容器
|
||||
```bash
|
||||
$ docker run --name some-mongo -d --network my-mongo-net mongo
|
||||
```
|
||||
|
||||
最后启动应用容器
|
||||
```bash
|
||||
$ docker run --name some-app -d --network my-mongo-net application-that-uses-mongo
|
||||
$ docker run --name some-app --link some-mongo:mongo -d application-that-uses-mongo
|
||||
```
|
||||
|
||||
或者通过 `mongo`
|
||||
|
||||
```bash
|
||||
$ docker run -it --rm \
|
||||
--network my-mongo-net \
|
||||
--link some-mongo:mongo \
|
||||
mongo \
|
||||
sh -c 'exec mongo "some-mongo:27017/test"'
|
||||
```
|
||||
sh -c 'exec mongo "$MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT/test"'
|
||||
```
|
||||
|
||||
## Dockerfile
|
||||
### Dockerfile
|
||||
|
||||
请到 https://github.com/docker-library/docs/tree/master/mongo 查看。
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
# [MySQL](https://hub.docker.com/_/mysql/)
|
||||
## [MySQL](https://hub.docker.com/_/mysql/)
|
||||
|
||||
## 基本信息
|
||||
### 基本信息
|
||||
|
||||
[MySQL](https://en.wikipedia.org/wiki/MySQL) 是开源的关系数据库实现。
|
||||
|
||||
该仓库位于 `https://hub.docker.com/_/mysql/` ,提供了 MySQL 5.5 ~ 8.x 各个版本的镜像。
|
||||
|
||||
## 使用方法
|
||||
### 使用方法
|
||||
|
||||
默认会在 `3306` 端口启动数据库。
|
||||
|
||||
@@ -16,31 +16,19 @@ $ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=mysecretpassword -d mysql
|
||||
|
||||
之后就可以使用其它应用来连接到该容器。
|
||||
|
||||
首先创建网络
|
||||
```bash
|
||||
$ docker network create my-mysql-net
|
||||
```
|
||||
|
||||
然后启动 MySQL 容器
|
||||
```bash
|
||||
$ docker run --name some-mysql -d --network my-mysql-net -e MYSQL_ROOT_PASSWORD=mysecretpassword mysql
|
||||
```
|
||||
|
||||
最后启动应用容器
|
||||
```bash
|
||||
$ docker run --name some-app -d --network my-mysql-net application-that-uses-mysql
|
||||
$ docker run --name some-app --link some-mysql:mysql -d application-that-uses-mysql
|
||||
```
|
||||
|
||||
或者通过 `mysql` 命令行连接。
|
||||
|
||||
```bash
|
||||
$ docker run -it --rm \
|
||||
--network my-mysql-net \
|
||||
--link some-mysql:mysql \
|
||||
mysql \
|
||||
sh -c 'exec mysql -hsome-mysql -P3306 -uroot -pmysecretpassword'
|
||||
sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
|
||||
```
|
||||
|
||||
|
||||
## Dockerfile
|
||||
### Dockerfile
|
||||
|
||||
请到 https://github.com/docker-library/docs/tree/master/mysql 查看
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
# [Nginx](https://hub.docker.com/_/nginx/)
|
||||
## [Nginx](https://hub.docker.com/_/nginx/)
|
||||
|
||||
## 基本信息
|
||||
### 基本信息
|
||||
|
||||
[Nginx](https://en.wikipedia.org/wiki/Nginx) 是开源的高效的 Web 服务器实现,支持 HTTP、HTTPS、SMTP、POP3、IMAP 等协议。
|
||||
|
||||
该仓库位于 `https://hub.docker.com/_/nginx/` ,提供了 Nginx 1.0 ~ 1.19.x 各个版本的镜像。
|
||||
该仓库位于 `https://hub.docker.com/_/nginx/` ,提供了 Nginx 1.0 ~ 1.17.x 各个版本的镜像。
|
||||
|
||||
## 使用方法
|
||||
### 使用方法
|
||||
|
||||
下面的命令将作为一个静态页面服务器启动。
|
||||
|
||||
@@ -16,7 +16,7 @@ $ docker run --name some-nginx -v /some/content:/usr/share/nginx/html:ro -d ngin
|
||||
|
||||
用户也可以不使用这种映射方式,通过利用 Dockerfile 来直接将静态页面内容放到镜像中,内容为
|
||||
|
||||
```docker
|
||||
```bash
|
||||
FROM nginx
|
||||
COPY static-html-directory /usr/share/nginx/html
|
||||
```
|
||||
@@ -39,11 +39,10 @@ Nginx的默认配置文件路径为 `/etc/nginx/nginx.conf`,可以通过映射
|
||||
```bash
|
||||
$ docker run -d \
|
||||
--name some-nginx \
|
||||
-p 8080:80 \
|
||||
-v /path/nginx.conf:/etc/nginx/nginx.conf:ro \
|
||||
-v /some/nginx.conf:/etc/nginx/nginx.conf:ro \
|
||||
nginx
|
||||
```
|
||||
|
||||
## Dockerfile
|
||||
### Dockerfile
|
||||
|
||||
请到 https://github.com/docker-library/docs/tree/master/nginx 查看。
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
# [Node.js](https://hub.docker.com/_/node/)
|
||||
## [Node.js](https://hub.docker.com/_/node/)
|
||||
|
||||
## 基本信息
|
||||
### 基本信息
|
||||
|
||||
[Node.js](https://en.wikipedia.org/wiki/Node.js) 是基于 JavaScript 的可扩展服务端和网络软件开发平台。
|
||||
|
||||
该仓库位于 `https://hub.docker.com/_/node/` ,提供了 Node.js 0.10 ~ 14.x 各个版本的镜像。
|
||||
该仓库位于 `https://hub.docker.com/_/node/` ,提供了 Node.js 0.10 ~ 12.x 各个版本的镜像。
|
||||
|
||||
## 使用方法
|
||||
### 使用方法
|
||||
|
||||
在项目中创建一个 Dockerfile。
|
||||
|
||||
```docker
|
||||
FROM node:12
|
||||
```bash
|
||||
FROM node:9
|
||||
# replace this with your application's default port
|
||||
EXPOSE 8888
|
||||
```
|
||||
@@ -31,10 +31,10 @@ $ docker run -it --rm \
|
||||
# -v "$(pwd)":/usr/src/myapp \
|
||||
--mount type=bind,src=`$(pwd)`,target=/usr/src/myapp \
|
||||
-w /usr/src/myapp \
|
||||
node:12-alpine \
|
||||
node:9-alpine \
|
||||
node your-daemon-or-script.js
|
||||
```
|
||||
|
||||
## Dockerfile
|
||||
### Dockerfile
|
||||
|
||||
请到 https://github.com/docker-library/docs/tree/master/node 查看。
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
# [PHP](https://hub.docker.com/_/php/)
|
||||
## [PHP](https://hub.docker.com/_/php/)
|
||||
|
||||
## 基本信息
|
||||
### 基本信息
|
||||
|
||||
[PHP](https://en.wikipedia.org/wiki/Php)(Hypertext Preprocessor 超文本预处理器的字母缩写)是一种被广泛应用的开放源代码的多用途脚本语言,它可嵌入到 HTML 中,尤其适合 web 开发。
|
||||
[PHP](https://en.wikipedia.org/wiki/php)(Hypertext Preprocessor 超文本预处理器的字母缩写)是一种被广泛应用的开放源代码的多用途脚本语言,它可嵌入到 HTML 中,尤其适合 web 开发。
|
||||
|
||||
该仓库位于 `https://hub.docker.com/_/php/` ,提供了 PHP 5.x ~ 8.x 各个版本的镜像。
|
||||
该仓库位于 `https://hub.docker.com/_/php/` ,提供了 PHP 5.x ~ 7.x 各个版本的镜像。
|
||||
|
||||
## 使用方法
|
||||
### 使用方法
|
||||
|
||||
下面的命令将运行一个已有的 PHP 脚本。
|
||||
|
||||
@@ -14,6 +14,6 @@
|
||||
$ docker run -it --rm -v "$PWD":/app -w /app php:alpine php your-script.php
|
||||
```
|
||||
|
||||
## Dockerfile
|
||||
### Dockerfile
|
||||
|
||||
请到 https://github.com/docker-library/docs/tree/master/php 查看。
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
# [Redis](https://hub.docker.com/_/redis/)
|
||||
## [Redis](https://hub.docker.com/_/redis/)
|
||||
|
||||
## 基本信息
|
||||
### 基本信息
|
||||
|
||||
[Redis](https://en.wikipedia.org/wiki/Redis) 是开源的内存 Key-Value 数据库实现。
|
||||
|
||||
该仓库位于 `https://hub.docker.com/_/redis/` ,提供了 Redis 3.x ~ 6.x 各个版本的镜像。
|
||||
该仓库位于 `https://hub.docker.com/_/redis/` ,提供了 Redis 3.x ~ 5.x 各个版本的镜像。
|
||||
|
||||
## 使用方法
|
||||
### 使用方法
|
||||
|
||||
默认会在 `6379` 端口启动数据库。
|
||||
|
||||
@@ -22,30 +22,21 @@ $ docker run --name some-redis -d -p 6379:6379 redis redis-server --appendonly y
|
||||
|
||||
默认数据存储位置在 `VOLUME/data`。可以使用 `--volumes-from some-volume-container` 或 `-v /docker/host/dir:/data` 将数据存放到本地。
|
||||
|
||||
使用其他应用连接到容器,首先创建网络
|
||||
```bash
|
||||
$ docker network create my-redis-net
|
||||
```
|
||||
使用其他应用连接到容器,可以用
|
||||
|
||||
然后启动 redis 容器
|
||||
```bash
|
||||
$ docker run --name some-redis -d --network my-redis-net redis
|
||||
```
|
||||
|
||||
最后启动应用容器
|
||||
```bash
|
||||
$ docker run --name some-app -d --network my-redis-net application-that-uses-redis
|
||||
$ docker run --name some-app --link some-redis:redis -d application-that-uses-redis
|
||||
```
|
||||
|
||||
或者通过 `redis-cli`
|
||||
|
||||
```bash
|
||||
$ docker run -it --rm \
|
||||
--network my-redis-net \
|
||||
--link some-redis:redis \
|
||||
redis \
|
||||
sh -c 'exec redis-cli -h some-redis'
|
||||
sh -c 'exec redis-cli -h "$REDIS_PORT_6379_TCP_ADDR" -p "$REDIS_PORT_6379_TCP_PORT"'
|
||||
```
|
||||
|
||||
## Dockerfile
|
||||
### Dockerfile
|
||||
|
||||
请到 https://github.com/docker-library/docs/tree/master/redis 查看。
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
# [Ubuntu](https://hub.docker.com/_/ubuntu/)
|
||||
## [Ubuntu](https://hub.docker.com/_/ubuntu/)
|
||||
|
||||
## 基本信息
|
||||
### 基本信息
|
||||
|
||||
[Ubuntu](https://en.wikipedia.org/wiki/Ubuntu) 是流行的 Linux 发行版,其自带软件版本往往较新一些。
|
||||
|
||||
该仓库位于 `https://hub.docker.com/_/ubuntu/` ,提供了 Ubuntu 从 12.04 ~ 20.04 各个版本的镜像。
|
||||
该仓库位于 `https://hub.docker.com/_/ubuntu/` ,提供了 Ubuntu 从 12.04 ~ 19.04 各个版本的镜像。
|
||||
|
||||
## 使用方法
|
||||
### 使用方法
|
||||
|
||||
默认会启动一个最小化的 Ubuntu 环境。
|
||||
|
||||
```bash
|
||||
$ docker run --name some-ubuntu -it ubuntu:20.04
|
||||
$ docker run --name some-ubuntu -it ubuntu:18.04
|
||||
root@523c70904d54:/#
|
||||
```
|
||||
|
||||
## Dockerfile
|
||||
### Dockerfile
|
||||
|
||||
请到 https://github.com/docker-library/docs/tree/master/ubuntu 查看。
|
||||
|
||||
@@ -1,38 +1,25 @@
|
||||
# [WordPress](https://hub.docker.com/_/wordpress/)
|
||||
## [WordPress](https://hub.docker.com/_/wordpress/)
|
||||
|
||||
## 基本信息
|
||||
### 基本信息
|
||||
|
||||
[WordPress](https://en.wikipedia.org/wiki/WordPress) 是开源的 Blog 和内容管理系统框架,它基于 PHP 和 MySQL。
|
||||
|
||||
该仓库位于 `https://hub.docker.com/_/wordpress/` ,提供了 WordPress 4.x ~ 5.x 版本的镜像。
|
||||
|
||||
## 使用方法
|
||||
### 使用方法
|
||||
|
||||
启动容器需要 MySQL 的支持,默认端口为 `80`。
|
||||
|
||||
首先创建网络
|
||||
```bash
|
||||
$ docker network create my-wordpress-net
|
||||
```
|
||||
|
||||
启动 MySQL 容器
|
||||
```bash
|
||||
$ docker run --name some-mysql -d --network my-wordpress-net -e MYSQL_ROOT_PASSWORD=mysecretpassword mysql
|
||||
```
|
||||
|
||||
启动 WordPress 容器
|
||||
```bash
|
||||
$ docker run --name some-wordpress -d --network my-wordpress-net -e WORDPRESS_DB_HOST=some-mysql -e WORDPRESS_DB_PASSWORD=mysecretpassword wordpress
|
||||
$ docker run --name some-wordpress --link some-mysql:mysql -d wordpress
|
||||
```
|
||||
|
||||
启动 WordPress 容器时可以指定的一些环境变量包括:
|
||||
|
||||
* `WORDPRESS_DB_HOST`: MySQL 服务的主机名
|
||||
* `WORDPRESS_DB_USER`: MySQL 数据库的用户名
|
||||
* `WORDPRESS_DB_PASSWORD`: MySQL 数据库的密码
|
||||
* `WORDPRESS_DB_NAME`: WordPress 要使用的数据库名
|
||||
* `WORDPRESS_DB_USER` 缺省为 `root`
|
||||
* `WORDPRESS_DB_PASSWORD` 缺省为连接 mysql 容器的环境变量 `MYSQL_ROOT_PASSWORD` 的值
|
||||
* `WORDPRESS_DB_NAME` 缺省为 `wordpress`
|
||||
|
||||
|
||||
## Dockerfile
|
||||
### Dockerfile
|
||||
|
||||
请到 https://github.com/docker-library/docs/tree/master/wordpress 查看。
|
||||
|
||||
@@ -3,11 +3,10 @@
|
||||
## 官方网站
|
||||
|
||||
* Docker 官方主页:https://www.docker.com
|
||||
* Docker 官方博客:https://www.docker.com/blog/
|
||||
* Docker 官方博客:https://blog.docker.com/
|
||||
* Docker 官方文档:https://docs.docker.com/
|
||||
* Docker Hub:https://hub.docker.com
|
||||
* Docker 的源代码仓库:https://github.com/moby/moby
|
||||
* Docker 路线图 https://github.com/docker/roadmap/projects
|
||||
* Docker 发布版本历史:https://docs.docker.com/release-notes/
|
||||
* Docker 常见问题:https://docs.docker.com/engine/faq/
|
||||
* Docker 远端应用 API:https://docs.docker.com/develop/sdk/
|
||||
@@ -20,8 +19,7 @@
|
||||
## 技术交流
|
||||
|
||||
* Docker 邮件列表: https://groups.google.com/forum/#!forum/docker-user
|
||||
* Docker 社区 Slack:https://dockercommunity.slack.com/
|
||||
* Docker Community Discord: https://discord.gg/docker
|
||||
* Docker 的 IRC 频道:https://chat.freenode.net#docker
|
||||
* Docker 的 Twitter 主页:https://twitter.com/docker
|
||||
|
||||
## 其它
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
# 归档项目
|
||||
|
||||
以下项目不被官方支持或内容陈旧,将在下一版本中删除(或已经删除)。
|
||||
|
||||
* [Docker Machine](https://github.com/yeasy/docker_practice/tree/ca29ab51b121f43563f5d6659dedbda5cb6f048d/machine)
|
||||
* [Docker Swarm](https://github.com/yeasy/docker_practice/tree/ca29ab51b121f43563f5d6659dedbda5cb6f048d/swarm)
|
||||
* Mesos
|
||||
@@ -1,9 +1,7 @@
|
||||
# 基本概念
|
||||
# Basic Concepts
|
||||
Docker contains 3 basic concepts
|
||||
* `Image`
|
||||
* `Container`
|
||||
* `Repository`
|
||||
|
||||
**Docker** 包括三个基本概念:
|
||||
|
||||
* **镜像**(`Image`):Docker 镜像是一个特殊的文件系统,除了提供容器运行时所需的程序、库、资源、配置等文件外,还包含了一些为运行时准备的一些配置参数(如匿名卷、环境变量、用户等)。镜像不包含任何动态数据,其内容在构建之后也不会被改变。
|
||||
* **容器**(`Container`):镜像(`Image`)和容器(`Container`)的关系,就像是面向对象程序设计中的 `类` 和 `实例` 一样,镜像是静态的定义,容器是镜像运行时的实体。容器可以被创建、启动、停止、删除、暂停等。
|
||||
* **仓库**(`Repository`):镜像构建完成后,可以很容易的在当前宿主机上运行,但是,如果需要在其它服务器上使用这个镜像,我们就需要一个集中的存储、分发镜像的服务,Docker Registry 就是这样的服务。
|
||||
|
||||
理解了这三个概念,就理解了 **Docker** 的整个生命周期。
|
||||
Only after knowing the above 3 concepts will we get a deeper understanding of the lifecyle of docker.
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
# Docker 容器
|
||||
## Docker Container
|
||||
|
||||
镜像(`Image`)和容器(`Container`)的关系,就像是面向对象程序设计中的 `类` 和 `实例` 一样,镜像是静态的定义,容器是镜像运行时的实体。容器可以被创建、启动、停止、删除、暂停等。
|
||||
The relationship between `Image` and `Container` is just as `Class` and `Instance` in [OOP](https://en.wikipedia.org/wiki/Object-oriented_programming). `Image` is the static definition of `container`, while `containers` are the `images` in running state. `Containers` can be created, started, paused, deleted or stopped.
|
||||
|
||||
容器的实质是进程,但与直接在宿主执行的进程不同,容器进程运行于属于自己的独立的 [命名空间](https://en.wikipedia.org/wiki/Linux_namespaces)。因此容器可以拥有自己的 `root` 文件系统、自己的网络配置、自己的进程空间,甚至自己的用户 ID 空间。容器内的进程是运行在一个隔离的环境里,使用起来,就好像是在一个独立于宿主的系统下操作一样。这种特性使得容器封装的应用比直接在宿主运行更加安全。也因为这种隔离的特性,很多人初学 Docker 时常常会混淆容器和虚拟机。
|
||||
The essence of `container` is `process`, but different from that in the host OS, the container processes run in their individual [`namespaces`](https://en.wikipedia.org/wiki/Linux_namespaces). With the namespace, a container can have its own `root` filesystem, network configurations, process space and even an ID space for users. The processes in a container run in an isolated environment, thus can be used as if it were an individual OS independent of the host OS. This feature makes docker-encapsulated applications safer than those running directly on the host. And that's also an important factor that confuses the novices to tell it from virtual machines.
|
||||
|
||||
前面讲过镜像使用的是分层存储,容器也是如此。每一个容器运行时,是以镜像为基础层,在其上创建一个当前容器的存储层,我们可以称这个为容器运行时读写而准备的存储层为 **容器存储层**。
|
||||
As we've discussed, `multi-layered filesystem` is applied to images, and so as the containers. When a container is running, it is based on its image, with a writable layer created on top of it. We call this layer prepared for R/W at runtime [**`Container Layer`**](https://docs.docker.com/storage/storagedriver/#images-and-layers).
|
||||
|
||||
容器存储层的生存周期和容器一样,容器消亡时,容器存储层也随之消亡。因此,任何保存于容器存储层的信息都会随容器删除而丢失。
|
||||
The lifecyle of the container layer is the same as contaier. The container layer dies as soon as the container dies. Therefore, anything stored at the container layer will be discarded when the container is deleted.
|
||||
|
||||
按照 Docker 最佳实践的要求,容器不应该向其存储层内写入任何数据,容器存储层要保持无状态化。所有的文件写入操作,都应该使用 [数据卷(Volume)](../data_management/volume.md)、或者 [绑定宿主目录](../data_management/bind-mounts.md),在这些位置的读写会跳过容器存储层,直接对宿主(或网络存储)发生读写,其性能和稳定性更高。
|
||||
As recommended by the [Docker Development Best Practices](https://docs.docker.com/develop/dev-best-practices/#where-and-how-to-persist-application-data), we should not write any data to the container layer to make it stateless. All file write operations should adhere to [`Volume`](../data_management/volume.md) or bind mounts. Writing to volume or bind mounts skips the container layer and R/W to host storage(or network storage) directly, which achieves better performance and stability.
|
||||
|
||||
数据卷的生存周期独立于容器,容器消亡,数据卷不会消亡。因此,使用数据卷后,容器删除或者重新运行之后,数据却不会丢失。
|
||||
The lifecyle of volume is independent of the container, and will not vanish when the container is deleted. In light of it, the data persists when a container is deleted or restarted.
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
# Docker 镜像
|
||||
## Docker Image
|
||||
|
||||
我们都知道,操作系统分为 **内核** 和 **用户空间**。对于 `Linux` 而言,内核启动后,会挂载 `root` 文件系统为其提供用户空间支持。而 **Docker 镜像**(`Image`),就相当于是一个 `root` 文件系统。比如官方镜像 `ubuntu:24.04` 就包含了完整的一套 Ubuntu 24.04 最小系统的 `root` 文件系统。
|
||||
As we all know, Operating System consists of kernel space and user space. For linux, it will mount `root` filesystem to support user space. For Docker Image, it is similar to a `root` filesystem in Linux. For example, the offical image `ubuntu:18:04` contains a micro `root` filesystem of complete opreating system.
|
||||
|
||||
**Docker 镜像** 是一个特殊的文件系统,除了提供容器运行时所需的程序、库、资源、配置等文件外,还包含了一些为运行时准备的一些配置参数(如匿名卷、环境变量、用户等)。镜像 **不包含** 任何动态数据,其内容在构建之后也不会被改变。
|
||||
Docker Image is a special filesystem. Apart from programs, libs, resources and config which support running container, Docker Image also includes config parameters like anonymous volumes, environment variables, users and others. Images don't have any dynamic data. Its content will not be changed after build.
|
||||
|
||||
## 分层存储
|
||||
## Advanced Multi-layered Unification Filesystem (AUFS)
|
||||
|
||||
因为镜像包含操作系统完整的 `root` 文件系统,其体积往往是庞大的,因此在 Docker 设计时,就充分利用 [Union FS](https://en.wikipedia.org/wiki/Union_mount) 的技术,将其设计为分层存储的架构。所以严格来说,镜像并非是像一个 `ISO` 那样的打包文件,镜像只是一个虚拟的概念,其实际体现并非由一个文件组成,而是由一组文件系统组成,或者说,由多层文件系统联合组成。
|
||||
Because the image contains the complete `root` file system of the operating system, its volume is often huge. So Docker made full use of [Union FS](https://en.wikipedia.org/wiki/Union_mount) and was designed as AUFS when it was designed. So strictly speaking, image is not a packaged file like an ISO image file. Image is just a virtual concept. It is not composed of a single file, but a group of file systems, or a combination of multi-layered filesystems.
|
||||
|
||||
镜像构建时,会一层层构建,前一层是后一层的基础。每一层构建完就不会再发生改变,后一层上的任何改变只发生在自己这一层。比如,删除前一层文件的操作,实际不是真的删除前一层的文件,而是仅在当前层标记为该文件已删除。在最终容器运行的时候,虽然不会看到这个文件,但是实际上该文件会一直跟随镜像。因此,在构建镜像的时候,需要额外小心,每一层尽量只包含该层需要添加的东西,任何额外的东西应该在该层构建结束前清理掉。
|
||||
When building an image, it builds layer by layer, and the former is the basis for the latter. Once each layer is built, it will not change later. Any change on the latter layer will only occur on its own level. For example, deleting the previous layer of files is not really deleting the files, but only marked as deleted in the current layer. When the final container runs, you won't see the file, but in fact the file will always follow the image. Therefore, take more care when building the image, and any redundant file should be cleared up in ahead of the layer's final construction.
|
||||
|
||||
分层存储的特征还使得镜像的复用、定制变的更为容易。甚至可以用之前构建好的镜像作为基础层,然后进一步添加新的层,以定制自己所需的内容,构建新的镜像。
|
||||
The layered storage feature also makes it easier to reuse and customize images. You can even use a previously built image as the base layer, and then add a new layer to customize the content to meet your need to build a new image.
|
||||
|
||||
关于镜像构建,将会在后续相关章节中做进一步的讲解。
|
||||
As for image building, further explanations will be given in subsequent relevant chapters.
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
# Docker Registry
|
||||
## Docker Registry
|
||||
|
||||
镜像构建完成后,可以很容易的在当前宿主机上运行,但是,如果需要在其它服务器上使用这个镜像,我们就需要一个集中的存储、分发镜像的服务,[Docker Registry](../repository/registry.md) 就是这样的服务。
|
||||
After the construction of an image, we can easily run it on a host. However, if we want to use the image on other servers, we need a centralized image storage and distribution service. The [Docker Registry](../repository/registry.md) we will introduce is such a service.
|
||||
|
||||
一个 **Docker Registry** 中可以包含多个 **仓库**(`Repository`);每个仓库可以包含多个 **标签**(`Tag`);每个标签对应一个镜像。
|
||||
A **Docker Registry** can contain several `Repositories`, where each repository can contain several tags and each tag corresponds to an image.
|
||||
|
||||
通常,一个仓库会包含同一个软件不同版本的镜像,而标签就常用于对应该软件的各个版本。我们可以通过 `<仓库名>:<标签>` 的格式来指定具体是这个软件哪个版本的镜像。如果不给出标签,将以 `latest` 作为默认标签。
|
||||
Typically, a repository contains images for different versions of the same software, where each tags corresponds to different versions of the software. We can uniquely identify an image of the same software with `repository:tag`. In case not explicitly specified, `latest` is taken as default tag.
|
||||
|
||||
以 [Ubuntu 镜像](https://hub.docker.com/_/ubuntu) 为例,`ubuntu` 是仓库的名字,其内包含有不同的版本标签,如,`22.04`, `24.04`。我们可以通过 `ubuntu:22.04`,或者 `ubuntu:24.04` 来具体指定所需哪个版本的镜像。如果忽略了标签,比如 `ubuntu`,那将视为 `ubuntu:latest`。
|
||||
Taking the [Ubuntu Image](https://hub.docker.com/_/ubuntu) as an example. `ubuntu` is the name for repository, and inside it are tags for different versions, for instance, `16.04`, `18.04`. We can use `ubuntu:16.04` or `ubuntu:18.04` to specify the particular image we want. If the tag is omitted, for example, `ubuntu`, then it will be considered as `ubuntu:latest`.
|
||||
|
||||
仓库名经常以 *两段式路径* 形式出现,比如 `jwilder/nginx-proxy`,前者往往意味着 Docker Registry 多用户环境下的用户名,后者则往往是对应的软件名。但这并非绝对,取决于所使用的具体 Docker Registry 的软件或服务。
|
||||
Repository name is typically seperated by a forward slash(/), for example, `jwilder/nginx-proxy`, the former is to identify a particular user in a multi-user Docker Registry, while the latter corresponds to the software name. But it is not always the case. It also depends on the Docker Registry software or service you are using.
|
||||
|
||||
## Docker Registry 公开服务
|
||||
### Docker Registry Public Services
|
||||
|
||||
Docker Registry 公开服务是开放给用户使用、允许用户管理镜像的 Registry 服务。一般这类公开服务允许用户免费上传、下载公开的镜像,并可能提供收费服务供用户管理私有镜像。
|
||||
`Docker Registry Public Services` are registry services open to users, allowing users to manage their images. Typically, those public services offer user free image uploads and downloads, and possibly provide charged service for privately managed images.
|
||||
|
||||
最常使用的 Registry 公开服务是官方的 [Docker Hub](https://hub.docker.com/),这也是默认的 Registry,并拥有大量的高质量的 [官方镜像](https://hub.docker.com/search?q=&type=image&image_filter=official)。除此以外,还有 Red Hat 的 [Quay.io](https://quay.io/repository/);Google 的 [Google Container Registry](https://cloud.google.com/container-registry/),[Kubernetes](https://kubernetes.io/) 的镜像使用的就是这个服务;代码托管平台 [GitHub](https://github.com) 推出的 [ghcr.io](https://docs.github.com/cn/packages/working-with-a-github-packages-registry/working-with-the-container-registry)。
|
||||
The most commonly used registry public service is the official [Docker Hub](https://hub.docker.com/), which is the default registry with thousands of high quality official images. Besides, the images for [Quay.io](https://quay.io/repository/) and CoreOS of [CoreOS](https://coreos.com/) are stored there. Google's [Google Container Registry](https://cloud.google.com/container-registry/) and [Kubernetes](https://kubernetes.io/) also use this service.
|
||||
|
||||
由于某些原因,在国内访问这些服务可能会比较慢。国内的一些云服务商提供了针对 Docker Hub 的镜像服务(`Registry Mirror`),这些镜像服务被称为 **加速器**。常见的有 [阿里云加速器](https://www.aliyun.com/product/acr?source=5176.11533457&userCode=8lx5zmtu)、[DaoCloud 加速器](https://www.daocloud.io/mirror#accelerator-doc) 等。使用加速器会直接从国内的地址下载 Docker Hub 的镜像,比直接从 Docker Hub 下载速度会提高很多。在 [安装 Docker](../install/mirror.md) 一节中有详细的配置方法。
|
||||
Due to some reasons knwon to all, accessing those services from China mainland is slow. There are some cloud service providers in China providing `Registry Mirror` for Docker Hub, those mirror services are called `accelerators`. The well-known ones are [Ali Cloud Image Accelerator](https://cr.console.aliyun.com/#/accelerator) and [DaoCloud Accelerator](https://www.daocloud.io/mirror#accelerator-doc). In China, downloading from these services are much faster than from Docker Hub. The detailed image source configuration tutorial is in the [Docker Installation](../install/mirror.md) section.
|
||||
|
||||
国内也有一些云服务商提供类似于 Docker Hub 的公开服务。比如 [网易云镜像服务](https://c.163.com/hub#/m/library/)、[DaoCloud 镜像市场](https://hub.daocloud.io/)、[阿里云镜像库](https://www.aliyun.com/product/acr?source=5176.11533457&userCode=8lx5zmtu) 等。
|
||||
There are also some cloud service providers that provide public services similar to Docker Hub in China. For example, [Tenxcloud Mirror Registry](https://hub.tenxcloud.com/), [NetEase Mirror Registry](https://c.163.com/hub#/m/library/), [DaoCloud Mirror Market](https://hub.daocloud.io/), [Ali Cloud Mirror Registry](https://cr.console.aliyun.com), etc.
|
||||
|
||||
## 私有 Docker Registry
|
||||
### Private Docker Registry
|
||||
|
||||
除了使用公开服务外,用户还可以在本地搭建私有 Docker Registry。Docker 官方提供了 [Docker Registry](https://hub.docker.com/_/registry/) 镜像,可以直接使用做为私有 Registry 服务。在 [私有仓库](../repository/registry.md) 一节中,会有进一步的搭建私有 Registry 服务的讲解。
|
||||
Apart from using public service, a user can set up private Docker Registry. Docker offical offers the [Docker Registry](https://hub.docker.com/_/registry/) docker image, which can be deployed for private registry service. We will explain how to set it up in detail in the [Private Registry](../repository/registry.md) section.
|
||||
|
||||
开源的 Docker Registry 镜像只提供了 [Docker Registry API](https://docs.docker.com/registry/spec/api/) 的服务端实现,足以支持 `docker` 命令,不影响使用。但不包含图形界面,以及镜像维护、用户管理、访问控制等高级功能。
|
||||
The open source Docker Registry image only provides the backend of [Docker Registry API](https://docs.docker.com/registry/spec/api/), which supports the `docker` commands and is enough for personal use, although the advanced functionalities like GUI(Graphical User Interface), Image Maintenance and Access Control are not supported. However, they are provided in the commercial version - [Docker Trusted Registry](https://docs.docker.com/datacenter/dtr/2.0/).
|
||||
|
||||
除了官方的 Docker Registry 外,还有第三方软件实现了 Docker Registry API,甚至提供了用户界面以及一些高级功能。比如,[Harbor](https://github.com/goharbor/harbor) 和 [Sonatype Nexus](../repository/nexus3_registry.md)。
|
||||
Except for the official Docker Registry, there are third-party softwares that implement Docker Registry API, even with some advanced features like user interface. For example, [Harbor](https://github.com/goharbor/harbor) and [Sonatype Nexus](../repository/nexus3_registry.md).
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"title": "Docker -- 从入门到实践",
|
||||
"title": "Docker Practice",
|
||||
"author": "yeasy",
|
||||
"language": "zh-hans",
|
||||
"language": "en",
|
||||
"links": {
|
||||
"sidebar": {
|
||||
"GitHub": "https://github.com/yeasy/docker_practice"
|
||||
@@ -19,14 +19,13 @@
|
||||
"attributes": {
|
||||
"width": "600"
|
||||
},
|
||||
"caption": "图 _PAGE_LEVEL_._PAGE_IMAGE_NUMBER_ - _CAPTION_"
|
||||
"caption": "Image _PAGE_LEVEL_._PAGE_IMAGE_NUMBER_ - _CAPTION_"
|
||||
},
|
||||
"github": {
|
||||
"url": "https://github.com/yeasy/docker_practice"
|
||||
},
|
||||
"editlink": {
|
||||
"base": "https://github.com/yeasy/docker_practice/blob/master/",
|
||||
"label": "编辑本页"
|
||||
"base": "https://github.com/yeasy/docker_practice/blob/english/"
|
||||
},
|
||||
"page-treeview": {
|
||||
"copyright": "Copyright © yeasy",
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
# Docker Buildx
|
||||
|
||||
Docker Buildx 是一个 docker CLI 插件,其扩展了 docker 命令,支持 [Moby BuildKit](buildkit.md) 提供的功能。提供了与 docker build 相同的用户体验,并增加了许多新功能。
|
||||
|
||||
> 该功能仅适用于 Docker v19.03+ 版本
|
||||
@@ -1,17 +0,0 @@
|
||||
# 使用 Buildx 构建镜像
|
||||
|
||||
## 使用
|
||||
|
||||
你可以直接使用 `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/
|
||||
@@ -1,121 +0,0 @@
|
||||
# 构建多种系统架构支持的 Docker 镜像
|
||||
|
||||
Docker 镜像可以支持多种系统架构,这意味着你可以在 `x86_64`、`arm64` 等不同架构的机器上运行同一个镜像。这是通过一个名为 "manifest list"(或称为 "fat manifest")的文件来实现的。
|
||||
|
||||
## Manifest List 是什么?
|
||||
|
||||
Manifest list 是一个包含了多个指向不同架构镜像的 manifest 的文件。当你拉取一个支持多架构的镜像时,Docker 会自动根据你当前的系统架构选择并拉取对应的镜像。
|
||||
|
||||
例如,官方的 `hello-world` 镜像就支持多种架构。你可以使用 `docker manifest inspect` 命令来查看它的 manifest list:
|
||||
|
||||
```bash
|
||||
$ docker manifest inspect hello-world
|
||||
{
|
||||
"schemaVersion": 2,
|
||||
"mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
|
||||
"manifests": [
|
||||
{
|
||||
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
|
||||
"size": 525,
|
||||
"digest": "sha256:80852a401a974d9e923719a948cc5335a0a4435be8778b475844a7153a2382e5",
|
||||
"platform": {
|
||||
"architecture": "amd64",
|
||||
"os": "linux"
|
||||
}
|
||||
},
|
||||
{
|
||||
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
|
||||
"size": 525,
|
||||
"digest": "sha256:3adea81344be1724b383d501736c3852939b33b3903d02474373700b25e5d6e3",
|
||||
"platform": {
|
||||
"architecture": "arm",
|
||||
"os": "linux",
|
||||
"variant": "v5"
|
||||
}
|
||||
},
|
||||
// ... more architectures
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 使用 `docker buildx` 构建多架构镜像
|
||||
|
||||
在 Docker 19.03+ 版本中,`docker buildx` 是推荐的用于构建多架构镜像的工具。它使用 `BuildKit` 作为后端,可以大大简化构建过程。
|
||||
|
||||
### 新建 `builder` 实例
|
||||
|
||||
首先,你需要创建一个新的 `builder` 实例,因为它支持同时为多个平台构建。
|
||||
|
||||
```bash
|
||||
$ docker buildx create --name mybuilder --use
|
||||
$ docker buildx inspect --bootstrap
|
||||
```
|
||||
|
||||
### 构建和推送
|
||||
|
||||
使用 `docker buildx build` 命令并指定 `--platform` 参数,可以同时构建支持多种架构的镜像。`--push` 参数会将构建好的镜像和 manifest list 推送到 Docker 仓库。
|
||||
|
||||
```dockerfile
|
||||
# Dockerfile
|
||||
FROM --platform=$TARGETPLATFORM alpine
|
||||
|
||||
RUN uname -a > /os.txt
|
||||
|
||||
CMD cat /os.txt
|
||||
```
|
||||
|
||||
```bash
|
||||
$ docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t your-username/multi-arch-image . --push
|
||||
```
|
||||
|
||||
构建完成后,你就可以在不同架构的机器上拉取并运行 `your-username/multi-arch-image` 这个镜像了。
|
||||
|
||||
### 架构相关的构建参数
|
||||
|
||||
在 `Dockerfile` 中,你可以使用一些预定义的构建参数来根据目标平台定制构建过程:
|
||||
|
||||
* `TARGETPLATFORM`: 构建镜像的目标平台,例如 `linux/amd64`。
|
||||
* `TARGETOS`: 目标平台的操作系统,例如 `linux`。
|
||||
* `TARGETARCH`: 目标平台的架构,例如 `amd64`。
|
||||
* `TARGETVARIANT`: 目标平台的变种,例如 `v7`。
|
||||
* `BUILDPLATFORM`: 构建环境的平台。
|
||||
* `BUILDOS`: 构建环境的操作系统。
|
||||
* `BUILDARCH`: 构建环境的架构。
|
||||
* `BUILDVARIANT`: 构建环境的变种。
|
||||
|
||||
例如,你可以这样编写 `Dockerfile` 来拷贝特定架构的二进制文件:
|
||||
|
||||
```dockerfile
|
||||
FROM scratch
|
||||
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
|
||||
COPY bin/dist-${TARGETOS}-${TARGETARCH} /dist
|
||||
|
||||
ENTRYPOINT ["/dist"]
|
||||
```
|
||||
|
||||
## 使用 `docker manifest` (底层工具)
|
||||
|
||||
`docker manifest` 是一个更底层的命令,可以用来创建、检查和推送 manifest list。虽然 `docker buildx` 在大多数情况下更方便,但了解 `docker manifest` 仍然有助于理解其工作原理。
|
||||
|
||||
### 创建 manifest list
|
||||
|
||||
```bash
|
||||
# 首先,为每个架构构建并推送镜像
|
||||
$ docker buildx build --platform linux/amd64 -t your-username/my-app:amd64 . --push
|
||||
$ docker buildx build --platform linux/arm64 -t your-username/my-app:arm64 . --push
|
||||
|
||||
# 然后,创建一个 manifest list,将它们组合在一起
|
||||
$ docker manifest create your-username/my-app:latest \
|
||||
--amend your-username/my-app:amd64 \
|
||||
--amend your-username/my-app:arm64
|
||||
|
||||
# 最后,推送 manifest list
|
||||
$ docker manifest push your-username/my-app:latest
|
||||
```
|
||||
|
||||
### 检查 manifest list
|
||||
|
||||
你可以使用 `docker manifest inspect` 来查看一个 manifest list 的详细信息,如上文所示。
|
||||
|
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 72 KiB |
@@ -1,7 +1,7 @@
|
||||
# CI/CD
|
||||
|
||||
**持续集成(Continuous integration)** 是一种软件开发实践,每次集成都通过自动化的构建(包括编译,发布,自动化测试)来验证,从而尽早地发现集成错误。
|
||||
持续集成(Continuous integration)是一种软件开发实践,每次集成都通过自动化的构建(包括编译,发布,自动化测试)来验证,从而尽早地发现集成错误。
|
||||
|
||||
**持续部署(continuous deployment)** 是通过自动化的构建、测试和部署循环来快速交付高质量的产品。
|
||||
持续部署(continuous deployment)是通过自动化的构建、测试和部署循环来快速交付高质量的产品。
|
||||
|
||||
与 `Jenkins` 不同的是,基于 Docker 的 CI/CD 每一步都运行在 Docker 容器中,所以理论上支持所有的编程语言。
|
||||
与 `Jenkins` 不同的是,基于 Docker 的 CI/CD 每一步都运行在 Docker 镜像中,所以理论上支持所有的编程语言。
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# GitHub Actions
|
||||
|
||||
GitHub [Actions](https://github.com/features/actions) 是 GitHub 推出的一款 CI/CD 工具。
|
||||
GitGub Actions 是 GitHub 推出的一款 CI/CD 工具。
|
||||
|
||||
我们可以在每个 `job` 的 `step` 中使用 Docker 执行构建步骤。
|
||||
我们可以在每个 job 的 step 中使用 Docker 执行构建步骤。
|
||||
|
||||
```yaml
|
||||
on: push
|
||||
@@ -25,4 +25,4 @@ jobs:
|
||||
|
||||
## 参考资料
|
||||
|
||||
* [Actions Docs](https://docs.github.com/en/actions)
|
||||
* [Actions Docs](https://help.github.com/en/categories/automating-your-workflow-with-github-actions)
|
||||
|
||||
@@ -86,14 +86,14 @@ $ git push origin master
|
||||
|
||||
打开我们部署好的 `Drone` 网站或者 Drone Cloud,即可看到构建结果。
|
||||
|
||||

|
||||

|
||||
|
||||
当然我们也可以把构建结果上传到 GitHub,Docker Registry,云服务商提供的对象存储,或者生产环境中。
|
||||
|
||||
本书 GitBook 也使用 Drone 进行 CI/CD,具体配置信息请查看本书根目录 [`.drone.yml`](../../../.drone.yml) 文件。
|
||||
本书 GitBook 也使用 Drone 进行 CI/CD,具体配置信息请查看本书根目录 [`.drone.yml`](https://github.com/yeasy/docker_practice/blob/master/.drone.yml) 文件。
|
||||
|
||||
## 参考链接
|
||||
|
||||
* [Drone Github](https://github.com/drone/drone)
|
||||
* [Drone 文档](https://docs.drone.io/)
|
||||
* [Drone 文档](http://docs.drone.io/)
|
||||
* [Drone 示例](https://github.com/docker-practice/drone-demo)
|
||||
|
||||
|
Before Width: | Height: | Size: 72 KiB |
@@ -1,9 +1,9 @@
|
||||
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
|
||||
drone-server:
|
||||
image: drone/drone:2.3.1
|
||||
image: drone/drone:1
|
||||
ports:
|
||||
- 443:443
|
||||
- 80:80
|
||||
@@ -12,6 +12,7 @@ services:
|
||||
- ./ssl:/etc/certs
|
||||
restart: always
|
||||
environment:
|
||||
- DRONE_AGENTS_ENABLED=true
|
||||
- DRONE_SERVER_HOST=${DRONE_SERVER_HOST:-drone.domain.com}
|
||||
- DRONE_SERVER_PROTO=${DRONE_SERVER_PROTO:-https}
|
||||
- DRONE_RPC_SECRET=${DRONE_RPC_SECRET:-secret}
|
||||
@@ -20,7 +21,7 @@ services:
|
||||
- DRONE_GITHUB_CLIENT_SECRET=${DRONE_GITHUB_CLIENT_SECRET}
|
||||
|
||||
drone-agent:
|
||||
image: drone/drone-runner-docker:1
|
||||
image: drone/agent:1
|
||||
restart: always
|
||||
depends_on:
|
||||
- drone-server
|
||||
|
||||
@@ -25,12 +25,12 @@
|
||||
我们通过使用 `Docker Compose` 来启动 `Drone`,编写 `docker-compose.yml` 文件。
|
||||
|
||||
```yaml
|
||||
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
|
||||
drone-server:
|
||||
image: drone/drone:2.3.1
|
||||
image: drone/drone:1
|
||||
ports:
|
||||
- 443:443
|
||||
- 80:80
|
||||
@@ -39,6 +39,7 @@ services:
|
||||
- ./ssl:/etc/certs
|
||||
restart: always
|
||||
environment:
|
||||
- DRONE_AGENTS_ENABLED=true
|
||||
- DRONE_SERVER_HOST=${DRONE_SERVER_HOST:-https://drone.yeasy.com}
|
||||
- DRONE_SERVER_PROTO=${DRONE_SERVER_PROTO:-https}
|
||||
- DRONE_RPC_SECRET=${DRONE_RPC_SECRET:-secret}
|
||||
@@ -47,7 +48,7 @@ services:
|
||||
- DRONE_GITHUB_CLIENT_SECRET=${DRONE_GITHUB_CLIENT_SECRET}
|
||||
|
||||
drone-agent:
|
||||
image: drone/drone-runner-docker:1
|
||||
image: drone/agent:1
|
||||
restart: always
|
||||
depends_on:
|
||||
- drone-server
|
||||
|
||||
47
cases/ci/travis/README.md
Normal file
@@ -0,0 +1,47 @@
|
||||
## 在 Travis CI 中使用 Docker
|
||||
|
||||
当代码提交到 GitHub 时,[Travis CI](https://travis-ci.com/) 会根据项目根目录 `.travis.yml` 文件设置的指令,执行一系列操作。
|
||||
|
||||
本小节介绍如何在 Travis CI 中使用 Docker 进行持续集成/持续部署(CI/CD)。这里以当代码提交到 GitHub 时自动构建 Docker 镜像并推送到 Docker Hub 为例进行介绍。
|
||||
|
||||
### 准备
|
||||
|
||||
首先登录 https://travis-ci.com/account/repositories 选择 GitHub 仓库,按照指引安装 GitHub App 来启用 GitHub 仓库构建。
|
||||
|
||||
在项目根目录新建一个 `Dockerfile` 文件。
|
||||
|
||||
```dockerfile
|
||||
FROM alpine
|
||||
|
||||
RUN echo "Hello World"
|
||||
```
|
||||
|
||||
新建 Travis CI 配置文件 `.travis.yml` 文件。
|
||||
|
||||
```yml
|
||||
language: bash
|
||||
|
||||
dist: xenial
|
||||
|
||||
services:
|
||||
- docker
|
||||
|
||||
before_script:
|
||||
# 登录到 docker hub
|
||||
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
|
||||
|
||||
script:
|
||||
# 这里编写测试代码的命令
|
||||
- echo "test code"
|
||||
|
||||
after_success:
|
||||
# 当代码测试通过后执行的命令
|
||||
- docker build -t username/alpine .
|
||||
- docker push username/alpine
|
||||
```
|
||||
|
||||
> 请提前在 Travis CI 仓库设置页面配置 `DOCKER_PASSWORD` `DOCKER_USERNAME` 变量
|
||||
|
||||
### 查看结果
|
||||
|
||||
将项目推送到 GitHub, 登录 [Travis CI](https://travis-ci.com/) 查看构建详情。
|
||||
16
cases/ci/travis/demo/.travis.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
language: bash
|
||||
|
||||
dist: xenial
|
||||
|
||||
services:
|
||||
- docker
|
||||
|
||||
before_script:
|
||||
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
|
||||
|
||||
script:
|
||||
- echo "test code"
|
||||
|
||||
after_success:
|
||||
- docker build -t username/alpine .
|
||||
- docker push username/alpine
|
||||
3
cases/ci/travis/demo/Dockerfile
Normal file
@@ -0,0 +1,3 @@
|
||||
FROM alpine
|
||||
|
||||
RUN echo "Hello World"
|
||||