===== Docker Windows Installation ===== [[https://id.docker.com/login/?next=%2Fid%2Foauth%2Fauthorize%2F%3Fclient_id%3D43f17c5f-9ba4-4f13-853d-9d0074e349a7%26next%3D%252Feditions%252Fcommunity%252Fdocker-ce-desktop-windows%253Fref%253Dlogin%26nonce%3DeyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiI0M2YxN2M1Zi05YmE0LTRmMTMtODUzZC05ZDAwNzRlMzQ5YTciLCJleHAiOjE1NDc0NzA4MTcsImlhdCI6MTU0NzQ3MDUxNywicmZwIjoiMVBtZWkyMGlWWm81YmxyYUQ5dmVsQT09IiwidGFyZ2V0X2xpbmtfdXJpIjoiL2VkaXRpb25zL2NvbW11bml0eS9kb2NrZXItY2UtZGVza3RvcC13aW5kb3dzP3JlZj1sb2dpbiJ9.ODnG79BOgw8a8BXggsfTeIi0DCjBiLp9jNtKUnP-YII%26redirect_uri%3Dhttps%253A%252F%252Fhub.docker.com%252Fsso%252Fcallback%26response_type%3Dcode%26scope%3Dopenid%26state%3DeyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiI0M2YxN2M1Zi05YmE0LTRmMTMtODUzZC05ZDAwNzRlMzQ5YTciLCJleHAiOjE1NDc0NzA4MTcsImlhdCI6MTU0NzQ3MDUxNywicmZwIjoiMVBtZWkyMGlWWm81YmxyYUQ5dmVsQT09IiwidGFyZ2V0X2xpbmtfdXJpIjoiL2VkaXRpb25zL2NvbW11bml0eS9kb2NrZXItY2UtZGVza3RvcC13aW5kb3dzP3JlZj1sb2dpbiJ9.ODnG79BOgw8a8BXggsfTeIi0DCjBiLp9jNtKUnP-YII | Docker Login Page]] Package : {{:cours:iot:docker_for_windows_installer_with_virtual_pc.exe|Docker for Windows}} **Test** : * //docker run hello-world// * //docker run -it ubuntu bash // ** FAQ : ** * ** If you must disable Hyper-V : ** dism.exe /Online /Disable-Feature:Microsoft-Hyper-V * ** If you must enable Hyper-V : ** dism.exe /Online /Enable-Feature:Microsoft-Hyper-V /All ** Docker Commands : ** [[https://docs.docker.com/engine/reference/commandline/docker/|Docker Command Line]] ===== Node-Red Docker Installation in a first Container ===== [[https://nodered.org/docs/platforms/docker|Node-Red on Docker]] //docker run -it -p 1880:1880 --name mynodered nodered/node-red-docker// This command will download the nodered/node-red-docker container from DockerHub and run an instance of it with the name of mynodered and with port 1880 exposed ** Test :** * http://localhost:1880, to access to the web-based editor ** Container Manipulations ** * Hit Ctrl-p Ctrl-q to detach from the container. This leaves it running in the background. * To reattach to the container: docker attach mynodered * To stop the container: docker stop mynodered * To start the container: docker start mynodered * To see the list of running containers : docker container ls ==== Tools to Manage easly Docker Containers : Kinematic ==== * [[https://github.com/docker/kitematic|Kinematic on GitHub for Mac, Windows and Linux]] * [[https://github.com/docker/kitematic/releases|Kinematic Releases on Mac, Windows and Linux]] ==== Mosquitto Installation in a second container ==== Various MQTT Broker are available like Mosquitto, RabbitMQ, EMQ, VerneMQ See : [[https://philhawthorne.com/setting-up-a-local-mosquitto-server-using-docker-for-mqtt-communication/| Setting up a MQTT broker (Eclypse Mosquitto) using Docker]] docker run --name mqtt --restart=always --net=host -tid -v /volume1/docker/mqtt/config:/mqtt/config:ro -v /volume1/docker/mqtt/log:/mqtt/log -v /volume1/docker/mqtt/data/:/mqtt/data/ toke/mosquitto * --name mqtt The name flag will allow us to easily identify which container is running MQTT. This is useful if we need to do some commands against the container (like starting, stopping etc) later. * --restart=always This is a powerful and handy flag to set. This will tell Docker to keep trying to re-start the MQTT Broker if it crashes, or on boot of the system. (This is one of the flags you can’t set when using the Synology Docker DSM Interface). * --net=host Another important and powerful flag. This gives your MQTT Broker full network access. This allows you to use 127.0.0.1 as the IP address of your MQTT Broker in Home Assistant, if you followed my setup guide. (This is one of the flags you can’t set when using the Synology Docker DSM Interface). * --itd This is actually three commands in the one. The important one is d. This tells Docker to run in detached mode. Once Docker runs the container, our SSH session is returned to us. If we don’t specify this, we’ll see the output from the MQTT Broker in our SSH console. Also import is the t, which tells Docker to tag the container for future use. * -v /volume1/docker/mqtt/config:/mqtt/config:ro Here we’re creating some mount volumes with the various -v flags. This will allow configuration to persist across reboots, as well as data. So, if your MQTT Broker goes down, any persistent messages you may have sent over the Broker should come back up. You can place it in any folder you like. Whatever you choose to use, the folder must exist before you will be able to start the MQTT Broker. If you want to use the same folder as I did above, you can create it by running mkdir -p /volume1/docker/mqtt/config * toke/mosquitto Finally this tells Docker which container to lookup on DockerHub. I’ve been using this image from Toke without issue for many months now. == Caveats : Docker Containers Mosquitto Configuration == {{ :cours:iot:hostname-port_configuration.png?500 |}} == Containers Network configuration for docker and its containers == // They in bridge mode and disconnect to host network // in the following steps. The result is described in the figure bellow. ==== Caveats : Docker Containers Network Configuration ==== {{ :cours:iot:docker_containers_network.jpg?700 |}} === Test with a GUI Clients === [[http://mqttfx.org/|JavaFX based MQTT Client]] The GUI client is running on the native computer, so the access to the mosquitto broker is done through // localhost:2500 // in this case (see above). === Test Shell MQTT Clients === docker run -it ubuntu bash If the clients are running on the native computer, the access to the mosquitto broker is done through // localhost:2500 // in this case (see above). === Test with Node-Red in a Docker Container === Because Node-Red is running in a Docker container, the MQTT client nodes can access to the mosquitto broker through //172.17.0.1// (the gateway address) in our case. ===== Appendices ===== ==== Network Management in Docker ==== [[https://blog.docker.com/2016/12/understanding-docker-networking-drivers-use-cases/|understanding docker networking drivers use cases]] [[cours:iot:network_management_in_docker|Network in Docker]] ====== Solutions ====== {{:cours:iot:solution_node_red_and_mosquitto_clients.rtf|}}