Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save romancin/00483888ec234a98d1435dcd9e8420c4 to your computer and use it in GitHub Desktop.
Save romancin/00483888ec234a98d1435dcd9e8420c4 to your computer and use it in GitHub Desktop.
docker-machine set up pointing QNAP Container Station
I use the QNAP nas server to host docker containers. We can configure
this mac to run docker-machine and point to the qnap server to deploy or
otherwise mess with docker.
This is how we set that up:
docker-machine create --driver=none --url tcp://<your qnap box>:2376 qnap
Next we need to install the certs. Download them from within the QNAP
Container Station in the preferences section.
cd ~/.docker/machine/machines/qnap (or the directory configured in MACHINE_STORAGE_PATH environment variable)
cp ~/Downloads/cert/*.pem .
Edit the config.json file to be somethng like this (obviously your paths will vary):
"AuthOptions": {
"CertDir": "/Users/rayj/.docker/machine/machines/qnap/",
"CaCertPath": "/Users/rayj/.docker/machine/machines/qnap/ca.pem",
"CaPrivateKeyPath": "/Users/rayj/.docker/machine/machines/qnap/key.pem",
"CaCertRemotePath": "",
"ServerCertPath": "/Users/rayj/.docker/machine/machines/qnap/cert.pem",
"ServerKeyPath": "/Users/rayj/.docker/machine/machines/qnap/key.pem",
"ClientKeyPath": "/Users/rayj/.docker/machine/machines/qnap/key.pem",
"ServerCertRemotePath": "",
"ServerKeyRemotePath": "",
"ClientCertPath": "/Users/rayj/.docker/machine/machines/qnap/cert.pem",
"ServerCertSANs": [],
"StorePath": "/Users/rayj/.docker/machine/machines/qnap"
}
You can test by doing something like this:
$> docker-machine ls --filter name=qnap
Then to use this machine do:
$> eval `docker-machine env qnap`
Then do normal docker commands like:
$> docker ps
You may have a newer version of docker running on your developer machine. If that happens
you will get a message something like this:
Error response from daemon: client is newer than server (client API version: 1.24, server API version: 1.23)
You can set an environment variable to make Docker happy:
export DOCKER_API_VERSION=1.23
(If using docker-compose you may also want to set COMPOSE_API_VERSION)
** rant ** It is really a shame docker-machine can not set the DOCKER_API_VERSION for us!
Unfortunately, it appears that Docker for Mac version 17.09.0-ce has a bug and it does not
honor the DOCKER_API_VERSION environment variable.
I was able to work around this by using docker version manager (dvm):
https://howtowhale.github.io/dvm/
I use version 17.05.0-ce of docker which properly honors DOCKER_API_VERSION
After all that you should be able use your docker client to talk to the engine on your qnap
server just fine!
To make my life a little simpler I added the following to my .bash_profile
function setTerm() { PROFILE=${1}; echo "tell app \"Terminal\" to set current settings of first window to settings set \"${PROFILE}\""|osascript; };
setQnap() {
eval $(docker-machine env qnap)
export DOCKER_API_VERSION=1.23
export COMPOSE_API_VERSION=1.23
dvm use 17.05.0-ce
setTerm homebrew
}
unsetQnap() {
eval $(docker-machine env -u)
unset DOCKER_API_VERSION
unset COMPOSE_API_VERSION
dvm deactivate
setTerm basic
}
Then I just call setQnap or unsetQnap to switch between talking to the qnap docker
engine or the one om my laptop. (The setTerm stuff is specific to Mac terminal.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment