Docker: Difference between revisions
Line 185: | Line 185: | ||
</pre> |
</pre> |
||
=Définition |
=Définition d'un Dockerfile= |
||
* Dockerfile Reference https://docs.docker.com/engine/reference/builder/ |
* Dockerfile Reference https://docs.docker.com/engine/reference/builder/ |
||
* Best Practices https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/ |
* Best Practices https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/ |
||
<pre> |
<pre> |
||
TODO bridge Node.js MQTT --> InfluxDB |
TODO bridge Node.js MQTT --> InfluxDB |
||
</pre> |
</pre> |
||
<pre> |
<pre> |
Revision as of 15:37, 16 March 2016
Voir
Installation de Docker et Docker Compose
Sur MacOS
TODO
Sur Debian/Ubuntu
sudo apt-get update sudo apt-get install docker.io docker --help sudo apt-get install docker-compose sudo usermod -aG docker ${USER} sudo service docker status sudo service docker stop sudo service docker status sudo service docker start docker run hello-world
Getting started
## . ## ## ## == ## ## ## ## ## === /"""""""""""""""""\___/ === ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~ \______ o __/ \ \ __/ \____\_______/ > docker Usage: docker [OPTIONS] COMMAND [arg...] docker [ --help | -v | --version ] A self-sufficient runtime for containers. Options: --config=~/.docker Location of client config files -D, --debug Enable debug mode -H, --host=[] Daemon socket(s) to connect to -h, --help Print usage -l, --log-level=info Set the logging level --tls Use TLS; implied by --tlsverify --tlscacert=~/.docker/ca.pem Trust certs signed only by this CA --tlscert=~/.docker/cert.pem Path to TLS certificate file --tlskey=~/.docker/key.pem Path to TLS key file --tlsverify Use TLS and verify the remote -v, --version Print version information and quit Commands: attach Attach 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 diff Inspect changes 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 a container or image kill Kill a running container load Load an image from a tar archive or STDIN login Register or log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container network Manage Docker networks pause Pause all processes within a container 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 a container rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save an image(s) to a tar archive 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 a running container tag Tag an image into a repository top Display the running processes of a container unpause Unpause all processes within a container update Update resources of one or more containers version Show the Docker version information volume Manage Docker volumes wait Block until a container stops, then print its exit code Run 'docker COMMAND --help' for more information on a command.
docker-compose --help Define and run multi-container applications with Docker. Usage: docker-compose [options] [COMMAND] [ARGS...] docker-compose -h|--help Options: -f, --file FILE Specify an alternate compose file (default: docker-compose.yml) -p, --project-name NAME Specify an alternate project name (default: directory name) --verbose Show more output -v, --version Print version and exit Commands: build Build or rebuild services help Get help on a command kill Kill containers logs View output from containers port Print the public port for a port binding ps List containers pull Pulls service images restart Restart services rm Remove stopped containers run Run a one-off command scale Set number of containers for a service start Start services stop Stop services up Create and start containers migrate-to-labels Recreate containers to add labels
Déploiement d'un conteneur
docker pull mesoscloud/zookeeper
docker pull ansi/mosquitto
List containers
docker ps -a
List images
docker images
Exec commands
docker exec dockertp_nodered_1 ps docker exec dockertp_nodered_1 ls /
List ports
docker port <id>
Stop container
docker stop <id>
Remove container
docker rm <id>
Remove image
docker rmi hello-world
Définition d'un Dockerfile
- Dockerfile Reference https://docs.docker.com/engine/reference/builder/
- Best Practices https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/
TODO bridge Node.js MQTT --> InfluxDB
docker login docker push donsez/mqtt2influxdb:0.1
Docker Compose
Déploiement d'une composition
Créer le descripteur suivant pour cet stack IoT : docker-compose.yml
mongodb: build: ./build/mongodb volumes: - /var/lib/docker/mongo/mongodb:/data/db command: mongod --smallfiles ports: - "27017:27017" mosquitto: image: ansi/mosquitto ports: - "1883:1883" nodered: image: cpswan/node-red volumes: - /var/lib/docker/node-red/:/root/.node-red/ ports: - "1880:1880" links: - mongodb - mosquitto
Exécuter
docker-compose build docker-compose up
Test de la composition
Depuis un autre terminal de la machine qui exécute le conteneur Docker (ou depuis une autre machine)
docker ps -a docker images python -m webbrowser -t "http://localhost:1880"
Ajouter le flow suivant via Menu > Import > Clipboard
[{"id":"6f440ee6.a1716","type":"mqtt-broker","z":"8072fbb2.b48e6","broker":"test.mosquitto.org","port":"1883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willRetain":null,"willPayload":"","birthTopic":"","birthQos":"0","birthRetain":null,"birthPayload":""},{"id":"96a17df1.8ff65","type":"mqtt in","z":"8072fbb2.b48e6","name":"IoT","topic":"fr/imag/air/iot","broker":"6f440ee6.a1716","x":450,"y":240,"wires":[["7947a469.896f8c","f8335f1d.a01108"]]},{"id":"7947a469.896f8c","type":"file","z":"8072fbb2.b48e6","name":"","filename":"sensor.txt","appendNewline":true,"createDir":false,"overwriteFile":"false","x":850,"y":240,"wires":[]},{"id":"f8335f1d.a01108","type":"debug","z":"8072fbb2.b48e6","name":"","active":true,"console":"false","complete":"false","x":850,"y":320,"wires":[]}]
Depuis une autre machine:
mosquitto_pub -h test.mosquitto.org -t fr/imag/air/iot -m "sensor deveui=1234567 temp=20.10;hum=56.0;pres=1013.25;wind=5.0;rainlast10min=5;rainlasthour=10"
Vérifier la récupération du message dans l'onglet Debug de Node-RED.
Affichage des logs des containers
docker-compose logs
Arrêt d'une composition
docker-compose stop
Docker Swarm
https://docs.docker.com/swarm/overview/ Docker Swarm is native clustering for Docker. It turns a pool of Docker hosts into a single, virtual Docker host.
Krane
https://github.com/krane-io/krane Krane is an open-source platform that enables developers and sysadmins to manage Docker instances across multiple clouds. Krane is built on the Docker code base, so supports the existing Docker command-line in a multi-cloud environment. This allows Docker users to use their existing workflows to launch apps transparently in multiple clouds, saving time and further reducing the friction of moving workloads between development, QA and production.