Machine: Proposal: Add `docker-machine exec`

Created on 29 Apr 2015  路  5Comments  路  Source: docker/machine

These would set the environment variables and then execute the command. E.g.

docker-machine exec mymachine docker images
docker-machine exec mymachine ./my-docker-wrapper.sh

Most helpful comment

Sounds like this is already what ssh does?

docker-machine ssh mymachine -- ifconfig -a
docker-machine ssh mymachine -- docker info
docker-machine ssh mymachine -- "echo uname -a > test && chmod +x test && ./test"

Can you elaborate on how that would be different?

All 5 comments

Sounds like this is already what ssh does?

docker-machine ssh mymachine -- ifconfig -a
docker-machine ssh mymachine -- docker info
docker-machine ssh mymachine -- "echo uname -a > test && chmod +x test && ./test"

Can you elaborate on how that would be different?

I don't want it to run on the docker host, I want it to run locally, but with docker setup to talk to the remote one. Basically a simpler version of

bash -c "eval $(docker-machine env mymachine);
docker images
"

I'm not so fond of changing my environment in my outermost shell, I keep forgetting I've done it, and then suddenly docker behaves differently and I'm confused.

It's a little verbose, but if I want to run one-off docker commands on machines I usually use docker-machine config, which will spit out the correct docker flags for connection to a given machine:

$ docker $(docker-machine config name) info

You could also write a little shell alias like so if it's too much to type:

dkrm () {
    docker $(docker-machine config $1) "${@:2}"
}

It will point the Docker client at the machine specified by first argument, and pass through the rest to the Docker client.

Usage like:

$ dkrm devbox ps
... some containers on the machine "devbox"
$ dkrm staging ps
...some containers on the machine "staging"

Does that help?

I wasn't aware of that command, so thanks for that. It does help, but it's not as transparent as an exec command. E.g. difficult to use with docker-compose, fig, or any kind of wrapper script. I have one that builds the Dockerfile out of several files in the current dir and feeds it via docker build -.

I could do something like DOCKER="docker $(docker-machine config mymachine)" ./build.sh and then have : ${DOCKER:=docker} in the script. So it's workable. Not sure about docker-compose though.

Heh, yeah, if you want to use docker-compose you're best off setting the proper environment variables.

Was this page helpful?
0 / 5 - 0 ratings