rimuovere delle istanze di docker

How To Remove Docker Images, Containers, and Volumes

UpdatedDecember 21, 2017 550.9k views Docker

A Docker Cheat Sheet

Introduction

Docker makes it easy to wrap your applications and services in containers so you can run them anywhere. As you work with Docker, however, it’s also easy to accumulate an excessive number of unused images, containers, and data volumes that clutter the output and consume disk space.

Docker gives you all the tools you need to clean up your system from the command line. This cheat sheet-style guide provides a quick reference to commands that are useful for freeing disk space and keeping your system organized by removing unused Docker images, containers, and volumes.

How to Use This Guide:

  • This guide is in cheat sheet format with self-contained command-line snippets
  • Jump to any section that is relevant to the task you are trying to complete.

The command substitution syntax, command $(command), used in the commands is available in many popular shells such as bash, zsh, and Windows Powershell.

Purging All Unused or Dangling Images, Containers, Volumes, and Networks

Docker provides a single command that will clean up any resources — images, containers, volumes, and networks — that are dangling (not associated with a container):

  • docker system prune

To additionally remove any stopped containers and all unused images (not just dangling images), add the -a flag to the command:

  • docker system prune -a

Removing Docker Images

Remove one or more specific images

Use the docker images command with the -a flag to locate the ID of the images you want to remove. This will show you every image, including intermediate image layers. When you’ve located the images you want to delete, you can pass their ID or tag to docker rmi:

List:

  • docker images -a

Remove:

  • docker rmi Image Image

Remove dangling images

Docker images consist of multiple layers. Dangling images are layers that have no relationship to any tagged images. They no longer serve a purpose and consume disk space. They can be located by adding the filter flag, -f with a value of dangling=true to the docker images command. When you’re sure you want to delete them, you can use the docker images purge command:

Note: If you build an image without tagging it, the image will appear on the list of dangling images because it has no association with a tagged image. You can avoid this situation by providing a tag when you build, and you can retroactively tag an images with the docker tag command.

List:

  • docker images -f dangling=true

Remove:

  • docker images purge

Removing images according to a pattern

You can find all the images that match a pattern using a combination of docker images and grep. Once you’re satisfied, you can delete them by using awk to pass the IDs to docker rmi. Note that these utilities are not supplied by Docker and are not necessarily available on all systems:

List:

  • docker images -a | grep “pattern

Remove:

  • docker images -a | grep “pattern” | awk ‘{print $3}’ | xargs docker rmi

Remove all images

All the Docker images on a system can be listed by adding -a to the docker images command. Once you’re sure you want to delete them all, you can add the -q flag to pass the Image ID to docker rmi:

List:

  • docker images -a

Remove:

  • docker rmi $(docker images -a -q)

Removing Containers

Remove one or more specific containers

Use the docker ps command with the -a flag to locate the name or ID of the containers you want to remove:

List:

  • docker ps -a

Remove:

  • docker rm ID_or_Name ID_or_Name

Remove a container upon exit

If you know when you’re creating a container that you won’t want to keep it around once you’re done, you can run docker run --rm to automatically delete it when it exits.

Run and Remove:

  • docker run –rm image_name

Remove all exited containers

You can locate containers using docker ps -a and filter them by their status: created, restarting, running, paused, or exited. To review the list of exited containers, use the -f flag to filter based on status. When you’ve verified you want to remove those containers, using -q to pass the IDs to the docker rm command.

List:

  • docker ps -a -f status=exited

Remove:

  • docker rm $(docker ps -a -f status=exited -q)

Remove containers using more than one filter

Docker filters can be combined by repeating the filter flag with an additional value. This results in a list of containers that meet either condition. For example, if you want to delete all containers marked as either Created (a state which can result when you run a container with an invalid command) or Exited, you can use two filters:

List:

  • docker ps -a -f status=exited -f status=created

Remove:

  • docker rm $(docker ps -a -f status=exited -f status=created -q)

Remove containers according to a pattern

You can find all the containers that match a pattern using a combination of docker ps and grep. When you’re satisfied that you have the list you want to delete, you can use awk and xargs to supply the ID to docker rmi. Note that these utilities are not supplied by Docker and not necessarily available on all systems:

List:

  • docker ps -a | grep “pattern

Remove:

  • docker ps -a | grep “pattern” | awk ‘{print $3}’ | xargs docker rmi

Stop and remove all containers

You can review the containers on your system with docker ps. Adding the -a flag will show all containers. When you’re sure you want to delete them, you can add the -q flag to supply the IDs to the docker stop and docker rm commands:

List:

  • docker ps -a

Remove:

  • docker stop $(docker ps -a -q)
  • docker rm $(docker ps -a -q)

Removing Volumes

Remove one or more specific volumes – Docker 1.9 and later

Use the docker volume ls command to locate the volume name or names you wish to delete. Then you can remove one or more volumes with the docker volume rm command:

List:

  • docker volume ls

