Luuc
Luuc

Reputation: 79

Use docker image in another docker image

I have two docker images:

  1. CLI tool
  2. Webserver

The CLI tool is a very heavy docker file which takes hours to compile. I am trying to call the CLI tool from the webserver, but not sure how to go from here. Is there a way to make the command created in 1 available in 2?

At this point I tried working with volumes, but no luck. Thanks!

Upvotes: 1

Views: 204

Answers (1)

Thomas
Thomas

Reputation: 182038

The design of Docker sort-of assumes that containers communicate through a network, not through the command line. So the cleanest solution is to create a simple microservice that wraps the CLI tool and can be called through HTTP.

As a quick and dirty hack, you could also use sshd as such a microservice without writing any code.


An alternative that doesn't involve the network is to make the socket of the Docker daemon available in the webserver container using a bind mount:

docker run -v /var/run/docker.sock:/var/run/docker.sock ...

Then you should be able to communicate with the host daemon from within the container, provided that you have installed the docker command line tool in the image. However, note that this makes your application strongly dependent on Docker, which might not be ideal. Also note that it essentially gives the container root access to the host system!

(Note that this is different from Docker-in-Docker, which is running a second Docker daemon inside a container and is generally not recommended except for specialized use cases.)

Upvotes: 1

Related Questions