Why docker cli gives "No such file or directory" while that file shows up in `ls`

Viewed 323

I'm using bazel to run a go test, and in that docker_test.go file I'm using docker go sdk's ContainerCreate function to mount the local dir to docker. In the BUILD.bazel file, I'm writing

go_test(
    name = "docker_test",
    size = "enormous",
    srcs = ["docker_test.go"],
    embed = [":docker"],
    data = glob([
            "docker-entrypoint-initdb.d/**",
    ]),
    deps = [
        "//pkg/util/contextutil",
        "//pkg/util/log",
        "@com_github_docker_docker//client",
        "@org_golang_x_net//context",
    ],
)

With "docker-entrypoint-initdb.d/**", exactly the folder that I'll mount to my docker container.

And I use bazel to run this go test, and the container is successfully started. I used docker exec -it ... /bin/sh to enter the cli, and in that cli it gave the following confusing results:

sh-4.4# cd docker-entrypoint-initdb.d/
sh-4.4# ls
foo.txt  hello.sql  yes.sql
sh-4.4# cat ./hello.sql
cat: ./hello.sql: No such file or directory

sh-4.4# ls -al
ls: cannot access 'foo.txt': No such file or directory
ls: cannot access 'hello.sql': No such file or directory
ls: cannot access 'yes.sql': No such file or directory
total 4
drwxr-xr-x 5 root root  160 Nov 28 22:57 .
drwxr-xr-x 1 root root 4096 Nov 28 22:57 ..
l????????? ? ?    ?       ?            ? foo.txt
l????????? ? ?    ?       ?            ? hello.sql
l????????? ? ?    ?       ?            ? yes.sql
sh-4.4#

So it turns out that the folder I wanted seems successfully mounted to the docker container, but when I tried to look at the files inside, it somehow gave me "No such file or directory". But these files are actually there in the ls's output! I'm so confused about this.

0 Answers
Related