multiple docker clients on the same machine

你离开我真会死。 提交于 2020-12-05 11:36:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!