本文是对官方文档的总结与备注。
官方文档:https://docs.docker.com/develop/
根据官方文档的层次,分为
Containers
) 使用 Docker run
Services
) 使用 Docker Compose
Defines how containers behave in productionStack
) 使用 Swarm mode
Defining the interactions of all the servicesDockerfile
构建镜像multistage builds
保持镜像最小Volume
和 bind mounts
管理数据docker swarm
部署服务docker stack
部署服务栈 compose 文件
Docker 开发最佳实践
openjdk
镜像,而不要基于 ubuntu
安装 openjdk
multistage builds
. 使用多阶段构建,如果你的 Docker 版本不支持 多阶段构建
,请请尽可能减少镜像层数。prod
或者 test
,尽量不使用 latest
标签。应用数据如何存储,存放在哪里
避免
将数据存放在镜像中volumes
存放数据bind mounts
,在生产环境使用 volume
secrets
存储敏感数据,使用 configs
存储非敏感数据,比如配置文件Swarm mode
Swarm mode
能提供更多的功能Swarm
服务,网络和数据卷能够连接和断开服务
中可用,比如 secrets
config
,上一部分已经提到docker stack deploy
pull 镜像,而不是使用 docker pull
Pull request
,使用 Docker Cloud 或者其他 CI/CD 自动构建镜像和创建镜像标签并自动测试镜像。Docker cloud 可以把测试通过的镜像部署到生产环境中。Development | Production |
---|---|
Use bind mounts to give your container access to your source code. | Use volumes to store container data. |
Use Docker for Mac or Docker for Windows. | Use Docker EE if possible, with userns mapping for greater isolation of Docker processes from host processes. |
Don’t worry about time drift. | Always run an NTP client on the Docker host and within each container process and sync them all to the same NTP server. If you use swarm services, also ensure that each Docker node syncs its clocks to the same time source as the containers. |
https://cloud.tencent.com/developer/article/1047173