基本原则

  • 官方镜像优于非官方的镜像,如果没有官方镜像,则尽量选择Dockerfile开源的
  • 固定版本tag而不是每次都使用latest
  • 尽量选择体积小的镜像
  1. $ docker image ls
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. bitnami/nginx 1.18.0 dfe237636dde 28 minutes ago 89.3MB
  4. nginx 1.21.0-alpine a6eb2a334a9f 2 days ago 22.6MB
  5. nginx 1.21.0 d1a364dc548d 2 days ago 133MB

Build一个Nginx镜像

假如我们有一个 index.html 文件

  1. <h1>Hello Docker</h1>

准备一个Dockerfile

  1. FROM nginx:1.21.0-alpine
  2. ADD index.html /usr/share/nginx/html/index.html

延申阅读