Skip to content

Commit

Permalink
docker image: multi-stage build
Browse files Browse the repository at this point in the history
build in a golang-based container, then copy
resulting binaries into a minimal alpine-based container
  • Loading branch information
soar authored and ploxiln committed Nov 5, 2017
1 parent c521a35 commit 4480364
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
FROM golang:latest AS build

RUN mkdir -p /go/src/github.com/nsqio/nsq
COPY . /go/src/github.com/nsqio/nsq

WORKDIR /go/src/github.com/nsqio/nsq

RUN wget -O /bin/dep https://github.com/golang/dep/releases/download/v0.3.2/dep-linux-amd64 \
&& chmod +x /bin/dep \
&& /bin/dep ensure \
&& ./test.sh \
&& CGO_ENABLED=0 make DESTDIR=/opt PREFIX=/nsq GOFLAGS='-ldflags="-s -w"' install

FROM alpine:3.6

EXPOSE 4150 4151 4160 4161 4170 4171

VOLUME /data
VOLUME /etc/ssl/certs
# Optional volumes
# /data - used for persistent storage across reboots
# VOLUME /data
# /etc/ssl/certs - directory for SSL certificates
# VOLUME /etc/ssl/certs

COPY dist/docker/bin/ /usr/local/bin/
COPY --from=build /opt/nsq/bin/ /usr/local/bin/
RUN ln -s /usr/local/bin/*nsq* / \
&& ln -s /usr/local/bin/*nsq* /bin/
&& ln -s /usr/local/bin/*nsq* /bin/

0 comments on commit 4480364

Please sign in to comment.