Docker image commands

How to build and manage docker images

view on github

Docker images management

Table of contents

  1. Image commands
  2. Registry commands

Image commands

List all images

docker image ls -a

Create a new image

# build image according to current directory's Dockerfile
docker build -t "$image" .

Delete an image

# delete a specific image
docker image rm "$image"

# delete all images not used by at least 1 container
docker image prune -f

Registry commands

Authenticate Docker daemon to a registry

# important : does not work on pseudo-TTY, it is thus impossible to login through SSH
# authenticating to a docker registry requires a real TTY and direct access to the machine
docker login

Tag $image for upload to the configured registry

# username is mandatory to avoid collision with similarly named images
docker tag "$image" username/repository:tag

Upload tagged image to the configured registry

# username is mandatory to avoid collision with similarly named images
docker push username/repository:tag

Pull image from the configured registry

# pull image locally
docker pull "$image"

# pull image and run CMD/ENTRYPOINT Dockerfile directive
docker container run username/repository:tag