Почему этот Tiny Go+Docker Server Crash SSH -соединение?Linux

Ответить
Anonymous
 Почему этот Tiny Go+Docker Server Crash SSH -соединение?

Сообщение Anonymous »

Следуя этому учебному пособию о том, как упаковать бинарную бинар в докер, при запуске Docker подключение SSH падает. Почему? package main

import (
"fmt"
"log"
"net/http"
)

func main() {
http.HandleFunc("/hello", HelloHandler)
fmt.Printf("Server running (port=8080), route: http://localhost:8080/hello\n")
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatal(err)
}
}

func HelloHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, World!")
}


dockerfile:
# ---- Build stage ----
FROM golang:1.23-alpine AS builder
RUN apk add --no-cache build-base
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o hello_go_http

# ---- Runtime stage ----
FROM alpine:3.20
# Install shell and any useful tools for debugging
RUN apk add --no-cache bash curl
WORKDIR /
# Copy binary from builder
COPY --from=builder /app/hello_go_http .
EXPOSE 8080
ENTRYPOINT ["/hello_go_http"]

< /code>
$ docker build -t hello_go_http .
$ docker run -p 8080:8080 --memory=256m --cpus=1 -t hello_go_http
Server running (port=8080), route: http://localhost:8080/hello
Connection reset by 10.3.1.2 #
(Hang occured after a few seconds. And the HTTP server works well in those few seconds, or after and from local console instead of SSH.)
As expected, the docker stats doesn't show particular RAM consumption:
$ docker stats 06e2
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
06e2f43ecd2b magical_sutherland 0.04% 6.863MiB / 256MiB 2.68% 10.3kB / 790B 4.41MB / 0B 5


Подробнее здесь: https://stackoverflow.com/questions/797 ... connection
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Linux»