Skip to content

Commit e5c71d2

Browse files
author
Manuel Morejón
authored
Merge pull request #5 from mmorejon/docker-multi-stage
Use docker multi-stage to build docker images.
2 parents af2a853 + 2953111 commit e5c71d2

File tree

4 files changed

+44
-20
lines changed

4 files changed

+44
-20
lines changed

bookings/Dockerfile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# golang image where workspace (GOPATH) configured at /go.
2-
FROM golang:1.11.2
2+
FROM golang:1.11.2 as dev
33

44
# Install dependencies
55
RUN go get gopkg.in/mgo.v2
@@ -11,11 +11,17 @@ ADD . /go/src/github.com/mmorejon/cinema/bookings
1111
# Setting up working directory
1212
WORKDIR /go/src/github.com/mmorejon/cinema/bookings
1313

14-
# Build the bookings command inside the container.
15-
RUN go install github.com/mmorejon/cinema/bookings
14+
# build binary
15+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o bookings .
1616

17-
# Run the bookings microservice when the container starts.
18-
ENTRYPOINT /go/bin/bookings
1917

18+
# alpine image
19+
FROM alpine:3.9.2 as prod
20+
# Setting up working directory
21+
WORKDIR /root/
22+
# copy movies binary
23+
COPY --from=dev /go/src/github.com/mmorejon/cinema/bookings .
2024
# Service listens on port 8080.
2125
EXPOSE 8080
26+
# Run the movies microservice when the container starts.
27+
ENTRYPOINT ["./bookings"]

movies/Dockerfile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# golang image where workspace (GOPATH) configured at /go.
2-
FROM golang:1.11.2
2+
FROM golang:1.11.2 as dev
33

44
# Install dependencies
55
RUN go get gopkg.in/mgo.v2
@@ -11,11 +11,17 @@ ADD . /go/src/github.com/mmorejon/cinema/movies
1111
# Setting up working directory
1212
WORKDIR /go/src/github.com/mmorejon/cinema/movies
1313

14-
# Build the movies command inside the container.
15-
RUN go install github.com/mmorejon/cinema/movies
14+
# build binary
15+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o movies .
1616

17-
# Run the movies microservice when the container starts.
18-
ENTRYPOINT /go/bin/movies
1917

18+
# alpine image
19+
FROM alpine:3.9.2 as prod
20+
# Setting up working directory
21+
WORKDIR /root/
22+
# copy movies binary
23+
COPY --from=dev /go/src/github.com/mmorejon/cinema/movies .
2024
# Service listens on port 8080.
2125
EXPOSE 8080
26+
# Run the movies microservice when the container starts.
27+
ENTRYPOINT ["./movies"]

showtimes/Dockerfile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# golang image where workspace (GOPATH) configured at /go.
2-
FROM golang:1.11.2
2+
FROM golang:1.11.2 as dev
33

44
# Install dependencies
55
RUN go get gopkg.in/mgo.v2
@@ -11,11 +11,17 @@ ADD . /go/src/github.com/mmorejon/cinema/showtimes
1111
# Setting up working directory
1212
WORKDIR /go/src/github.com/mmorejon/cinema/showtimes
1313

14-
# Build the showtimes command inside the container.
15-
RUN go install github.com/mmorejon/cinema/showtimes
14+
# build binary
15+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o showtimes .
1616

17-
# Run the showtimes microservices when the container starts.
18-
ENTRYPOINT /go/bin/showtimes
1917

18+
# alpine image
19+
FROM alpine:3.9.2 as prod
20+
# Setting up working directory
21+
WORKDIR /root/
22+
# copy movies binary
23+
COPY --from=dev /go/src/github.com/mmorejon/cinema/showtimes .
2024
# Service listens on port 8080.
2125
EXPOSE 8080
26+
# Run the movies microservice when the container starts.
27+
ENTRYPOINT ["./showtimes"]

users/Dockerfile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# golang image where workspace (GOPATH) configured at /go.
2-
FROM golang:1.11.2
2+
FROM golang:1.11.2 as dev
33

44
# Install dependencies
55
RUN go get gopkg.in/mgo.v2
@@ -11,11 +11,17 @@ ADD . /go/src/github.com/mmorejon/cinema/users
1111
# Setting up working directory
1212
WORKDIR /go/src/github.com/mmorejon/cinema/users
1313

14-
# Build the users command inside the container.
15-
RUN go install github.com/mmorejon/cinema/users
14+
# build binary
15+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o users .
1616

17-
# Run the users microservice when the container starts.
18-
ENTRYPOINT /go/bin/users
1917

18+
# alpine image
19+
FROM alpine:3.9.2 as prod
20+
# Setting up working directory
21+
WORKDIR /root/
22+
# copy movies binary
23+
COPY --from=dev /go/src/github.com/mmorejon/cinema/users .
2024
# Service listens on port 8080.
2125
EXPOSE 8080
26+
# Run the movies microservice when the container starts.
27+
ENTRYPOINT ["./users"]

0 commit comments

Comments
 (0)