Docker Notes
T

如何选择基础镜像 FROM

  • DockerHub 上选择时建议勾选 Official Images(Official Images Published By Docker)
  • tag 指定详细版本号,不要使用 latest。因为 latest 会根据版本号改变。
  • alpine 镜像时建议使用。

基本原则

  • 官方镜像优于非官方的镜像,如果没有官方镜像,则尽量选择 Dockerfile 开源的
  • 固定版本 tag 而不是每次都使用 latest
  • 尽量选择体积小的镜像

练习 - 构建 nginx image

编写 index.html, hello.nginx.alpine.Dockerfilehello.nginx.Dockerfile 文件,然后根据 Dockerfile 构建镜像,查看两个镜像差异。

#i ndex.html
<h1>hello nginx, hello jaime</h1>

# hello.nginx.alpine.Dockerfile
FROM nginx:1.21.5-alpine
COPY index.html /usr/share/nginx/html/index.html

# hello.nginx.Dockerfile
FROM nginx:1.21.5
COPY index.html /usr/share/nginx/html/index.html

dockerfile-from

Show Graph Visualisation