kodlan
kodlan

Reputation: 631

Running docker commands on remote machine through ssh

I have two machines:

I want to be able to run docker commands from MacOS through ssh on my Ubuntu workstation. Docker works fine when running commands on Ubuntu. SSH works fine (key based with entity saved).

I've tried creating a context:

docker context create ubuntu --docker "host=ssh://[email protected]"
docker context use ubuntu
docker run -it alpine sh

and I get:

docker: Cannot connect to the Docker daemon at http://docker. Is the docker daemon running?.

the same error I get when trying to:

docker -H ssh://[email protected] run -it alpine sh

Nothing from the solutions I've found seems to be helping.

PS: 192.168.1.100 is only for the question. When running commands I use real IP, which is correct and not colliding with anything. Dirrect SSH is working perfectly.

Upvotes: 1

Views: 1166

Answers (2)

user216
user216

Reputation: 156

For your case you can use docker-machine:

Install:

base=https://github.com/docker/machine/releases/download/v0.16.0 &&
curl -L $base/docker-machine-$(uname -s)-$(uname -m) >/tmp/docker-machine &&
sudo mv /tmp/docker-machine /usr/local/bin/docker-machine &&
chmod +x /usr/local/bin/docker-machine

Run/create:

docker-machine create \
  --driver generic \
  --generic-ip-address=put_here_ip_of_remote_docker \
  --generic-ssh-key ~/.ssh/id_rsa \
  vm_123

Check:

docker-machine ls
docker-machine ip vm_123
docker-machine inspect vm_123

Use:

docker-machine ssh vm_123
docker run -it alpine sh
exit
exit
eval $(docker-machine env -u)

Extra tips:

Also you can make vm_123 as the active docker machine via this command:

eval $(docker-machine env vm_123)
docker run -it alpine sh
exit
eval $(docker-machine env -u)

and unset docker machine vm_123 as active via this command:

eval $(docker-machine env -u)

https://docs.docker.com/machine/drivers/generic/

https://docs.docker.com/machine/examples/aws/

https://docs.docker.com/machine/install-machine/

https://docs.docker.com/machine/reference/ssh/

Upvotes: 1

user216
user216

Reputation: 156

Is you sure that ip on your Ubuntu is 192.168.1.1 ?

Because I think that its your router ip :)

Can you post ip a from your Ubuntu, please ?

Upvotes: 0

Related Questions