Docker: Difference between revisions

From DWIKI
 
(30 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Links=
=Links=
*[https://www.docker.com/ Homepage]
=Docs=
*[https://docs.docker.com/compose Docker-compose]
*https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-centos-7
*https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-centos-7
*[https://www.digitalocean.com/community/tutorials/how-to-remove-docker-images-containers-and-volumes Removing images, containers and volumes]
*[https://training.play-with-docker.com/beginner-linux/ Docker for beginners]
*[https://runnable.com/docker/basic-docker-networking Docker networking]
*[https://docs.docker.com/config/pruning/ Docker pruning]
=HOWTO=


=FAQ=
==List running containers==
==List running containers==
  docker ps
  docker ps


==Get shell in container==
==List containers==
docker ps -a
 
==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 prune a
 
==List images==
docker images
 
==Export image==
docker save <image name> > imagename.tar
 
==Get shell in running container==
To get image name
To get image name
  docker ps
  docker ps
then
then
  docker run --it <imagename> bash
  docker exec -it <image-id> bash
 
==Network==
docker network ls
docker network inspect
 
 
==image has dependent child images==
docker inspect --format='{{.Id}} {{.Parent}}' $(docker images --filter since=<image_id> -q)
 
==Dangling images==
===list dangling images===
docker images -f dangling=true
 
===Remove dangling image===
docker rmi image-id
 
===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==
==Backups==
*https://linuxconfig.org/docker-container-backup-and-recovery
*https://linuxconfig.org/docker-container-backup-and-recovery
*[https://bobcares.com/blog/docker-backup/ Docker - Easy backup & restore]
*[https://bobcares.com/blog/docker-backup/ Docker - Easy backup & restore]
=FAQ=
==Error messages==
===The container name "/mycontainer" is already in use by container===
It already exists, so use
docker start
instead of
docker run
===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
==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

Latest revision as of 11:55, 18 November 2024

Links


Docs

HOWTO

List running containers

docker ps

List containers

docker ps -a

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 prune a

List images

docker images

Export image

docker save <image name> > imagename.tar

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)

Dangling images

list dangling images

docker images -f dangling=true

Remove dangling image

docker rmi image-id

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

instead of

docker run

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

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