Maximus S
Maximus S

Reputation: 11095

docker-compose up doesn't build

I am trying to build and run a golang app with docker-compose. Here are my settings:

./docker/Dockerfile
./main.go
Makefile

Makefile

compose:
        env GOOS=linux GOARCH=amd64 GOARM=7 go build
        cd docker && docker-compose up

./docker/Dockerfile

FROM golang:1.11

COPY app .
CMD ["./app"]

./docker/docker-compose.yml

version: '3'
services:
    app:
        build:
            context: ../
            dockerfile: ./docker/Dockerfile
        env_file: ./app.env
        ports:
            - '9292:8000'

I run the following command, expecting to build a new binary and run it inside a Docker container.

$make compose

It runs great, but if I run the same command after updating main.go the new binary isn't copied to docker container. The docker container seems to use the previous binary (i.e. the first binary that was copied when the container was first constructed).

Can someone explain why this is happening and what should I do to fix it?

Upvotes: 1

Views: 3559

Answers (1)

Maximus S
Maximus S

Reputation: 11095

The key was to use --build option in docker-compose up. I expected docker-compose up to rebuild every time, but it just starts the container once it has been built and created from before.

Upvotes: 4

Related Questions