Archive July 2015

migrate local docker images to a remote docker host

A. New remote 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

nginx as reverse proxy

I’m working on dockerizing several projects with docker-compose. And, I automated checkout from git repository and building projects,
One of maven projects inherits from parent pom the url of nexus repository. And unfortunately, nexus server was moved to a new url. This fails maven build, because it can’t download artifacts from old nexus url.

While I have no time to fix nexus url in parent pom and recompile all depending projects. And while I’m rushed to run and validate my docker-compose. I’m looking for rapid solution.

We can simply use hosts to redirect old url to the new one. But in my case, it’s not possible because the old url contains a port number.

old_url: http://oldurl.net:8080
new url: https://newurl.net

So, I use nginx as reverse proxy to solve problem:

Step1: install nginx

$ sudo apt-get install nginx

Step2: nginx configuration
create /etc/nginx/conf.d/witr.conf with following content

server {
listen 8080;
server_name oldurl.net;
location / {
proxy_pass https://newurl.net;
proxy_redirect off;
}
}

Step3: locally redirect server name
edit /etc/hosts and add new entry

127.0.0.1 oldurl.net

Step4: restart nginx

service nginx restart

Finally : run my automated build. On download, maven will ask oldurl:8080. hosts will redirect to nginx. Nginx will redirect to newurl. And maven will be able to download artifacts and build will not fail.