Ne approfitto per fare un breve cenno a come si è evoluta la CLI (Command Line Interface) negli ultimi tempi, in modo da chiarire perché a volte sia possibile trovare alcuni comandi con una sintassi differente.

Avrei potuto prendere un comando già visto ma dato che ci siamo, impariamo qualcosa di nuovo. Prendiamo quindi:

docker image inspect

Questo comando restituisce un oggetto in formato json con i metadati dell’immagine specificata per parametro.

Eseguendo:

docker image inspect alpine

Ottenendo il seguente risultato:

[
    {
        "Id": "sha256:f70734b6a266dcb5f44c383274821207885b549b75c8e119404917a61335981a",
        "RepoTags": [
            "alpine:latest"
        ],
        "RepoDigests": [
            "alpine@sha256:9a839e63dad54c3a6d1834e29692c8492d93f90c59c978c1ed79109ea4fb9a54"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2020-04-24T01:05:03.92860976Z",
        "Container": "d3de5454dd4538da6ccb451b8fe1574b2efc482f958b04e6d109f123198d3d30",
        "ContainerConfig": {
            "Hostname": "d3de5454dd45",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) ",
                "CMD [\"/bin/sh\"]"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:fce4411719cb54972247bbe799cf1dd74ecffda05bad4909df5224000dfd070e",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "DockerVersion": "18.09.7",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/sh"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:fce4411719cb54972247bbe799cf1dd74ecffda05bad4909df5224000dfd070e",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 5612304,
        "VirtualSize": 5612304,
        "GraphDriver": {
            "Data": {
                "MergedDir": "/var/lib/docker/overlay2/bb0a38faf8a51dd52fed8883ddefe73effab9736c4f67eea46a78a3ad4de4bc2/merged",
                "UpperDir": "/var/lib/docker/overlay2/bb0a38faf8a51dd52fed8883ddefe73effab9736c4f67eea46a78a3ad4de4bc2/diff",
                "WorkDir": "/var/lib/docker/overlay2/bb0a38faf8a51dd52fed8883ddefe73effab9736c4f67eea46a78a3ad4de4bc2/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:3e207b409db364b595ba862cdc12be96dcdad8e36c59a03b7b3b61c946a5741a"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]

vedremo diversi hash, tag architettura di riferimento, versione di Docker e molte altre informazioni su che a mio avviso ha senso approfondire, soprattutto in questa fase. 

La cosa strana è che eseguendo:

docker inspect alpine

otteniamo esattamente lo stesso risultato.

Perché ci sono due modi diversi di eseguire lo stesso comando?

Questo avviene perché la CLI di Docker ha cambiato la sua notazione ed ora utilizza dei sotto-comandi per evitare di avere dei conflitti sui nomi e per rendere il tutto più chiaro.

Docker Inc. vorrebbe abbandonare il supporto alla notazione precedente, per capirci, quella senza i sotto-comandi. Ad oggi sono ancora operativi e siccome questo potrebbe rompere molti script su cui Docker non ha controllo è possibile che possa non avvenire nell’immediato (o forse non avvenire mai). Consiglio personale, abituiamoci ad usare la nuova notazione così ci proteggiamo da eventuali rimozioni di comandi legacy e evitiamo di incorrere in spiacevoli inconvenienti.

Ma quali sono questi sottocomandi?

Eseguiamo il comando “docker”, senza alcun parametro.

Usage:	docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default "/Users/fabioros/.docker")
  -c, --context string     Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default
                           context set with "docker context use")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket(s) to connect to
  -l, --log-level string   Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default "/Users/fabioros/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default "/Users/fabioros/.docker/cert.pem")
      --tlskey string      Path to TLS key file (default "/Users/fabioros/.docker/key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit

Management Commands:
  builder     Manage builds
  checkpoint  Manage checkpoints
  config      Manage Docker configs
  container   Manage containers
  context     Manage contexts
  image       Manage images
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  secret      Manage Docker secrets
  service     Manage services
  stack       Manage Docker stacks
  swarm       Manage Swarm
  system      Manage Docker
  trust       Manage trust on Docker images
  volume      Manage volumes

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  build       Build an image from a Dockerfile
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  deploy      Deploy a new stack or update an existing stack
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  images      List images
  import      Import the contents from a tarball to create a filesystem image
  info        Display system-wide information
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  login       Log in to a Docker registry
  logout      Log out from a Docker registry
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  ps          List containers
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  run         Run a command in a new container
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  search      Search the Docker Hub for images
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  version     Show the Docker version information
  wait        Block until one or more containers stop, then print their exit codes

Run 'docker COMMAND --help' for more information on a command.

Quello che ci verrà restituito è un semplice cheatsheet. Non è completo, per quello è sempre possibile utilizzare l’help come indicato nell’ultima riga (Run ‘docker COMMAND –help’ for more information on a command.).
Tuttavia, questo comando ci fornisce tutto ciò di cui abbiamo bisogno in questo momento.

Tra i comandi (Commands) è possibile osservare la voce ‘inspect’.

  inspect     Return low-level information on Docker objects

La descrizione di questo comando fa riferimento ad oggetti Docker generici e non alle immagini. Probabilmente è sovraccaricato. Sappiamo già che è presente all’interno del sotto-comando image, verifichiamo se è definito anche all’interno del sotto-comando container.
Eseguiamo quindi:

docker container

È possibile notare che il comando inspect è definito anche qui e si riferisce ai container.

Utilizzare i sotto-comandi aiuta molto a mettere ordine sia agli script, sia alle idee.


Prosegui su: Nomi delle immagini

Immagine: Barca rossa nel lago vicino alla montagna – it.freepik.com

 

Dockertutorial.it ha bisogno di te!

Il progetto è completamente autofinanziato.

Gratis, per tutti.

 

Vuoi dare una mano a questo progetto?