Docker
2021-11-20 本文已影响0人
michael_jia
Docker 每个命令、每个选项,都有详尽的解释。
-
Why Docker?
2013: Containers are a standardized unit of software that allows developers to isolate their app from its environment, solving the “it works on my machine” headache. Cloud Native Computing Foundation (CNCF)
Glossary
- Docker Hub 上可以找到很多 container images。
-
Dockerfile
通过docker inspect
可以看到 dockerfile 的一些迹象。How can I see Dockerfile for each docker image?-
CentOS Dockerfile 示例
image.png
-
CentOS Dockerfile 示例
docker inspect:Return low-level information on Docker objects
docker inspect [OPTIONS] NAME|ID [NAME|ID...]
docker run:Run a command in a new container
$ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
-
--name <container-name>
: 指定 container name。Container identification 的一种。 -
-v
参数 VOLUME (shared filesystems)
--volume=[host-src:]container-dest[:<options>]
:
- The
host-src
can either be an absolute path or a name value. If you supply an absolute path for the host-src, Dockerbind-mounts
to the path you specify. If you supply a name, Docker creates anamed volume
by that name.- The
container-dest
must always be an absolute path such as /src/docs.
-
--mount
键值对,type 有3种值:bind, volume, tmpfs。- 使用
docker inspect <docker-name>
命令验证 bind mount 是否正确创建,查看Mounts
部分。
- 使用
Storage overview: Manage data in Docker
- Use bind mounts
-
Use volumes
Volumes are the preferred mechanism for persisting data generated by and used by Docker containers. -
Use tmpfs mounts
As opposed tovolumes
andbind mounts
, atmpfs
mount is temporary, and only persisted in the host memory. When the container stops, thetmpfs
mount is removed, and files written there won’t be persisted. 用于临时存储敏感文件等。