I'm trying to deploy a simple example webserver on a Droplet instance from Digital Ocean. This example works on my development machine (Windows) but not on my server (Ubuntu).
Tried from inside the Droplet:
curl localhost:8080
Obtained:
curl: (52) Empty reply from server
docker ps
shows:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9325cfbc60d5 myapp.com "/bin/sh -c ./app" 36 minutes ago Up 36 minutes 80/tcp, 0.0.0.0:8080->8080/tcp myappcom_website_1
Application:
package main
import (
"net/http"
"strings"
)
func sayHello(w http.ResponseWriter, r *http.Request) {
message := r.URL.Path
message = strings.TrimPrefix(message, "/")
message = "Hello " + message
w.Write([]byte(message))
}
func main() {
http.HandleFunc("/", sayHello)
if err := http.ListenAndServe(":8080", nil); err != nil {
panic(err)
}
}
Dockerfile:
# Build stage
FROM golang:alpine AS builder
WORKDIR /go/src/app
COPY . .
RUN apk add --no-cache curl
RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
RUN dep ensure
RUN go install
# Final stage
FROM alpine:latest
COPY --from=builder /go/bin/app /app
ENTRYPOINT ./app
LABEL Name=myapp.com Version=0.0.1
EXPOSE 8080:8080
docker-compose.yml:
version: '3.6'
services:
website:
image: myapp.com
build: .
ports:
- 8080:8080
Why?
EDIT: I noted that if I docker ps
on my dev machine, under "ports" it shows 0.0.0.0:8080->8080/tcp
, without the port 80 like in the droplet. I didn't expose port 80 on my droplet, so I wonder why it is showed there. Maybe digital ocean docker image is messing something up?