2 ms·
The trick around this, without requiring volumes and staging binaries in a host directory between containers is to... Have a builder container that contains yo
by colemickens 10y ago
The trick around this, without requiring volumes and staging binaries in a host directory between containers is to...
Have a builder container that contains your build-deps (compiler, etc). Have it build your code, but have the CMD be a `tar` command that just tars your "output" to standard out, along with your "final container"s Dockerfile. Then, you run the builder container and pipe it's output as a new context to a docker build command.
This gives me minimal "Prod" containers that only include the built binaries. It doesn't include any of the SDK tooling, and it doesn't rely on staging the binary in some location on the host in between running the builder and building the final container.
For example, my frontend "builder" container winds up being hundreds of megabytes (thanks npm/nodejs) but the final product after doing the Angular2 build is a handful of kilobytes. Makes a big difference.
(It was also the only way to achieve this in certain setups before docker-machine and the new Docker for {Mac,Win} became available. I still use it because it feels "cleaner".)
I still think Dockerfile syntax should be extended to support this, but there have been proposals for well over two years now and nothing has happened.