Remove:

  • docker volume rm volume_name volume_name

Remove dangling volumes – Docker 1.9 and later

Since the point of volumes is to exist independent from containers, when a container is removed, a volume is not automatically removed at the same time. When a volume exists and is no longer connected to any containers, it’s called a dangling volume. To locate them to confirm you want to remove them, you can use the docker volume ls command with a filter to limit the results to dangling volumes. When you’re satisfied with the list, you can remove them all with docker volume prune:

List:

  • docker volume ls -f dangling=true

Remove:

  • docker volume prune

Remove a container and its volume

If you created an unnamed volume, it can be deleted at the same time as the container with the -v flag. Note that this only works with unnamed volumes. When the container is successfully removed, its ID is displayed. Note that no reference is made to the removal of the volume. If it is unnamed, it is silently removed from the system. If it is named, it silently stays present.

Remove:

  • docker rm -v container_name

Conclusion

This guide covers some of the common commands used to remove images, containers, and volumes with Docker. There are many other combinations and flags that can be used with each. For a comprehensive guide to what’s available, see the Docker documentation for docker system prune, docker rmi, docker rm and docker volume rm. If there are common cleanup tasks you’d like to see in the guide, please ask or make suggestions in the comments.



Disinstallare ESET per Linux

Per disinstallare questo antivirus… per linux dovete aprire un terminale e entrare in

cd /opt/eset/esets/bin

poi dare il comando

sudo ./esets_gil

ATTENZIONE SE OTTENETE IL SEGUENTE ERRORE
Invalid MIT-MAGIC-COOKIE-1 key
(esets_gil:15377): Gtk-WARNING **: cannot open display: :0

dovete dare il comando da temrinale

$xhost +si:localuser:root

per togliere l’utente

$xhost -si:localuser:root

 

Configurare infostrada con Asterisk Askozia

Salve,

infostrada offre con il servizio fibra un account sip per le sue chiamate. Per configurare un peer con asterisk è necessario la seguente configurazione:

type=peer
callerid=”390xxxxxxxxxx” <390xxxxxxxx>
username=390xxxxxxxx@sip.infostrada.it
secret=INSERIRE_LA_PASSWORD
fromuser=390xxxxxxxx
fromdomain=sip.infostrada.it
host=sip.infostrada.it
outboundproxy=voip.libero.it
insecure=port,invite
realm=sip.infostrada.it
port=5060
nat=yes
qualify=yes
regseconds=60
disallow=all
allow=alaw
allow=ulaw
allow=g729

Naturalmente la password e il numero di telefono sono da cambiare secondo i vostri dati. La risoluzione dell’URI voip.libero.it avviene ad opera dei server dns di infostrada. Se non siete connessi con loro dovete mettere l’indirizzo ip o inserire una voce nel vostro file host (voip.libero.it 151.6.123.166)

 

Problema con ttf-mscorefonts-installer

Potrebbe capitare un problema di installazione con il software

ttf-mscorefonts-installer

Come risolvere? Da shell con i permessi di root

sudo apt purge ttf-mscorefonts-installer

poi

wget
http://ftp.de.debian.org/debian/pool/contrib/m/msttcorefonts/ttf-mscorefonts-installer_3.6_all.deb
&& sudo apt install ./ttf-mscorefonts-installer_3.6_all.deb

Oppure

sudo dpkg-reconfigure ttf-mscorefonts-installer (questo comando va ripetuto alcune volte se dovesse verificarsi un problema di connessione con i mirror di sourceforge.net)

IP Statico TIM

Configurazione ADSL telecom anche con IP statico su router diversi

Il nome utente si ricava dall’indirizzo MAC del router Telecom (consegnato al momento dell’attivazione) seguito da una stringa costante. Mentre la password è default per tutte le connessioni busines ed è “alicenewag

Indicando invece la coppia username/password aliceadsl/aliceads, si perde l’eventuale IP Statico.

Protocollo:          PPoE

Incapsulazione:   LLC

VPI/VCI:             8 / 35

User Name:        xxyyzzxxyyzz-0013C8-t@alicebiz.it

Password:          alicenewag

xxyyzzxxyyzz: al posto di questa stringa bisogna inserire l’indirizzo MAC WAN del router che vi ha consegnato Telecom (lo trovate scritto sotto, è composto da 6 coppie alfanumeriche).

In alcuni casi funziona anche la coppia:

User: @alicebiz.routed
passw: @alicebiz.routed

 

Usare router TIM FIBRA come

Dopo avervi aiutato nello sblocco di questo dispositivo, con questa guida sarà possibile convertire il modem, in router puro per utilizzarlo come access point oppure come ata voip. L’unico requisito per eseguire questo cambio è ovviamente il root…

 E’ consigliato creare un backup della configurazione nel caso in cui si volesse tornare indietro

Andremo prima di tutto a pulire il modem dalle varie configurazioni per la pppoe e la parte adsl.

