Question description
When I run fiber with prefork: false inside docker, all works fine. prefork: true causes the container to panic out.
Code snippet _Optional_
package main
import "github.com/gofiber/fiber/v2"
func main() {
app := fiber.New(fiber.Config{
Prefork: true,
})
go func() {
if err := app.Listen(fmt.Sprintf(":%d", viper.GetInt("server.port"))); err != nil {
log.Panic(err)
}
}()
c := make(chan os.Signal, 1) // Create channel to signify a signal being sent
signal.Notify(c, os.Interrupt) // When an interrupt is sent, notify the channel
_ = <-c // This blocks the main thread until an interrupt is received
fmt.Println("Gracefully shutting down...")
_ = app.Shutdown()
}
**Output
```
$ docker run test
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Fiber v2.2.0 โ โ Child PIDs ... 16, 17, 21, 28 โ
โ http://127.0.0.1:3000 โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โ Handlers ............. 7 Threads ............. 4 โ
โ Prefork ........ Enabled PID ................. 1 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
2020/11/14 21:17:53 exit status 1
panic: exit status 1
goroutine 19 [running]:
log.Panic(0xc00009dfb8, 0x1, 0x1)
/usr/local/go/src/log/log.go:351 +0xae
main.main.func2(0xc0000cb320)
/build/cmd/ad-delivery/main.go:55 +0x110
created by main.main
/build/cmd/ad-delivery/main.go:53 +0x507
````
Thanks for opening your first issue here! ๐ Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord
We just did a little investigation in the Discord. Prefork uses environment variables so it will need to be executed within a shell. Docker docs:
Unlike the shell form, the exec form (
CMD [...]) does not invoke a command shell. This means that normal shell processing does not happen. For example, CMD [ "echo", "$HOME" ] will not do variable substitution on $HOME. If you want shell processing then either use the shell form (CMD ./app) or execute a shell directly, for example: CMD [ "sh", "-c", "echo $HOME" ]. When using the exec form and executing a shell directly, as in the case for the shell form, it is the shell that is doing the environment variable expansion, not docker.
So execute your app with either CMD ./app or CMD ["sh", "-c", "/app"]. Let me know if this works.
We've also mentioned this case in the docs, gofiber/docs#144
Sorry I have missed the discussion in the Discord chat :(
Thanks a lot for looking into this one. I confirm it runs perfectly now!
Most helpful comment
Sorry I have missed the discussion in the Discord chat :(
Thanks a lot for looking into this one. I confirm it runs perfectly now!