Update SUMMARY

pull/411/head
khs1994 2019-05-14 00:16:13 +08:00
parent 8280d40922
commit 3b959abf68
No known key found for this signature in database
GPG Key ID: 0A380828B1C243A7
3 changed files with 140 additions and 484 deletions

View File

@ -1,4 +1,4 @@
# Docker
# Docker
[![](https://img.shields.io/github/stars/yeasy/docker_practice.svg?style=social&label=Stars)](https://github.com/yeasy/docker_practice) [![](https://travis-ci.org/yeasy/docker_practice.svg?branch=master)](https://travis-ci.org/yeasy/docker_practice) [![](https://img.shields.io/github/release/yeasy/docker_practice/all.svg)](https://github.com/yeasy/docker_practice/releases) [![](https://img.shields.io/badge/Based-Docker%20CE%20v18.x-blue.svg)](https://github.com/docker/docker-ce) [![](https://img.shields.io/badge/Docker%20%E6%8A%80%E6%9C%AF%E5%85%A5%E9%97%A8%E4%B8%8E%E5%AE%9E%E6%88%98-jd.com-red.svg)](https://union-click.jd.com/jdc?e=&p=AyIGZRtYFAcXBFIZWR0yEgRQH1kXAhs3EUQDS10iXhBeGlcJDBkNXg9JHU4YDk5ER1xOGRNLGEEcVV8BXURFUFdfC0RVU1JRUy1OVxUBFwNXGVscMlVYLlAaXAV1Z1JHA0dWEHVXZTliY1QLWStaJQAWB10fXhwKEDdlG1wlUHzf462DsLMO0%2F%2BUjp2VIgZlG18RBBcCUBlbEAoTBWUcWxwySVI7HAhBBxEOBUgOFQYQUGUraxYyIjdVK1glQHxXUEhYEVEUUFQcC0IHGgRRSAgVARAPAhsLFgNCDl0ZWiUAEwZREg%3D%3D&t=W1dCFFlQCxxKQgFHREkdSVJKSQVJHFRXFk9FUlpGQUpLCVBaTFhbXQtWVmpSWRtYEAYQBVUS)

View File

@ -1,16 +1,16 @@
# [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)
@ -18,139 +18,139 @@
* [Raspberry Pi](install/raspberry-pi.md)
* [macOS](install/mac.md)
* [Windows PC](install/windows.md)
* [](install/mirror.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)
* [](image/dockerfile/references.md)
* [Dockerfile ](image/multistage-builds/README.md)
* [ Laravel ](image/multistage-builds/laravel.md)
* [ Docker ](image/manifest.md)
* [使 BuildKit ](image/buildkit.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)
* [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)
* [访](network/port_mapping.md)
* [](network/linking.md)
* [ DNS](network/dns.md)
* [](advanced_network/README.md)
* [](advanced_network/quick_guide.md)
* [访](advanced_network/access_control.md)
* [](advanced_network/port_mapping.md)
* [ docker0 ](advanced_network/docker0.md)
* [](advanced_network/bridge.md)
* [](advanced_network/example.md)
* [](advanced_network/config_file.md)
* [](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)
* [Docker Machine ](machine/README.md)
* [](machine/install.md)
* [使](machine/usage.md)
* [Docker Docker Swarm](swarm/README.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)
* [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 Machine](machine/README.md)
* [Install](machine/install.md)
* [Usage](machine/usage.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)
* [CoreOS ](coreos/README.md)
* [](coreos/intro.md)
* [](coreos/intro_tools.md)
* [ CoreOS ](coreos/quickstart.md)
* [Kubernetes ](kubernetes/README.md)
* [](kubernetes/intro.md)
* [](kubernetes/quickstart.md)
* [](kubernetes/concepts.md)
* [kubectl 使](kubernetes/kubectl.md)
* [](kubernetes/design.md)
* [Mesos - ](mesos/README.md)
* [Mesos ](mesos/intro.md)
* [使](mesos/installation.md)
* [](mesos/architecture.md)
* [Mesos ](mesos/configuration.md)
* [](mesos/monitor.md)
* [](mesos/framework.md)
* [](mesos/summary.md)
* [](cloud/README.md)
* [](cloud/intro.md)
* [](cloud/aws.md)
* [](cloud/tencentCloud.md)
* [](cloud/alicloud.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)
* [CoreOS Cluster](coreos/quickstart.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)
* [Mesos](mesos/README.md)
* [Introduction](mesos/intro.md)
* [Install](mesos/installation.md)
* [Arch](mesos/architecture.md)
* [Config](mesos/configuration.md)
* [Monitor](mesos/monitor.md)
* [Framework](mesos/framework.md)
* [SUMMARY](mesos/summary.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)
* [Drone](cases/ci/drone.md)
* [Travis CI](cases/ci/travis.md)
* [Docker ](opensource/README.md)
* [Docker Open Source](opensource/README.md)
* [LinuxKit](opensource/linuxkit.md)
* [](appendix/README.md)
* [](appendix/faq/README.md)
* [](appendix/repo/README.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)
@ -160,7 +160,6 @@
* [MongoDB](appendix/repo/mongodb.md)
* [Redis](appendix/repo/redis.md)
* [Node.js](appendix/repo/nodejs.md)
* [Docker ](appendix/command/README.md)
* [Dockerfile ](appendix/best_practices.md)
* [ Docker](appendix/debug.md)
* [](appendix/resources.md)
* [Docker commands](appendix/command/README.md)
* [Docker debug](appendix/debug.md)
* [Resources](appendix/resources.md)

View File

@ -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/linking.md)
###
`Dockerfile`
###
便 `PRs` `\`
`buildpack-deps`
```dockerfile
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` `#`
>使使
```dockerfile
# 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`
```dockerfile
# 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`
```dockerfile
RUN apt-get update && apt-get install -y \
package-bar \
package-baz \
package-foo
```
`apt-get update` `RUN` `apt-get install` `Dockerfile`
```dockerfile
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install -y curl
```
Docker `apt-get install`
```dockerfile
FROM ubuntu:18.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`
```dockerfile
RUN apt-get update && apt-get install -y \
package-bar \
package-baz \
package-foo=1.3.*
```
使
`RUN` `apt-get`
```dockerfile
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 udpate`
apt `var/lib/apt/lists` `RUN` `apt-get udpate` `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`
```dockerfile
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`
```dockerfile
COPY requirements.txt /tmp/
RUN pip install --requirement /tmp/requirements.txt
COPY . /tmp/
```
`COPY . /tmp/` `RUN` `.`
使 `ADD` URL 使 `curl` `wget`
```dockerfile
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
```
使
```dockerfile
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`:
```dockerfile
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`
```dockerfile
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/)