How can I use a single command to send the instructions below into a docker virtualbox vm using ssh?
I would like to run one single command from outside the vm so that the command can be embedded in scripts. But all I seem able to do is to connect with the interactive console instead.
The specifics are as follows:
I start by getting a list of available virtual machines as follows:
[root@localhost ~]# docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
myvm1 - virtualbox Running tcp://192.168.99.102:2376 v18.04.0-ce
myvm2 - virtualbox Running tcp://192.168.99.100:2376 v18.04.0-ce
Next, I try to send a command into one of the listed VMs using a command from this tutorial as follows:
[root@localhost ~]# docker-machine ssh myvm1 “docker swarm init --advertise-addr tcp://192.168.99.102:2377”
sh: “docker: not found
exit status 127
Note that the command throws an error because the
docker
command cannot be found when the command is passed into the VM as an argument.
To isolate the problem, I checked to be sure that the same command works if I log into the interactive console manually as follows:
[root@localhost ~]# docker-machine ssh myvm1
## .
## ## ## ==
## ## ## ## ## ===
/"""""""""""""""""\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\_______/
_ _ ____ _ _
| |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 18.04.0-ce, build HEAD : b8a34c0 - Wed Apr 11 17:00:55 UTC 2018
Docker version 18.04.0-ce, build 3d479c0
docker@myvm1:~$ docker swarm init --advertise-addr 192.168.99.102:2377
Swarm initialized: current node (gnrj1sbx36j8lf82o9bk6yz58) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-57xhc6p7xpmeicznpfc7i6fhz9p9tdt48m5dqhqj3v4u42217g-50vj218ggzvm1shbuj3ei4brb 192.168.99.102:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
docker@myvm1:~$
Given that the command works when called from INSIDE the VM's console, what specific steps are required in order to get the command to work when passed as an argument from outside the VM?
The host is a CentOS 7 server, in case that affects the docker machine CLI commands.
The command not found is “docker
and not docker
Try typing or copying from here:
docker-machine ssh myvm1 "docker swarm init --advertise-addr tcp://192.168.99.102:2377"
I have this problem a lot of times when I copy and paste code from some sites. They normally use “
instead of "
.
In shell (and normally for coding) we just use regular quotes (double quotes "
or single quotes '
).
For writing (in Word, for example), it is common the quotes get substituted to curly quotes. But this type of quote is not interpreted the same way as the regular quotes (they are a different character).
“docker ...“
is not the same as "docker ..."