问题
As I'm working with docker and docker-machine a lot, I have to work with several docker versions at the same time. And we all know how hard this can be:
$ docker ps
Error response from daemon: client is newer than server (client API version: 1.23, server API version: 1.22)
So, my question: (How) is it possible to run multiple versions of docker client on my Ubuntu 16.04? Ideally it would be to automatically select the right version, once I enter a host with docker-machine
.
Side note: I know how to update the client or the server. But I still have to work with different versions.
回答1:
I found a solution for me:
mkdir /opt/docker && cd /opt/docker
wget https://get.docker.com/builds/Linux/i386/docker-1.11.2.tgz
wget https://get.docker.com/builds/Linux/i386/docker-1.11.0.tgz
wget https://get.docker.com/builds/Linux/i386/docker-1.10.0.tgz # versions you want
tar -xzf docker-1.11.2.tgz -C 1.11.2
tar -xzf docker-1.11.0.tgz -C 1.11.0
tar -xzf docker-1.10.0.tgz -C 1.10.0
add something like this to your .bashrc
PATH_DOCKER=$PATH
dmenter() {
case $1 in
swarm)
eval $(dm env --swarm swarm)
VERSION=$(docker-machine version swarm)
export PATH=/opt/docker/$VERSION/usr/local/bin:$PATH_DOCKER
;;
"")
eval $(docker-machine env --unset)
export PATH=$PATH_DOCKER
;;
*)
eval $(docker-machine env $*)
VERSION=$(docker-machine version $*)
export PATH=/opt/docker/$VERSION/usr/local/bin:$PATH_DOCKER
;;
esac
}
Now you can enter your docker with dmenter <host>
and always have the right client version available.
来源:https://stackoverflow.com/questions/37617400/multiple-docker-clients-on-the-same-machine