migrate local docker images to a remote docker host
– install docker
– setup simple configuration to let docker daemon be accessible from other machines:
Edit /etc/default/docker, and add following line
DOCKER_OPTS=”-H tcp://0.0.0.0:2375″
– restart docker daemon
sudo service docker restart
IMPORTANT:
With systemd systems (trusty and vivid), we must add new file :
/etc/systemd/system/docker.service.d/docker.conf
with following content:
[Service]
EnvironmentFile=-/etc/default/docker
ExecStart=
ExecStart=/usr/bin/docker -d $DOCKER_OPTS
And then restart socker.
Now, when trying :
docker ps
we’ll got error:
Get http:///var/run/docker.sock/v1.19/containers/json: dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?
That’s because docker client try to connect to file socket by default. So, from now, we must specify which host to connect to when running docker client. Like so :
docker -H localhost:2375 ps
# or
docker -H 127.0.0.1:2375 ps
# or
simply docker -H :2375 ps
Ok, but it’s annoying to specify the host all the time !
So, the solution is to define an environment variable DOCKER_HOST:
export DOCKER_HOST=0.0.0.0:2375
then we can just run :
docker ps
B. Local host
We must set environment variable DOCKER_HOST like following (assume host machien ip is 192.168.33.10)
export DOCKER_HOST=192.168.33.10:2375
C. transfer images from local docker host to remote docker host
Now, to move all local images to the new docker host, we have to make it in three steps :
1. under local machine: export images as tar files
docker -H “” save -o /tmp/myimage.tar myimage
2. transfer tar files from local machine to the remote one (with scp for example)
scp /tmp/myimage.tar user@192.168.33.10:/tmp/
3. under remote machine: load images
docker load -i /tmp/myimage.tar
Hope this help