docker image build
Build an image from a Dockerfile. The last argument is the build context path.
docker image build -t linuxacademy/weather-app:v1 .
Environment variables and build args
docker image build --env <KEY>=<VALUE> .
docker image build --build-arg <NAME>=<VALUE> .
Useful flags
-f, --file <string>— Dockerfile name.--force-rm— always remove intermediate containers.--label— set image metadata.--rm— remove intermediate containers after a successful build.--ulimit— ulimit options.
Alternative build methods
Pipe a Dockerfile from STDIN:
docker image build -t <NAME>:<TAG> -<<EOF
FROM nginx:latest
VOLUME ["/usr/share/nginx/html/"]
EOF
Build from a Git URL:
docker image build -t <NAME>:<TAG> <GIT_URL>#<REF>
docker image build -t <NAME>:<TAG> <GIT_URL>#:<DIRECTORY>
docker image build -t <NAME>:<TAG> <GIT_URL>#<REF>:<DIRECTORY>
Build from a compressed archive:
docker image build -t <NAME>:<TAG> - < <FILE>.tar.gz
Debugging failed builds
If a build fails, run the last successful layer interactively:
docker run -it <LAST_LAYER_ID>
Use the layer ID from the docker build output.
docker image tag
Assign a repository name and tag to an image.
During build:
docker image build -t <name>:<tag> .
docker image build --tag <name>:<tag> .
After build:
docker image tag <SOURCE_IMAGE>:<TAG> <TARGET_IMAGE>:<TAG>
If no tag is specified, latest is assumed.
Examples:
docker tag faa2b75ce09a newname
docker tag newname:latest amouat/newname
docker tag newname:latest amouat/newname:newtag
docker image ls
List local images with repository, tag, size, and ID.
docker image ls
docker image ls -q
Intermediate build layers are hidden by default. VIRTUAL SIZE includes all underlying layers (which may be shared across images). An image appears multiple times if it has multiple tags.
Remove dangling images:
docker rmi $(docker image ls -q -f dangling=true)
docker image history
Show each layer in an image.
docker image history <IMAGE>
docker image history --no-trunc <IMAGE>
docker image history --quiet <IMAGE>
docker image pull
Pull an image or repository from a registry.
docker image pull nginx
docker image push
Push an image to a registry. Register at open_in_new hub.docker.com first.
docker image tag <IMAGE_NAME>:<TAG> <USERNAME>/<IMAGE_NAME>:<TAG>
docker image push <USERNAME>/<IMAGE_NAME>:<TAG>
docker image inspect
Return low-level information: environment variables, default command, layers.
docker image inspect <IMAGE_ID>
docker image rm
Remove one or more images by ID or repository:tag. If only a repository name is given, latest is assumed.
For images shared across multiple repositories, specify the image ID and use -f.
docker image save
Save one or more images to a tar archive.
docker image save <IMAGE> > <FILE>.tar
docker image save <IMAGE> -o <FILE>.tar
docker image load
Load an image from a tar archive.
docker image load < <FILE>.tar
docker image load -i <FILE>.tar
Andrew Dorokhov