Tuesday, August 13, 2019

Docker Desktop for Mac, Docker Toolbox, Docker Machine and Docker Engine

MacOS Mojave  v10.14.6
Docker Engine  v19.03.1
Virtual Box  v6.0.10


Goals:  Understanding the scenario.


Additional Info:
  • Docker Toolbox is for older Mac and Windows systems that do not meet the requirements of Docker Desktop for Mac and Docker Desktop for Windows.
  • The applications dockerdocker-compose and docker-machine will be installed by Docker Toolbox and also by Docker Desktop. Yet, you can always install Docker Machine directly (e.g. when using Linux).
  • Use Docker Desktop for Mac to run Docker natively on your local system without using Docker Machine at all, because Docker Desktop comes with their own native lightweight virtualization solutions (HyperKit) rather than Oracle VirtualBox.
  • But, if you want to create multiple local machines, you still need Docker Machine to create and manage a Docker host inside of a virtual machine, for multi-node experimentation.
  • You can use Docker Desktop for Mac and Docker Toolbox together on the same machine. You can also run both HyperKit and Oracle VirtualBox on the same system.
  • Docker Machine is a tool that lets you provision and manage large numbers of Docker hosts. It automatically creates virtual hosts, installs Docker Engine on them, then configures the docker clients. Each managed host (“machine”) is the combination of a Docker host and a configured client. Look at your machine as a pool of resource to host your containers.
  • Use docker-machine commands to create, use and manage a Docker Host inside of a Virtual Machine (e.g. VirtualBox). Each Docker Host you create will be running inside a VM with the same name of the Docker Host (e.g. default) in the VirtualBox. 
  • Once you create a machine it maintains its configuration between uses, like any VirtualBox VM. However, the default machine is Boot2docker - a lightweight Linux distribution (~45MB) made specifically to run Docker containers - the docker-machine auto-creates a disk that will be automounted and used to persist your docker data in /var/lib/docker and /var/lib/boot2docker. Changes outside of these directories will be lost after powering down or restarting the VM.
  • Docker Desktop ships with hypervisors for the host OS.  The hypervisor is responsible for running a lightweight Linux kernel (LinuxKit), which is included as part of Docker Desktop.  This fast and lightweight container OS comes packaged with the QEMU emulator, and comes pre-configured with binfmt_misc to run binaries of any supported architecture.
  • Under Docker 19.03.0 Beta 3, there is a new experimental CLI plugin called “buildx”. Buildx allows you to build multi-arch images.
Docker Machine

Docker Engine

QEMU emulation for the arm/v6, arm/v7 and arm64 Docker images


Install:
  • Download and Install Docker Desktop for MacOS
  • Download and Install VirtualBox for MacOS:
  • How to run a Docker container in a Docker Host:
    • Start the Docker Machine
    • Create a new (or start an existing) Docker Virtual Machine (VM).
    • Switch your environment to the new Docker VM.
    • Use the docker client to create, load and manage Docker containers.
  • Start the Docker Machine
    • docker-machine start
  • Create a new Docker VM named "default":
    • docker-machine create --driver virtualbox default 
    • For more verbose info you can create with debug (-D) option:
      • sudo docker-machine -D create --virtualbox-no-vtx-check default
  • List available Machines:
    • docker-machine ls
  • In order to run docker commands on this host we need to tell Docker to talk to the new machine. Then, let's switch your Docker environment to your new VM (running on VirtualBox).
    • First, we need to get the environment variables from Docker Machine:
      • docker-machine env
    • And then we can use the output of the command above to set up the environment variables:
      • eval "$(docker-machine env default)"
  • You need to do this setup each time you open a new shell or restart your machine.
Tests:
  • Run containers and experiment with Machine commands:
    • docker run busybox echo hello world
  • SSH into VM:
    • docker-machine ssh default
    • Docker Machine auto logs in using the generated SSH key, but if you want to SSH into the machine manually (or you're not using a Docker Machine managed VM), the credentials are:
      • user: docker
      • pass: tcuser
  • Get the host IP address:
    • docker-machine ip default
      • 192.168.99.100
  • Start, stop and remove Machines:
    • docker-machine start default
    • docker-machine stop default
    • docker-machine kill default
    • docker-machine rm -y default
  • Unset environment variables in the current shell:
    • Check whether DOCKER environment variables are set:
      • env | grep DOCKER 

    • Run a shortcut command to show the command you need to run to unset all DOCKER variables:
      • docker-machine env -u
      • eval $(docker-machine env -u)
  • Virtual Box command line manager
    • vboxmanage list vms | runningvms | natnets | intnets
    • vboxmanage --version
    • vboxmanage dhcpservers
    • vboxmanage dhcpserver modify --netname HostInterfaceNetworking-vboxnet0 --ip 192.168.99.2 --lowerip 192.168.99.100 --upperip 192.168.99.254 --netmask 255.255.255.0
Troubleshooting Links:
References:
If you like this content, feel free to

Tuesday, August 6, 2019

Starting RabbitMQ, Redis and MondoDB Docker Containers

MacOS 10.14.6
Docker Engine 19.03.1


Goals:
  • Install and test these two Broker/Message Systems.

Install:
  • Create the RabbitMQ Container:
    • docker container create --hostname rabbitmq --name rabbitmq-3.6 -p 5672:5672 -p 15672:15672 -p 25672:25672 rabbitmq:3.6-management
  • Start the RabbitMQ Container:
    • docker start rabbitmq-3.6
  • Install MQTT Plugin for RabbitMQ:
    • docker exec -it rabbitmq-3.6 bash
      • rabbitmq-plugins enable rabbitmq_mqtt
  • Create the Redis Container:
    • docker container create --name=redis -p 6379:6379 redis:alpine
  • Start the Redis Container:
    • docker start redis
  • Create the MongoDB Container:
    • docker container create --name=mongodb-3.6 -p 27017:27017 mongo:3.6
    • OR, to start the container automatically when they exit, or when Docker restarts.
      • docker container create --name=mongodb-3.6 -p 27017:27017 --restart always mongo:3.6
  • Start the MongoDB Container:
    • docker start mongodb-3.6


Test:

  • Check if the containers are running:
    • docker ps
  • RabbitMQ:
    • Open the url http://localhost:15672 and enter `guest` as username and also as password.

More Information:
    • db.updateUser("user_to_update", { ...  })
    • use db_to_remove
    • db.dropDatabase()


  • Superuser Roles
      • The following roles provide the ability to assign any user any privilege on any database, which means that users with one of these roles can assign themselves any privilege on any database:
        • dbOwner role - when scoped to the admin database
        • userAdmin role - when scoped to the admin database
        • userAdminAnyDatabase role
      • The following role provides full privileges on all resources:
        • root role - provides access to the operations and all the resources of the readWriteAnyDatabase, dbAdminAnyDatabase, userAdminAnyDatabase, clusterAdmin, restore, and backup combined


  • Rename Database
      • mongo --port 27017 -u "<USER>" -p --authenticationDatabase "admin"
      • db.copyDatabase("old-db-name","new-db-name")
      • use old-db-name
      • db.dropDatabase()


    References:
    If you like this content, feel free to