Q:

Build containers for dev and production environment

How do you build images for development and for production(swarm):
I am trying to have one Dockerfile for both to keep "Dockerfile implementation in one place" like inheritance:
FROM golang AS gobase
ENV APP_ENV "pro"
COPY ./app /go/src/github.com/user/myProject/app
WORKDIR /go/src/github.com/user/myProject/app

RUN go get ./
RUN go build
EXPOSE 8080

FROM gobase AS godev

ENV APP_ENV "dev"

RUN go get github.com/pilu/fresh
RUN go-wrapper download
RUN go-wrapper install

CMD [ "fresh" ]

And then use docker-compose.dev.yml & docker-compose.pro.yml
Like for docker-compose.dev.yml:
version: '2'

services:
  godev:
    environment:
      - APP_ENV="dev"
    image: godev

So first of all, the naming is not working.
Bonus question: how to you build an image for production - do you just compile in one container(docker run) and then copy the binary to a new container?

A:

Don't use dev as a name, but as a tag:
go:dev
go:prod

and your compose.yml:
services:
  go:
    image: go:dev

Bonus: Have a look at this answer under "Edit 29/06/17" and use this build step for both (dev and prod)

