ubuntu:docker:docker_images_vs._container
Differences
This shows you the differences between two versions of the page.
ubuntu:docker:docker_images_vs._container [2019/11/27 01:05] – created peter | ubuntu:docker:docker_images_vs._container [2020/04/15 18:55] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Ubuntu - Docker - Docker Images vs. Container ====== | ||
- | |||
- | Docker has images and containers. | ||
- | |||
- | ---- | ||
- | |||
- | ===== Docker Images ===== | ||
- | |||
- | Images are basically a template used to create containers. | ||
- | |||
- | An image is an inert, immutable, file that's essentially a snapshot of a container. | ||
- | |||
- | Local images can be listed by running: | ||
- | |||
- | <code bash> | ||
- | docker images | ||
- | </ | ||
- | |||
- | returns: | ||
- | |||
- | <code bash> | ||
- | REPOSITORY | ||
- | ubuntu | ||
- | ubuntu | ||
- | ubuntu | ||
- | ubuntu | ||
- | < | ||
- | </ | ||
- | |||
- | Some things to note: | ||
- | |||
- | * **IMAGE ID** is the first 12 characters of the true identifier for an image. You can create many tags of a given image, but their IDs will all be the same (as above). | ||
- | * **VIRTUAL SIZE** is virtual because its adding up the sizes of all the distinct underlying layers. | ||
- | * The value in the **REPOSITORY** column comes from the -t flag of the docker build command, or from docker tag-ing an existing image. | ||
- | * The full form of a tag is [REGISTRYHOST/ | ||
- | * The **TAG** column is just the [:TAG] part of the full tag. This is unfortunate terminology. | ||
- | * The latest tag is not magical, it's simply the default tag when you don't specify a tag. | ||
- | * You can have untagged images only identifiable by their **IMAGE ID**s. | ||
- | |||
- | More info on images is available from the [[https:// | ||
- | |||
- | ---- | ||
- | |||
- | ===== Docker Containers ===== | ||
- | |||
- | To use a programming metaphor, if an image is a class, then a container is an instance of a class — a runtime object. | ||
- | |||
- | View local running containers by running: | ||
- | |||
- | <code bash> | ||
- | docker ps | ||
- | </ | ||
- | |||
- | returns: | ||
- | |||
- | <code bash> | ||
- | CONTAINER ID IMAGE | ||
- | f2ff1af05450 | ||
- | </ | ||
- | |||
- | Here I'm running a dockerized version of the docker registry, so that I have a private place to store my images. | ||
- | |||
- | - Like **IMAGE ID**, **CONTAINER ID** is the true identifier for the container. | ||
- | - docker ps only outputs running containers. | ||
- | - **NAMES** can be used to identify a started container via the **< | ||
- | |||
- | ---- | ||
- | |||
- | ===== How to avoid image and container build-up ===== | ||
- | |||
- | There' | ||
- | |||
- | We can remove all untagged images by combining **docker rmi** with the recent **dangling=true** query: | ||
- | |||
- | <code bash> | ||
- | docker images -q --filter " | ||
- | </ | ||
- | |||
- | Docker won't be able to remove images that are behind existing containers, so you may have to remove stopped containers with **docker rm** first: | ||
- | |||
- | <code bash> | ||
- | docker rm `docker ps --no-trunc -aq` | ||
- | </ | ||
- | |||
- | These are known pain points with Docker, and may be addressed in future releases. | ||
- | |||
- | - Always remove a useless, stopped container with **docker rm [CONTAINER_ID]**. | ||
- | - Always remove the image behind a useless, stopped container with **docker rmi [IMAGE_ID]**. | ||
ubuntu/docker/docker_images_vs._container.1574816735.txt.gz · Last modified: 2020/07/15 09:30 (external edit)