console.error("The {{match}} helper is not available. The Match helper flag must be enabled in labs if you wish to use the {{match}} helper. See https://ghost.org/docs/themes/");> Docker: Commandes utiles ">
">
">

Docker: Commandes utiles

  • Changer le répertoire de stockage de Docker:
    https://forums.docker.com/t/how-do-i-change-the-docker-image-installation-directory/1169

  • Construire une image à partir d'un Dockerfile
    $ docker build -t test/cowsay-dockerfile .

  • Créer une instance de container à partir d'une image:
    $ docker run test/cowsay-dockerfile "Moo"
    $ docker run --name oc -p 80:80 -p 443:443 -d l3iggs/owncloud
    $ docker run -p 27017:27017 -v /opt/mongodb/db:/data/db -d mongo mongod --auth

  • Forcer la suppression d'un pod en status 'ImagePullBackOff":
    $ kubectl delete -f whoami.xml

  • Supprimer les images qui ne sont plus attachées à un conteneur:
    $ docker rm -v $(docker ps -aq -f status=exited)
    "Note that the -v argument will delete any Docker-managed volumes that aren’t referenced by other contain‐ers."

  • suppression des images sans label:
    docker images --filter "dangling=true" -q | xargs docker rmi

  • Transforme un conteneur en une image réutilisable par la suite:
    $ docker commit cowsay test/cowsayimage
    ici le conteneur nommé à son lancement cowsay est sauvegardé dans test/cowsayimage

  • See the full set of layers that make up an image by running the docker history command.
    For example:
    $ docker history mongo:latest

  • Se connecter via terminal sur un container déjà lancé
    docker exec -it docker_owncloud_1 bash

bouger un container d'un host à un autre sans passer par un repository:

  1. Export the container to a tarball
    docker export <CONTAINER ID> > /home/export.tar
  2. Move your tarball to new machine
  3. Import it back

cat /home/export.tar | docker import - some-name:latest

  • Si copie à partir d'une image:
    docker save 'image_name:tag' > ./export.tar

  • stats usage mémoire : dockker stats -a

Liens vers doc sur la manipulation des conteneurs:
Save vs export

Construction d'une image à partir d'un dockerfile:

https://docs.docker.com/engine/reference/builder

$ mkdir cowsay $ cd cowsay $ touch Dockerfile

in dockerfile:

FROM debian:wheezy
RUN apt-get update && apt-get install -y cowsay fortune
COPY entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]
NB: l'entrypoint permet de spécifier quel script docker doit lancer au démarrage du conteneur

commande pour lancer la construction:

$ docker build -t test/cowsay-dockerfile .
...
$ docker run test/cowsay-dockerfile "Moo"

Base Image

Toujours privilégier les images officielle, notamment celles minimalistes à taille réduite, tout en profitant des systèmes de layer (image déjà chargée)
https://hub.docker.com/_/alpine/ système minimal Linux génére une image d'un server de 16Mo, contre >200Mo pour une base Ubuntu.