0

I have an application which uses docker to build itself, and I want to build a docker image of it. This requires exposing the docker.sock to the application during the docker build command (similar to adding a -v /var/run/docker.sock:/var/run/docker.sock argument to a docker run command).

It there any way I can do this or should I resort to building in a virtual machine and copying the build artefacts into a container? The Dockerfile look like this:

FROM docker

RUN docker run --rm -v /opt/<myapp>:/opt/<myapp> <myapp> /build_and_install.sh /opt/<myapp>

# etc...
Ron
  • 1,989
  • 2
  • 17
  • 33
  • Why don't you run the `docker run` step as a previous step outside of the dockerfile? When I need to do prior setup for a Dockerfile I use a Makefile – stacksonstacks Dec 06 '17 at 22:36
  • @stacksonstacks this is a Linux web application (surprisingly written in C++) which I want to build on a Mac. I could build on the Mac in a docker and copy the build artifacts to another docker like I said, but I’d like to avoid that. Besides, the build process has many steps (all of which use docker) and I really want an image layer for each step. – Ron Dec 06 '17 at 22:44
  • Treat each step as a seperate image. Then you could use `FROM ` in subsequent images to keep build cache functionality – stacksonstacks Dec 06 '17 at 22:56
  • looks like `multi-stage` build is the way to go – stacksonstacks Dec 06 '17 at 23:00
  • Okay - but why? – TJ Biddle Dec 07 '17 at 00:23

1 Answers1

0

Your usecase is a little unclear. That said, in many cases this can be done with a multi-stage build. Docker has put out a sample Java application with a good example of a multi-stage Dockerfile.

Mano Marks
  • 8,761
  • 3
  • 27
  • 28