简体   繁体   中英

docker container couldn't locate file but file is present

I am trying to package gotty into a Docker container but found a weird behavior.

$ tree                                                                                                                                                                                                                
.
├── Dockerfile
├── gotty
└── gotty_linux_amd64.tar.gz

Dockerfile:

FROM alpine:3.11.3

RUN mkdir -p /home/gotty
WORKDIR /home/gotty
COPY gotty /home/gotty
RUN chmod +x /home/gotty/gotty
CMD ["/bin/sh"]

The image was built without issue:

[strip...]
Removing intermediate container 0dee1ab645e0
 ---> b5c6957d36e1
Step 7/9 : COPY gotty /home/gotty
 ---> fb1a1adec04a
Step 8/9 : RUN chmod +x /home/gotty/gotty
 ---> Running in 90031140da40
Removing intermediate container 90031140da40
 ---> 609e1a5453f7
Step 9/9 : CMD ["/bin/sh"]
 ---> Running in 30ce65cd4339
Removing intermediate container 30ce65cd4339
 ---> 099bc22ee6c0
Successfully built 099bc22ee6c0

The chmod changed the file mode successfully. So /home/gotty/gotty is present.

$ docker run -itd 099bc22ee6c0
9b219a6ef670b9576274a7b82a1b2cd813303c6ea5280e17a23a917ce809c5fa
$ docker exec -it 9b219a6ef670 /bin/sh
/home/gotty # ls
gotty
/home/gotty # ./gotty
/bin/sh: ./gotty: not found

Go into the container, the gotty command is there. I ran it with relative path. Why the not found ?

You are running into one of the more notorious problems with Alpine: Musl, instead of glibc. Check out the output of ldd gotty . Try adding libc6-compat :

apk add libc6-compat

and see if that fixes it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM