0

We're currently using Docker for development and are currently looking at how we can use Docker also to run our software in other environments such as staging and production.

What we do now is that we compile our Java software with Jenkins and then - in the very same Jenkins build - also build a Docker image which the Java software will run in using docker-compose.

Now, after the Docker image has been built we need to get that image over to the (remote) Docker host where the software is to run. This remote Docker host is NOT the same host as the one Jenkins runs on. I believe we can do that by following the accepted answer for this question.

However, once the image has been copied to the Docker Host - how do we start that image with docker-compose? The image we've copied is just the image - not the docker-compose.yml files or Dockerfile for that matter.

sbrattla
  • 1,456
  • 3
  • 26
  • 48

3 Answers3

5

You can configure docker daemon on your Docker host to listen on TCP port rather than the /var/run/docker.sock socket. You just need to run dockerd on that host with one extra parameter:

-H tcp://<IP>:<PORT>

See the documentation for details.

Once you have that, you can tell docker-compose on your Jenkins node to connect to remote daemon over TCP rather than using local socket by providing the same -H flag pointing to your Docker host and port.

This way any docker containers will be started on that machine.

Miroslav
  • 1,101
  • 8
  • 6
1

Would personally setup a private Docker registry or use private repos on Dockerhub for example. This can also mean that Dockerhub itself can do image builds (on their servers or your own) and then submit them to he repo with the tag "latest" when it has succeeded - very helpful IMO.

-1

If you're running on Linux, you don't have to directly install Docker in the container at all. You can bind mount the docker binary (usually at /usr/bin/docker) directly. Note that bind mounting the socket does not give you a totally new Docker, but rather access to the existing Docker daemon from inside the container. If you want to bake in the Docker binary to an image you could always make one called laoyumi/docker or something and then to "quickly" get access to it in another image you just start the Dockerfile with from laoyumi/docker.

  • 1
    ...but what I don't understand is how do I start the Docker image on the (remote) Docker Host? The image was built on the Jenkins server, and I'm not copying docker-compose.yml or Dockerfile to the (remote) Docker Host. – sbrattla Oct 17 '16 at 07:28