-1

I have Docker Desktop installed on my Mac (not Docker Toolkit) and I installed docker-machine according to the official documentation

I'm triying to add my localhost Docker engine like a docker node under docker machine with no success.

The steps that I made were:

  1. Enable sshd in localhost (ssh localhost works)

  2. Add localhost Docker to Docker Machine:

docker-machine create --driver generic --generic-ip-address 127.0.0.1 --generic-ssh-user <"ssh_username"> <node_name>
Running pre-create checks...
Creating machine...
(localhost) No SSH key specified. Assuming an existing key at the default location.
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Password:
Detecting the provisioner...
Password:
Error creating machine: Error detecting OS: Error getting SSH command: ssh command error:
command : cat /etc/os-release
err     : exit status 1
output  : cat: /etc/os-release: No such file or directory

Output of docker-machine ls

docker-machine ls
NAME        ACTIVE   DRIVER    STATE     URL                    SWARM   DOCKER    ERRORS
localhost   -        generic   Running   tcp://127.0.0.1:2376           Unknown   Unable to query docker version: Cannot connect to the docker engine endpoint

Sorry for my English, I'm not native.

  • What are you trying to do that you would need this? You can generally use Docker just fine without `docker-machine`. – David Maze Aug 28 '20 at 23:32
  • It's for testing purpose and learn how ````docker-machine```` works. I have some remote Docker engines in production env scattered in different servers, and before make the step of managing them remotely with ````docker-machine```` I want to set up a testing lab on my localhost. And the most important thing... I'm very curious on how to accomplish this task. – Ramiro Dutto Luquez Aug 29 '20 at 00:51
  • It's look like that is not possible [Docker Doc](https://docs.docker.com/docker-for-mac/networking/#i-cannot-ping-my-containers) – Ramiro Dutto Luquez Aug 29 '20 at 01:53

1 Answers1

0

docker-machine is dangerous. I wouldn't recommend it for managing production servers as it requires passwordless sudo and makes it very easy to damage your Docker installation. I managed to completely remove all containers an images from a server, not realizing the command I ran was not merely connecting to the server, but initializing it from scratch.

If you want to control multiple Docker daemons from single CLI try Docker Contexts.

Edit:

docker-machine's purpose is provisioning and managing machines with Docker daemon.

It can be used both with local VM's and with various cloud providers. With a single command it can create and start a VM, then install and configure Docker on that new VM (including generating TLS certificates).

It can create an entire Docker Swarm cluster.

It can also install Docker on a physical machine, given SSH access with passwordless sudo (that is what generic driver you tried to use is for).

Once a machine is fully provisioned with Docker it also can set environment variables that configure Docker CLI to send commands to a remote Docker daemon installed on that machine - see here for details.

Finally, one can also add machines with Docker manually configured by not using any driver - as described here. The only purpose of that is to allow for a unified workflow when switching between various remote machines.

However, as I stated before docker-machine is dangerous - it can also remove existing VMs and in case of physical machines reprovsion them, thereby removing all existing images, containers, etc. A simple mistake can wipe a server clean. Not to mention it requires both key-based SSH and passwordless sudo, so if an unauthorized person gets their hands on an SSH key for a production server, then that's it - they have full root access to everything.

It is possible to use docker-machine with preexisting Docker installations safely - you need to add them without using any driver as described here. In this scenario, however, most docker-machine commands won't work, so the only benefit is easy generation of those environment variables for Docker CLI I mentioned before.

Docker Contexts are a new way of telling Docker CLI which Docker daemon it's supposed to communicate with. They essentially are meant to replace all those environment variables docker-machine generates.

Since Docker CLI only communicates with Docker daemon, there is no risk of accidentally deleting a VM or reprovisioning already configured physical machine. And since they are a part of Docker CLI, there is no need to install additional software.

On the other hand, Docker contexts cannot be used to create or provision new machines - one needs to either do that manually or use some other mechanism or tool (like Vagrant or some kind of template provided by the cloud provider).

So if you really need a tool that'll let you easily create, provision and remove docker-enabled machines then use docker-machine. If, however, all you wan is to have a list of all your Docker-enabled machines in one place and a way to easily set up which one your local Docker CLI is supposed to talk to, Docker Contexts are a much safer alternative.

Konrad Botor
  • 4,765
  • 1
  • 16
  • 26