-3

Here's my Dockerfile:

FROM alpine:latest
COPY ./main .
COPY ./configs/. .
EXPOSE 8081
CMD ["/main"]

If I do docker run -it --entrypoint=/bin/sh metadata I can see the /main file is there and is executable

/ # ls -lart /main
-rwxrwxr-x    1 root     root      15352712 May 29 19:16 /main

This is a Go binary so there are no unsatisfied dependencies.

When I try to run it it says that the /main file doesn't exist, even though it is there:

$ docker run -p 8081:8081 -it metadata
exec /main: no such file or directory

Is this a bug in docker?

I'm running docker 20.10.21 on Ubuntu 22.04.

--Edit--

I've tried running the /main binary from within docker and the Alpine distro can't find it to exec it:

$ docker run -it --entrypoint=/bin/sh metadata
/ # ls -l /main
-rwxrwxr-x    1 root     root      15352712 May 29 19:16 /main
/ # /main
/bin/sh: /main: not found
/ # ls
base.yaml  dev        home       main       mnt        proc       run        srv        tmp        var
bin        etc        lib        media      opt        root       sbin       sys        usr
/ # ./main
/bin/sh: ./main: not found
/ # main
/bin/sh: main: not found
Dean Schulze
  • 9,633
  • 24
  • 100
  • 165

1 Answers1

-2

I solved this with

FROM ubuntu:22.04

It looks like alpine is not compatible with my binary.

Zeitounator
  • 38,476
  • 7
  • 53
  • 66
Dean Schulze
  • 9,633
  • 24
  • 100
  • 165
  • It looks like your executable isn't as statically linked as you think it is. Alpine uses musl libc; you can't run things that use glibc there. – Charles Duffy May 29 '23 at 20:24
  • (that's not uncommon: for example, Go uses glibc for DNS resolution when compiled with cgo enabled, as is default, despite its documentation saying at first glance that it does static linking by default). – Charles Duffy May 29 '23 at 20:24
  • (Also see [Why is `CGO_ENABLED=1` default?](https://stackoverflow.com/questions/64531437/why-is-cgo-enabled-1-default), which explicitly discusses how cgo makes Go binaries no longer static). – Charles Duffy May 29 '23 at 23:19
  • Thanks for those insights, Charles. But if glibc is the problem then 1) The error message is ridiculously misleading and 2) There are many apps that won't run on Alpine. I shouldn't have to worry if my statically linked binary is mostly-static-but-not-for-dns or mostly-static-but-not-for-XYZ. I'll use something other than Alpine. – Dean Schulze May 30 '23 at 15:08
  • (1) is true, but that misleading error message is covered in the linked duplicates. (2) is true insofar as you aren't willing to recompile those applications against alpine, and it's not an issue specific to alpine or to musl libc -- you'd have the same problem compiling against glibc 2.1 and running on an OS with glibc 2.2, f/e. (There _are_ also programs that can't be compiled against alpine, mostly because they use GNU extensions, but it's a set that's constantly growing smaller -- particularly with the popularity Alpine has picked up in recent years). – Charles Duffy May 30 '23 at 19:32