Basic example of docker build and run works - see build.sh for now

This commit is contained in:
Ben Yanke
2018-04-21 22:33:05 -05:00
parent f076f868dc
commit 68edcdc228
4 changed files with 21 additions and 56 deletions
+19 -19
View File
@@ -3,45 +3,45 @@
#################
FROM golang:latest as build
MAINTAINER Ben Yanke <ben@benyanke.com>
# Setup work env
RUN mkdir /app /tmp/gocode
ADD . /app/
WORKDIR /app
# Required Envs for GO
# Required envs for GO
ENV GOPATH=/tmp/gocode
ENV GOOS=linux
ENV GOARCH=amd64
# Install deps
RUN go get -d ./...
# Build
# RUN rm -f /app/bin/glauth64 && GOOS=linux GOARCH=amd64 go build -o /app/bin/glauth64 glauth.go bindata.go ldapbackend.go webapi.go configbackend.go
RUN GOOS=linux GOARCH=amd64 go build -o /app/bin/glauth64 glauth.go bindata.go ldapbackend.go webapi.go configbackend.go
# RUN for GOOS in darwin linux; do
# for GOARCH in 386 amd64; do
# go build -v -o /app/bin/glauth-$GOOS-$GOARCH
# done
# done
RUN go build -o /app/glauth glauth.go bindata.go ldapbackend.go webapi.go configbackend.go
#################
# Test Step
#################
FROM golang:alpine as run
# TBD
#################
# Run Step
#################
FROM golang:latest as run
MAINTAINER Ben Yanke <ben@benyanke.com>
RUN apk --no-cache add ca-certificates
# Copies a sample config to be used if a volume isn't mounted with user's config
ADD sample-simple.cfg /app/config/config.cfg
ADD sample-simple.cfg /app/sample-simple.cfg
WORKDIR /app
# Copy binary from build container
COPY --from=build /app/glauth /app/glauth
COPY --from=build /app/bin/glauth64 /app/glauth64
# Expose web and LDAP ports
EXPOSE 389 5555
# CMD /app/glauth64 -c /app/sample-simple.cfg
CMD ["/app/glauth64", "-c", "/app/sample-simple.cfg"]
# To use your own config, mount /app/config, and place config.cfg in mounted volume
CMD ["/app/glauth", "-c", "/app/config/config.cfg"]
-20
View File
@@ -1,20 +0,0 @@
FROM frolvlad/alpine-glibc:latest
MAINTAINER Ben Yanke <ben@benyanke.com>
RUN apk add --update git \
&& mkdir /data /app \
&& cd /tmp \
&& git clone https://github.com/nmcclain/glauth /tmp/glauth \
&& cp /tmp/glauth/bin/glauth64 /app/glauth64 \
&& mkdir /app/config \
&& cp /tmp/glauth/sample-simple.cfg /app/config/config.cfg \
&& cp /tmp/glauth/sample-simple.cfg /tmp/config.backup.cfg \
&& rm -Rf /tmp/glauth
COPY start.sh /app/start.sh
RUN chmod +x /app/start.sh
EXPOSE 389 5555
VOLUME [ "/app/config" ]
CMD [ "/bin/sh", "/app/start.sh" ]
-16
View File
@@ -1,16 +0,0 @@
# Example file
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
# docker build -t alexellis2/href-counter:latest .
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 CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=0 /go/src/github.com/alexellis/href-counter/app .
CMD ["./app"]
+2 -1
View File
@@ -1,8 +1,9 @@
#!/bin/bash
img="glauth-dev"
img="localhost/glauth-dev"
sudo docker build -f Dockerfile -t $img .
# sudo docker run $img --publish-all
sudo docker run $img
sudo docker rmi -f $img