I am having a hard time on GET request to endpoint of /biz on AWS with Docker file. I made the following project based on this course and would love to hear your insights.
I ran through all the following commands in terminal
docker build -t projectname
docker tag projectname username/projectname
docker push username/projectname
ssh -i ~/.ssh/projectAWS.pem ec2-user@[public-DNS
Inside terminal of AWS EC2
sudo yum update -y
sudo yum install -y dockersudo service docker start
sudo usermod -a -G docker ec2-user
docker run -d -p 80:80 usernam/projectname
When I hit my IPv4 Public IP http://xxx.xxx.xxx/biz, nothing return but "This site can’t be reached"It works on localhost:80/biz when docker run locally. Do you think there's something I am missing? Like the Dockerfile? Missing imports? AWS set-up? Endpoints? or main.go itself? Thanks in advance!
# Dockerfile from Docker
# Start from a Debian image with the latest version of Go installed
# and a workspace (GOPATH) configured at /go.
FROM golang
# Copy the local package files to the container's workspace.
ADD . /go/src/github.com/seintun/dinesty.ninja-backend
WORKDIR /go/src/github.com/seintun/dinesty.ninja-backend
# Build the outyet command inside the container.
RUN go get ./
RUN go build
# Run the outyet command by default when the container starts.
ENTRYPOINT /go/bin/dinesty.ninja-backend
# Document that the service listens on port 8080.
EXPOSE 8080
package main
import (
"log"
"net/http"
"os"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
ctrl "github.com/username/projectname/controllers"
)
func main() {
r := mux.NewRouter()
r.HandleFunc("/biz", ctrl.FetchBiz).Methods("GET")
rLog := handlers.LoggingHandler(os.Stdout, r)
if err := http.ListenAndServe(":8080", rLog); err != nil {
log.Fatal(err)
}
}
// In case you wonder what ctrl.FetchBiz do, it just GET JSON from mongoDB package ctrl
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
. "github.com/username/projectname/models"
"gopkg.in/mgo.v2/bson"
mgo "gopkg.in/mgo.v2"
)
// FetchBiz return list of bizs
func (b *BizDAO) FetchBiz() ([]Biz, error) {
query := bson.M{"active": true}
var bizs []Biz
err := db.C(BCOLLECTION).Find(query).All(&bizs)
return bizs, err
}
</div>