Docker: Difference between revisions

From DWIKI
Tony (talk | contribs)
Tag: wikieditor
Tony (talk | contribs)
 
(13 intermediate revisions by the same user not shown)
Line 11: Line 11:
*[https://runnable.com/docker/basic-docker-networking Docker networking]
*[https://runnable.com/docker/basic-docker-networking Docker networking]
*[https://docs.docker.com/config/pruning/ Docker pruning]
*[https://docs.docker.com/config/pruning/ Docker pruning]
*[https://www.virtualizationhowto.com/2023/11/docker-overlay2-cleanup-5-ways-to-reclaim-disk-space/ Docker Overlay2 Cleanup: 5 Ways to Reclaim Disk Space]


=HOWTO=
=HOWTO=
 
==Run container==
docker run <IMAGE ID>
==List running containers==
==List running containers==
  docker ps
  docker ps
Line 20: Line 22:
  docker ps -a
  docker ps -a


==Start container==
docker start <name>
name as found with docker ps -a
==Add parameter to existing container==
docker update --my-param 1234 mycontainer
==Show log==
docker logs <container>
or to follow:
docker logs -f <container>
==Show disk usage==
==Show disk usage==
*https://niklasmtj.de/blog/understand-docker-storage/
  docker system df
  docker system df
outputs:
outputs:
  TYPE            TOTAL    ACTIVE    SIZE      RECLAIMABLE
  TYPE            TOTAL    ACTIVE    SIZE      RECLAIMABLE
Line 30: Line 45:
===RECLAIMABLE===
===RECLAIMABLE===
Is what you get back when running
Is what you get back when running
  docker prune a
  docker system prune -a


==List images==
==List images==
  docker images
  docker images
==Remove image==
===docker rm===
removes container
docker ps -a
and then
docker rm <container id>
===docker rmi===
alias for '''docker image rm'''
docker image ls
and then
docker rmi <ID>


==Export image==
==Export image==
  docker save <image name> > imagename.tar
  docker save <image name> > imagename.tar
==Update image==
docker pull imagename


==Get shell in running container==
==Get shell in running container==
Line 51: Line 87:
==image has dependent child images==
==image has dependent child images==
  docker inspect --format='{{.Id}} {{.Parent}}' $(docker images --filter since=<image_id> -q)
  docker inspect --format='{{.Id}} {{.Parent}}' $(docker images --filter since=<image_id> -q)
or get [https://github.com/justone/dockviz dockviz] and run
dockviz images --tree -l


==Dangling images==
==Dangling images==
Line 81: Line 119:
===The container name "/mycontainer" is already in use by container===
===The container name "/mycontainer" is already in use by container===
It already exists, so use
It already exists, so use
  docker start
  docker start <container id>
instead of
instead of
  docker run
  docker run
Line 125: Line 163:
=== image is being used by stopped container===
=== image is being used by stopped container===
use the force
use the force
==Docker rmi not freeing space==
Correct, you need
docker image prune

Latest revision as of 09:14, 10 June 2026

Links


Docs

HOWTO

Run container

docker run <IMAGE ID>

List running containers

docker ps

List containers

docker ps -a

Start container

docker start <name>

name as found with docker ps -a

Add parameter to existing container

docker update --my-param 1234 mycontainer

Show log

docker logs <container>

or to follow:

docker logs -f <container>

Show disk usage

docker system df

outputs:

TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          27        10        11.35GB   5.72GB (50%)
Containers      12        12        123.6MB   0B (0%)
Local Volumes   0         0         0B        0B
Build Cache     0         0         0B        0B

RECLAIMABLE

Is what you get back when running

docker system prune -a

List images

docker images

Remove image

docker rm

removes container

docker ps -a

and then

docker rm <container id>

docker rmi

alias for docker image rm

docker image ls

and then

docker rmi <ID>



Export image

docker save <image name> > imagename.tar


Update image

docker pull imagename


Get shell in running container

To get image name

docker ps

then

docker exec -it <image-id> bash

Network

docker network ls
docker network inspect


image has dependent child images

docker inspect --format='Template:.Id Template:.Parent' $(docker images --filter since=<image_id> -q)

or get dockviz and run

dockviz images --tree -l

Dangling images

list dangling images

docker images -f dangling=true

Remove dangling image

docker rmi image-id

Errors/warnings

Error response from daemon: conflict: unable to delete 9e82ccb228df (must be forced) - image is being used by stopped container a14fb2b549f1

Find the culprit with

docker ps -a

and then

docker rm <id you find>

Remove all dangling images

docker rmi $(docker images -f dangling=true -q)

image is being used by stopped container xyz

docker rm xyz

and try again


Backups

FAQ

Error messages

The container name "/mycontainer" is already in use by container

It already exists, so use

docker start <container id>

instead of

docker run

OR find the culprit

docker ps -a

and then

docker rm container/name

etc

ERROR: failed to solve: failed to read dockerfile: open Dockerfile: no such file or directory

It really wants a file called Dockerfile

docker.service: Start request repeated too quickly

Try

dockerd --debug

dial unix /var/run/docker.sock: connect: permission denied

You're not in group docker


docker rmi

Error response from daemon: reference does not exist

See https://www.baeldung.com/linux/docker-image-deletion-problem-fix


Address already in use

First try

lsof -i:8080

Compose

unknown shorthand flag: 'd' in -d

docker-compose is probably a script/wrapper. Install the https://docs.docker.com/engine/install/debian/

docker: 'compose' is not a docker command.

Check https://docs.docker.com/engine/install/debian/

unknown flag: --detach

apt install docker-compose-v2


image is being used by stopped container

use the force


Docker rmi not freeing space

Correct, you need

docker image prune