Some useful commands using Docker

About docker images

  • List images

    docker images
    

    https://docs.docker.com/reference/cli/docker/image/ls/

    Should display something like:

    REPOSITORY                              TAG                 IMAGE ID       CREATED        SIZE
    alpine                                  edge                7f9cc4fcfea4   2 weeks ago    7.39MB
    linusseelinger/model-exahype-tsunami    latest              14577f3ab1ed   5 weeks ago    1.28GB
    detocs/lagun                            1.1.0-I-b2-alpine   c3f4e2aaccd2   7 weeks ago    2.02GB
    detocs/lagun-simulations-launcher       1.1.0-I-b2-alpine   5c9db87dd87f   7 weeks ago    1.35GB
    

    Useful to see which images are usable, which are their ID, the disk space used by each one.

  • Remove an image

    docker image rm 5c9db87dd87f
    

    https://docs.docker.com/reference/cli/docker/image/rm/

    Should remove the image whose ID is 5c9db87dd87f (see docker images). Useful to free disk space.

  • Save an image to a tar archive

    docker save 5c9db87dd87f > lagun-launcher.tar
    

    https://docs.docker.com/reference/cli/docker/image/save/

    Should create a tar file called lagun-launcher.tar corresponding to the image whose ID is 5c9db87dd87f (see docker images). Useful to copy an image on a machine which doesn’t have access to Docker Hub. See also docker load.

  • Load an image from a tar archive

    docker load < lagun-launcher.tar
    

    https://docs.docker.com/reference/cli/docker/image/load/

    Should create an image from a tar file called lagun-launcher.tar (see also docker save). Useful to retrieve an image on a machine which doesn’t have access to Docker Hub. See also docker save.

About docker containers

  • Show all containers (running and stopped)

    docker ps --all
    

    https://docs.docker.com/reference/cli/docker/container/ls/

    Should display something like:

    CONTAINER ID   IMAGE                                                 COMMAND                   CREATED       STATUS          PORTS                    NAMES
    c49d4120a7a0   detocs/lagun-simulations-launcher:1.1.0-I-b2-alpine   "node main.js"            10 days ago   Up 16 seconds   3000/tcp                 focused_keller
    c18669274607   detocs/lagun:1.1.0-I-b2-alpine                        "/bin/sh -c 'R -e \"r…"   5 weeks ago   Up 5 hours      0.0.0.0:6023->6023/tcp   sweet_blackwell
    

    Useful to see the ID of containers, the name of their parent image and their status (running or stopped).

  • Fetch the logs of a container

    docker logs c18669274607
    

    https://docs.docker.com/reference/cli/docker/container/logs/

    Should display the logs retrieved from the container whose ID is c18669274607 (see docker ps). Useful to debug (why a simulator failed).

  • Open a shell on a container

    docker exec -it c49d4120a7a0 sh
    

    https://docs.docker.com/reference/cli/docker/container/exec/

    Should start a new shell session in the container whose ID is c49d4120a7a0 (see docker ps). Useful to debug (test a simulator outside of Lagun) or (re)compile one of your simulator.

  • Stop a container

    docker stop c49d4120a7a0
    

    https://docs.docker.com/reference/cli/docker/container/stop/

    Should stop the container whose ID is c49d4120a7a0 (see docker ps). Useful to free a port or test another version of an image.

  • Start a stopped container

    docker start c49d4120a7a0
    

    https://docs.docker.com/reference/cli/docker/container/start/

    Should start the container whose ID is c49d4120a7a0 (see docker ps).

  • Create a new image from a container’s changes

    docker commit c49d4120a7a0 my-launcher
    

    https://docs.docker.com/reference/cli/docker/container/commit/

    Should create a new image called my-launcher from the container whose ID is c49d4120a7a0 (see docker ps). Useful if you have setup your own simulator on the simulation launcher container and you want to share it with somebody else. See also docker save and docker load.

1 « J'aime »