I'm aware of the new multi-stage build feature, which works nicely with Docker Compose. However, let's say I'm stuck with the builder-pattern (don't ask)... is there any way to have docker-compose up use the build script required by the builder pattern?
Consider the same builder-pattern files from the linked article:
Dockerfile.build
FROM golang:1.7.3
WORKDIR /go/src/github.com/alexellis/href-counter/
RUN go get -d -v golang.org/x/net/html
COPY app.go .
RUN go get -d -v golang.org/x/net/html \
&& CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
Dockerfile
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY app .
CMD ["./app"]
build.sh
#!/bin/sh
docker build -t alexellis2/href-counter:build . -f Dockerfile.build
docker create --name extract alexellis2/href-counter:build
docker cp extract:/go/src/github.com/alexellis/href-counter/app ./app
docker rm -f extract
docker build --no-cache -t alexellis2/href-counter:latest .
rm ./app
I could construct a Docker Compose file kinda like this one, but I have no idea how to cp the files from the temporary Docker container.
docker-compose.yml
version: '3'
services:
app:
build: .
depends_on:
- app-build
app-build:
build:
context: .
dockerfile: Dockerfile.build
I could build the temporary Docker image/container and run the cp by using the first part of the build.sh script from above and then using a stripped down compose file, but, then, I might as well just stick with the script.