Managing Docker images and containers effectively is a core skill for any developer or sysadmin working with containers. This guide covers the essential commands for building, tagging, pushing, listing, inspecting, and cleaning up Docker images and containers on Ubuntu 26.04 LTS.

Tested and valid on:

  • Ubuntu 26.04 LTS

Prerequisites

  • Ubuntu 26.04 LTS with Docker Engine installed
  • A user in the docker group

Step 1 – Working with Images

docker images                          # list local images
docker pull nginx:alpine               # download an image
docker inspect nginx:alpine            # detailed metadata
docker image history nginx:alpine      # layer history
docker rmi nginx:alpine                # remove image

Step 2 – Building Images

# Create a Dockerfile:
cat > Dockerfile << 'EOF'
FROM ubuntu:26.04
RUN apt-get update && apt-get install -y curl
CMD ["bash"]
EOF
docker build -t myimage:latest .
docker build -t myimage:v1.0 --no-cache .

Step 3 – Tagging and Pushing

docker tag myimage:latest registry.example.com/myimage:v1.0
docker push registry.example.com/myimage:v1.0

Step 4 – Running Containers

docker run -d --name myapp -p 8080:80 nginx:alpine   # detached
docker run -it ubuntu:26.04 bash                      # interactive
docker run --rm ubuntu echo 'hello'                   # auto-remove

Step 5 – Managing Running Containers

docker ps                  # list running
docker ps -a               # list all
docker stop myapp          # graceful stop
docker start myapp         # start stopped
docker restart myapp       # restart
docker rm myapp            # remove stopped
docker logs -f myapp       # follow logs

Step 6 – Exec Into a Container

docker exec -it myapp /bin/sh
docker exec myapp env     # run single command

Step 7 – Clean Up Unused Resources

docker system prune -a            # remove all unused
docker image prune -a             # remove all dangling images
docker container prune            # remove stopped containers
docker volume prune               # remove unused volumes
docker system df                  # disk usage

Conclusion

You now have a solid command of Docker image and container management on Ubuntu 26.04 LTS. Combine these commands with Dockerfiles and Docker Compose for a complete containerisation workflow.