Gin: fail to run in alpine docker with error "no such file or directory"

Created on 21 Nov 2017  路  4Comments  路  Source: gin-gonic/gin

use simple demo app, compile to exe file on ubuntu named as demo

package main

import "github.com/gin-gonic/gin"

func main() {
    r := gin.Default()
    r.GET("/ping", func(c *gin.Context) {
        c.JSON(200, gin.H{
            "message": "pong",
        })
    })
    r.Run() // listen and serve on 0.0.0.0:8080
}

```Dockerfile
FROM alpine:latest
RUN apk --no-cache add ca-certificates
ADD demo /bin
CMD [ "demo" ]

build docker image and run
```bash
docker build -t test .
docker run test

result:
standard_init_linux.go:178: exec user process caused "no such file or directory"

if I run the service in ubuntu docker image, there is no such issue.

FROM ubuntu:xenial
ADD demo /bin
CMD [ "demo" ]

Can we make it clear what is missing?

Most helpful comment

Thanks for the explaination. I compile on linux(arm64) acutally.
I can run in alpine container by disable cgo finally. (I can run it in scratch docker :))
CGO_ENABLED=0 go build ...

All 4 comments

have you ever tried static build? GOOS=linux GOARCH=amd64 go build

why should I try that?

because there is no standard libc in alpine. compile it as suggested.

Thanks for the explaination. I compile on linux(arm64) acutally.
I can run in alpine container by disable cgo finally. (I can run it in scratch docker :))
CGO_ENABLED=0 go build ...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lilee picture lilee  路  3Comments

mdnight picture mdnight  路  3Comments

frederikhors picture frederikhors  路  3Comments

CodingPapi picture CodingPapi  路  3Comments

iiinsomnia picture iiinsomnia  路  3Comments