docker build [-t NAME:TAG]... [-f DOCKERFILE] CONTEXT| Flag | Purpose |
|---|---|
-t status-page:1.0 | Tag the result. Repeat for more tags |
-f Dockerfile.dev | Use another Dockerfile (default: CONTEXT/Dockerfile) |
--no-cache | Rebuild every step (lesson 8) |
-q | Print only the image ID |
Tags
registry.example.com/platform/status-page:1.0
└──── registry ────┘ └namespace┘└─ repo ──┘└tag┘- Without a registry, the image is local (and
docker.iowhen pushed). Chapter 8 covers registries. - Without a tag, Docker uses
latest.latestis only a name; it is not updated automatically. - Repository names must be lowercase:
learner@pier:~/status-page$ docker build -t Status-Page:1.0 .
ERROR: invalid tag "Status-Page:1.0": invalid reference format: repository name must be lowercaseA tag is a pointer to an image ID. One image can have many tags:
learner@pier:~/status-page$ docker build -t status-page:1.0 -t status-page:latest .
...
=> => naming to docker.io/library/status-page:1.0 0.0s
=> => naming to docker.io/library/status-page:latest 0.0sdocker tag status-page:1.0 status-page:stable adds a tag to an existing image without building.
Releasing a new version
Build the new version under its own tag and move latest:
learner@pier:~/status-page$ docker build -t status-page:1.1 -t status-page:latest .
learner@pier:~/status-page$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
status-page 1.1 5d21aa324468 4 seconds ago 139MB
status-page latest 5d21aa324468 4 seconds ago 139MB
status-page dev 55753b2db040 10 seconds ago 139MB
status-page 1.0 257d9bfc85ae 23 seconds ago 139MB1.0 still points at the old build, so you can roll back by running it.
Dangling images
Rebuilding the same tag moves it to the new image. The old one keeps its ID and loses its name:
learner@pier:~/status-page$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
status-page 1.0 924e43dd9e66 4 seconds ago 139MB
<none> <none> 60c345359349 10 seconds ago 139MBbuild 1: status-page:1.0 ──▶ 60c345359349
build 2: status-page:1.0 ──▶ 924e43dd9e66 60c345359349 is now <none>:<none>List and remove them:
docker images -f dangling=true
docker image prunedocker image prune asks for confirmation and deletes only untagged images that no container uses. Add -f to skip the prompt in scripts.
Another Dockerfile, same context
Keep variants side by side and pick one with -f:
~/status-page/
├── Dockerfile production: npm install --omit=dev
└── Dockerfile.dev development: all dependencies, node --watchdocker build -f Dockerfile.dev -t status-page:dev .The build output names the file: load build definition from Dockerfile.dev.