Skip to content
Rodrigo edited this page Oct 14, 2019 · 4 revisions

The aim of this page is to show several commands related to images on Docker 🐳. For instance, by using Docker CLI, we can search for an image by its name:

vagrant@ubuntu-xenial:~$ docker search alpine
NAME                                   DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
alpine                                 A minimal Docker image based on Alpine Linux…   5672                [OK]                
mhart/alpine-node                      Minimal Node.js built on Alpine Linux           441                                     
anapsix/alpine-java                    Oracle Java 8 (and 7) with GLIBC 2.28 over A…   422                                     [OK]
frolvlad/alpine-glibc                  Alpine Docker image with glibc (~12MB)          215                                     [OK]
gliderlabs/alpine                      Image based on Alpine Linux will help you wi…   180                                     
mvertes/alpine-mongo                   light MongoDB container                         105                                     [OK]
alpine/git                             A  simple git container running in alpine li…   98                                      [OK]
yobasystems/alpine-mariadb             MariaDB running on Alpine Linux [docker] [am…   48                                      [OK]
kiasaki/alpine-postgres                PostgreSQL docker image based on Alpine Linux   44                                      [OK]
alpine/socat                           Run socat command in alpine container           37                                      [OK]
davidcaste/alpine-tomcat               Apache Tomcat 7/8 using Oracle Java 7/8 with…   36                                      [OK]
zzrot/alpine-caddy                     Caddy Server Docker Container running on Alp…   35                                      [OK]
easypi/alpine-arm                      AlpineLinux for RaspberryPi                     32                                      
jfloff/alpine-python                   A small, more complete, Python Docker image …   27                                      [OK]
byrnedo/alpine-curl                    Alpine linux with curl installed and set as …   26                                      [OK]
hermsi/alpine-sshd                     Dockerize your OpenSSH-server with rsync and…   24                                      [OK]
etopian/alpine-php-wordpress           Alpine WordPress Nginx PHP-FPM WP-CLI           22                                      [OK]
hermsi/alpine-fpm-php                  Dockerize your FPM PHP 7.4 upon a lightweigh…   19                                      [OK]
bashell/alpine-bash                    Alpine Linux with /bin/bash as a default she…   14                                      [OK]
zenika/alpine-chrome                   Chrome running in headless mode in a tiny Al…   13                                      [OK]
davidcaste/alpine-java-unlimited-jce   Oracle Java 8 (and 7) with GLIBC 2.21 over A…   13                                      [OK]
tenstartups/alpine                     Alpine linux base docker image with useful p…   9                                       [OK]
spotify/alpine                         Alpine image with `bash` and `curl`.            9                                       [OK]
rawmind/alpine-traefik                 This image is the traefik base. It comes fro…   5                                       [OK]
hermsi/alpine-varnish                  Dockerize Varnish upon a lightweight alpine-…   1                                       [OK]

We can set filters:

vagrant@ubuntu-xenial:~$ docker search alpine --filter "is-official=true"
NAME                DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
alpine              A minimal Docker image based on Alpine Linux…   5672                [OK]              

And you can pull an image with a specific tag:

vagrant@ubuntu-xenial:~$ docker image pull alpine:latest
Using default tag: latest
latest: Pulling from library/alpine
9d48c3bd43c5: Pull complete 
Digest: sha256:72c42ed48c3a2db31b7dafe17d275b634664a708d901ec9fd57b1529280f01fb
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest

vagrant@ubuntu-xenial:~$ docker image list
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
alpine              latest              961769676411        4 weeks ago         5.58MB

Or if you want to pull all tags of a repository (:warning: not advisable):

vagrant@ubuntu-xenial:~$ docker image pull -a alpine

When we pull a Docker image... ¿ where is it located ? (/var(lib/docker/{{storage_driver}}, in this case, overlay2).

vagrant@ubuntu-xenial:~$ sudo -i
root@vagrant:~# cat /var/lib/docker/overlay2/l/JVUHQIN4DUQIEMRMDHXOESC347/etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.10.2
PRETTY_NAME="Alpine Linux v3.10"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"
root@ubuntu-xenial:~# logout
vagrant@ubuntu-xenial:~$ 

We can use docker image inspect in order to get hash of each layer:

vagrant@ubuntu-xenial:~$ docker image inspect --format "{{.RootFS}}:" alpine:latest 
{layers [sha256:03901b4a2ea88eeaad62dbe59b072b28b6efa00491962b8741081c5df50c65e0] }:

An useful command is docker image rm. We are going to pull some images and remove them by using a command:

vagrant@ubuntu-xenial:~$ docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
5667fdb72017: Pull complete 
d83811f270d5: Pull complete 
ee671aafb583: Pull complete 
7fc152dfb3a6: Pull complete 
Digest: sha256:b88f8848e9a1a4e4558ba7cfc4acc5879e1d0e7ac06401409062ad2627e6fb58
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest

vagrant@ubuntu-xenial:~$ docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
b8f262c62ec6: Pull complete 
a6639d774c21: Pull complete 
22a7aa8442bf: Pull complete 
Digest: sha256:9688d0dae8812dd2437947b756393eb0779487e361aa2ffbc3a529dca61f102c
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

vagrant@ubuntu-xenial:~$ docker image ls 
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              2ca708c1c9cc        4 days ago          64.2MB
nginx               latest              ab56bba91343        11 days ago         126MB
alpine              latest              961769676411        4 weeks ago         5.58MB

vagrant@ubuntu-xenial:~$ docker image ls -a 
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              2ca708c1c9cc        4 days ago          64.2MB
nginx               latest              ab56bba91343        11 days ago         126MB
alpine              latest              961769676411        4 weeks ago         5.58MB

vagrant@ubuntu-xenial:~$ docker image ls -a -q
2ca708c1c9cc
ab56bba91343
961769676411

vagrant@ubuntu-xenial:~$ docker image rm $(docker image ls -a -q)
Untagged: ubuntu:latest
Untagged: ubuntu@sha256:b88f8848e9a1a4e4558ba7cfc4acc5879e1d0e7ac06401409062ad2627e6fb58
Deleted: sha256:2ca708c1c9ccc509b070f226d6e4712604e0c48b55d7d8f5adc9be4a4d36029a
Deleted: sha256:bd416bed302bc2f061a2f6848a565483a5f265932d2d4fa287ef511b7d1151c8
Deleted: sha256:5308e2e4a70bd4344383b8de54f8a52b62c41afb5caa16310326debd1499b748
Deleted: sha256:dab02287e04c8b8207210b90b4056bd865fcfab91469f39a1654075f550c5592
Deleted: sha256:a1aa3da2a80a775df55e880b094a1a8de19b919435ad0c71c29a0983d64e65db
Untagged: nginx:latest
Untagged: nginx@sha256:9688d0dae8812dd2437947b756393eb0779487e361aa2ffbc3a529dca61f102c
Deleted: sha256:ab56bba91343aafcdd94b7a44b42e12f32719b9a2b8579e93017c1280f48e8f3
Deleted: sha256:57d7b96ffad6ea05fe17c800b518a2a04ff9cca78ba2ccd7b935f67a8106530f
Deleted: sha256:9d8204abdaaec18fe2d87a461ca9e67c31466b33c7b48c13c79b8286bde5739d
Deleted: sha256:2db44bce66cde56fca25aeeb7d09dc924b748e3adfe58c9cc3eb2bd2f68a1b68
Untagged: alpine:latest
Untagged: alpine@sha256:72c42ed48c3a2db31b7dafe17d275b634664a708d901ec9fd57b1529280f01fb
Deleted: sha256:961769676411f082461f9ef46626dd7a2d1e2b2a38e6a44364bcbecf51e66dd4
Deleted: sha256:03901b4a2ea88eeaad62dbe59b072b28b6efa00491962b8741081c5df50c65e0
Clone this wiki locally