ATTENZIONE!
Prima di eseguire questi cambiamenti bisogna cambiare la classe di ip del modem… Se il router a cui si vorrà collegare il modem ha classe di ip 192.168.1.1 ovviamente il modem non dovrà e potrà avere la stessa classe di ip quindi dalla gui telecom cambiarla di conseguenza in qualcosa come 192.168.2.1. Nel caso in cui si mantenga la stessa classe non si potrà accedere al router collegato ma esclusivamente al modem.

Dare quindi i seguenti comandi

:ppp relay flush

:ppp flush

:eth flush

:atm flush

:atm phonebook flush

Ora andremo ad eliminare la porta WAN dalla configurazione per cui telecom l’ha settata inizialmente (in situazioni di connessioni FTTH in cui il collegamento si esegue con la medesima)

:eth bridge vlan ifdelete brname=bridge name=dummy intf=eth_wan

:eth bridge ifdelete brname=bridge intf=eth_wan

Andremo a settare il modem in WAN mode
:system config WANMode=ETH

Ora è tutto pronto per procedere alla conversione…

:eth ifadd intf=eth_wan

:eth ifconfig intf=eth_wan dest=ethif7 vlan=default

:eth ifattach intf=eth_wan

:ip ifadd intf=Internet dest=eth_wan

:ip ifconfig intf=Internet mtu=1500 linksensing=enabled group=wan acceptredir=disabled rpfilter=disabled ipv4=enabled ipv6=enabled curhoplimit=64 dadtransmits=1 retranstimer=1000 basereachabletime=30000 gctimer=600000 acceptra=disabled autoconf=disabled

:ip ifattach intf=Internet

E ora il fulcro, dove verrà settato il dhcp client

:dhcp client ifadd intf=Internet
:dhcp client ifconfig intf=Internet metric=0 dnsmetric=5 broadcast=enabled serverroute=disabled followlabel=disabled forcerenew=enabled leasehist=enabled localdns=enabled gracefulrestart=1 gracefulrestartcount=1
:dhcp client rqoptions add intf=Internet option=dhcp-lease-time
:dhcp client rqoptions add intf=Internet option=dhcp-renewal-time
:dhcp client rqoptions add intf=Internet option=dhcp-rebinding-time
:dhcp client rqoptions add intf=Internet option=subnet-mask
:dhcp client rqoptions add intf=Internet option=classless-static-routes
:dhcp client rqoptions add intf=Internet option=default-routers
:dhcp client rqoptions add intf=Internet option=classfull-static-routes
:dhcp client rqoptions add intf=Internet option=domain-name-servers
:dhcp client ifattach intf=Internet

Ora attiviamo il nat per il passaggio della connessione

:nat ifconfig intf=Internet translation=enabled

Disattiviamo il check dei led per l’aggancio alla portante così da non avere il led rosso sempre attivo per un errore non esistente.

:led config mode=all-led-blinking-in-trouble-state checkinternetservice=enabled checkbroadbandservice=disabled checkvoiceservice=enabled checkvideoservice=disabled

:system config defaultconnection=Internet

Procedere con un

:saveall

per confermare i cambiamenti e riavviare

Ora il modem prenderà in automatico l’ip da un qualsiasi modem/router che collegherete via lan alla porta WAN.
Il modem sarà accessibile dall’ip assegnato dal router a cui è collegato e l’access point configurato potrà accedere al router a cui è collegato internamente.

Correggere problemi di connessione voip

Per permettere la connessione al voip, bisognerà modificare l’outbound proxy e convertirlo in ip. Quindi eseguire il seguente comando modificandolo propriamente.

:voice sip config primproxyaddr=IP CONVERTITO

Mini Guida per convertire ims address in ip
Abbiamo xxxxx.co.imsw.telecomitalia.it (si può prendere dal file ini tranquillamente)

xxxxx cambia da persona a persona!
Digitare nel prompt dei comandi

nslookup
server 151.99.0.100
set q=srv
_sip._udp.xxxxx.co.imsw.telecomitalia.it

Dopo aver ottenuto il risultato in figura eseguire i seguenti comandi
set q=a
server xxxxxxxxx.co.imsw.telecomitalia.it (utilizzare l’address con priority 10)

A questo punto vi restituirà l’ip convertito

In questo modo non si sarà obbligati ad usare i dns telecom per effettuare la connessione voip!

Connessione PPP dedicata

Nel caso in cui il modem o il router support il pppoerelay (protocollo per permettere di creare una ulteriore connessione ppp su un dispositivo che non effettua collegamento alla centrale, telecom ne permette 10 contemporaneamente) e si voglia utilizzare il modem solo come ata voip è consigliato creare una connessione pppoe separata.
:ppp ifadd intf=Voip

:ppp ifconfig intf=Voip dest=eth_wan user=alice password=alice

:ppp ifattach intf=Voip

E quindi modifichiamo l’interfaccia da cui il voip dovrà collegarsi.

:voice config intf=Voip