Skip to content

Instantly share code, notes, and snippets.

@vinceyoumans
Last active December 10, 2018 18:24
Show Gist options
  • Save vinceyoumans/e36a5acab42063ee2b87437ab2076710 to your computer and use it in GitHub Desktop.
Save vinceyoumans/e36a5acab42063ee2b87437ab2076710 to your computer and use it in GitHub Desktop.
docker run --name vyamex01 c7e6ae8e14bb
So everything is compiling.
BUT... when I do a
docker run --name amex01c 8c0ac9dab807
Can not get a response from a web page.
I changed the go code to just respond to /
Also, the go code runs out side of a container.
go run main.go works fine.
So I suspect I need to open up a port to make this work?
#Dockerfile
############################
# STEP 1 build executable binary
############################
FROM golang:alpine AS builder
# Install git.
# Git is required for fetching the dependencies.
RUN apk update && apk add --no-cache git
COPY . $GOPATH/src/dock/v01
WORKDIR $GOPATH/src/dock/v01
# Fetch dependencies.
# Using go get.
RUN go get -d -v
# Build the binary.
#RUN go build -o /go/bin/v01
RUN CGO_ENABLED=0 go build -installsuffix 'static' -o /app .
############################
# STEP 2 build a small image
############################
FROM scratch
# Copy our static executable.
COPY --from=builder /go/bin/v01 /go/bin/v01
# Run the hello binary.
ENTRYPOINT ["/go/bin/v01"]
package main
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
)
func main() {
r := mux.NewRouter()
// r.HandleFunc("/books/{title}/page/{page}", func(w http.ResponseWriter, r *http.Request) {
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// vars := mux.Vars(r)
// title := vars["title"]
// page := vars["page"]
// fmt.Fprintf(w, "You've requested the book: %s on page %s\n", title, page)
fmt.Fprintf(w, " hi there")
})
http.ListenAndServe(":80", r)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment