我正在尝试在Digital Ocean的Droplet实例上部署一个简单的示例Web服务器。此示例在我的开发计算机(Windows)上有效,但在我的服务器(Ubuntu)上无效。
从Droplet内部尝试
curl localhost:8080
获得:
curl: (52) Empty reply from server
docker ps
显示:
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
应用程序:
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
为什么?
编辑:我注意到,如果我在开发机上docker ps
,在“端口”下显示0.0.0.0:8080->8080/tcp
,而端口80像小滴中一样。我没有在液滴上暴露端口80,所以我想知道为什么在那里显示它。也许数字海洋码头工人的形象搞砸了?