Ubuntu Docker Build - facing error during run at ENTRYPOINT "No such file or directory" - docker

I have a working build that I am trying to dockerise. This is my dockerfile, I added the "pwd" and "ls -l" to see if the build is copied correctly and it is. However when I try to run "docker run " I get the error "No such file or directory. Please let me know what I might be doing wrong. Appreciate your help.
Dockerfile
FROM <base image>
WORKDIR /app
RUN echo 'List all files'
RUN pwd
RUN ls -l
COPY src/mysolution-linux-amd64 /app/
RUN ls -l
ENTRYPOINT ["/app/mysolution-linux-amd64"]
I have tried ENTRYPOINT with both "./mysolution-linux-amd64" and "/app/mysolution-linux-amd64" but both fail when I run.
Output during Docker build
Sending build context to Docker daemon 1.014GB
Step 1/8 : FROM <base image>
---> 3ed27f7c19ce
Step 2/8 : WORKDIR /app
---> Running in 1b273ccccd22
Removing intermediate container 1b273ccccd22
---> 92560bbb67eb
Step 3/8 : RUN echo 'List all files'
---> Running in faddc1b6adfd
List all files
Removing intermediate container faddc1b6adfd
---> b7b2f657012e
Step 4/8 : RUN pwd
---> Running in 8354a5a476ac
/app
Removing intermediate container 8354a5a476ac
---> 204a625b730b
Step 5/8 : RUN ls -l
---> Running in 0d45cf1339d9
total 0
Removing intermediate container 0d45cf1339d9
---> 6df6451aef44
Step 6/8 : COPY src/mysolution-linux-amd64 /app/
---> 44ac2f066340
Step 7/8 : RUN ls -l
---> Running in d17ec6b0c7af
total 11460
-rwxrwxr-x 1 root root 11734780 Nov 26 04:25 mysolution-linux-amd64
Removing intermediate container d17ec6b0c7af
---> 56a879ef9440
Step 8/8 : ENTRYPOINT ["/app/mysolution-linux-amd64"]
---> Running in 33bea73f14dc
Removing intermediate container 33bea73f14dc
---> ef794fe310bc
Successfully built ef794fe310bc
Successfully tagged newtech/mysolution:latest

Related

Docker Build and Docker run `no such file or directory` when file exists as executable

I have a dockerfile that's copying a binary from a previous step. The entrypoint/command does not work however. I can see the file exists though.
FROM rust as rust-builder
WORKDIR /app
COPY Cargo.lock Cargo.lock
COPY Cargo.toml Cargo.toml
COPY src/ src
RUN cargo build --release
FROM alpine:latest
COPY --from=rust-builder /app/target/release/kube-logs-generator /app/kube-logs-generator
RUN ls -la /app
CMD ["/app/kube-logs-generator"]
This is the output:
Sending build context to Docker daemon 2.159GB
Step 1/10 : FROM rust as rust-builder
---> dd3f19acb681
Step 2/10 : WORKDIR /app
---> Using cache
---> 5e0281f74323
Step 3/10 : COPY Cargo.lock Cargo.lock
---> Using cache
---> 060b7d6f8349
Step 4/10 : COPY Cargo.toml Cargo.toml
---> Using cache
---> 56b90bed67d5
Step 5/10 : COPY src/ src
---> Using cache
---> cdfa52607837
Step 6/10 : RUN cargo build --release
---> Using cache
---> 2f13c20bbebe
Step 7/10 : FROM alpine:latest
---> 9c6f07244728
Step 8/10 : COPY --from=rust-builder /app/target/release/kube-logs-generator /app/kube-logs-generator
---> Using cache
---> b2158ebfac6f
Step 9/10 : RUN ls -la /app
---> Running in cda38e0f4ff0
total 8056
drwxr-xr-x 1 root root 38 Oct 28 14:07 .
drwxr-xr-x 1 root root 140 Oct 28 14:14 ..
-rwxr-xr-x 1 root root 8245984 Oct 28 14:03 kube-logs-generator
Removing intermediate container cda38e0f4ff0
---> 6bf0803d98d6
Step 10/10 : CMD ["/app/kube-logs-generator"]
---> Running in 99ba34dd6afa
Removing intermediate container 99ba34dd6afa
---> c616fa4a1d55
Successfully built c616fa4a1d55
Successfully tagged bkauffman7/kube-logs-generator:latest
Then running
docker run bkauffman7/kube-logs-generator
exec /app/kube-logs-generator: no such file or directory
I'm not sure why it thinks the file isn't there.
Your final application stage is using an Alpine-based image, but your builder isn't using an Alpine base. There are some incompatibilities in the base C library stack that can cause "no such file or directory" errors, even when the file plainly exists.
The easiest way to work around this is to use a Debian- or Ubuntu-based image for the final stage. This is somewhat larger, but it includes the standard GNU libc.
FROM rust:bullseye as rust-builder
...
FROM debian:bullseye
COPY --from=rust-builder /app/target/release/kube-logs-generator /app/kube-logs-generator
The Docker Hub rust image includes an Alpine variant, and it also may work to use an Alpine-based image as the builder
FROM rust:alpine3.16 AS rust-builder
...
FROM alpine:3.16
In both cases, I've made sure that both the Linux distribution and their major versions match between the builder and runtime stages.

Docker - Node js app docker run command error in windows container

I have a NODE.js application which will run only in the Windows environment.
I am running docker desktop on windows 10 Enterprise edition. Docker server version: 20.10.14. So I have switched to the windows container in the docker desktop to create a windows container.
When I am running the container using the docker run command, the container does not start and throws the error.
C:\Users\app>docker run -d helloapp:latest -p 8085:8085
7286c4a0d38c87ec09c009a59cdda527f939f7e7b2814c2324f52cd454744658.
docker: Error response from daemon: container 7286c4a0d38c87ec09c009a59 encountered an error during hcsshim::System::CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2)
[Event Detail: Provider: 00000000-0000-0000-0000-000000000000]
[Event Detail: Provider: 00000000-0000-0000-0000-000000000000]
[Event Detail: onecore\vm\compute\management\orchestration\vmhostedcontainer\processmanagement.cpp(174)\vmcomputeagent.exe!00007FF67F5BC00A: (caller: 00007FF67F58ECEA) Exception(2) tid(36c) 80070002 The system cannot find the file specified.
CallContext:[\Bridge_ProcessMessage\ComputeSystemManager_ExecuteProcess\VmHostedContainer_ExecuteProcess]
Provider: 00000000-0000-0000-0000-000000000000].
Here is my docker file:
FROM customnode/node:12.14.1
RUN mkdir C:\\applications\\docker-firstapp
COPY myfirstapp C:\\applications\\docker-firstapp
WORKDIR C:\\applications\\docker-firstapp
RUN npm install
ENV PORT=8085
ENV SQL_USER=username
ENV SQL_PASSWORD=passwd
ENV SQL_SERVER=serverip
ENV SQL_SERVER_DB=dbname
ENV SQL_SERVER_PORT=1433
RUN npm run build
CMD ["npm", "run prod", "--port 8085"]
My folder structure:
*+--- myfirstapp
--- .dockerignore
--- Dockerfile*
For building the image:
docker build -t helloapp .
For running the container:
docker run -d helloapp:latest -p 8085:8085
Docker build logs:
C:\Users\app>docker build -t helloapp .
Sending build context to Docker daemon 12.85MB
Step 1/12 : FROM customnode/node:12.14.1
12.14.1: Pulling from customnode/node
e46122273a4e: Pull complete
c37a24ce81a9: Pull complete
Digest: sha256:ccd9d53710c8b8f8fd4bb779afe79bhd8d45dugf44c4ddf7b7f655ea5cbfe540550cd892c
Status: Downloaded newer image for customnode/node:12.14.1
---> 2cb9637cf0ec
Step 2/12 : RUN mkdir C:\\applications\\docker-firstapp
---> Running in b5c9bc1fabe0
Removing intermediate container b5c9bc1fabe0
---> bc300a981554
Step 3/12 : COPY myfirstapp C:\\applications\\docker-firstapp
---> b039e12ed5de
Step 4/12 : WORKDIR C:\\applications\\docker-firstapp
---> Running in a522ca627602
Removing intermediate container a522ca627602
---> fe67791910c9
Step 5/12 : RUN npm install
---> Running in 796e435a9ecf
added 628 packages from 996 contributors in 63.929s
Removing intermediate container 796e435a9ecf
---> 2301e525f348
Step 6/12 : ENV PORT=8085
---> Running in 43b2cfe4f50b
Removing intermediate container 43b2cfe4f50b
---> 56babd0dfc87
Step 7/12 : ENV SQL_USER=username
---> Running in 7a7b5c3164c3
Removing intermediate container 7a7b5c3164c3
---> cff0b54056f6
Step 8/12 : SQL_PASSWORD=passwd
---> Running in 162832e5b80d
Removing intermediate container 162832e5b80d
---> c4cc16d73439
Step 9/12 : ENV SQL_SERVER=serverip
---> Running in 22f010aaa9c6
Removing intermediate container 22f010aaa9c6
---> fba9cb278a2a
Step 10/12 : ENV SQL_SERVER_DB=dbname
---> Running in 37f14891e5ed
Removing intermediate container 37f14891e5ed
---> 22477a823bdd
Step 11/12 : ENV SQL_SERVER_PORT=1433
---> Running in a0b9ec381efd
Removing intermediate container a0b9ec381efd
---> 30bc3fb6d543
Step 12/12 : RUN npm run build
---> Running in f6b3b0c7ec9b
> nodewithtypescript#1.0.0 build C:\applications\docker-firstapp
> tsc
Removing intermediate container f6b3b0c7ec9b
---> da1352245135
Step 12/12 : CMD ["npm", "run prod", "--port 8085"]
---> Running in 744719faa7c3
Removing intermediate container 744719faa7c3
---> 1912b73a80d5
Successfully built 1912b73a80d5
Successfully tagged helloapp:latest

Docker not able to find/run binary

I have what I believe is a pretty simple setup.
I build a binary file outside of docker and then try to add it using this Dockerfile
FROM alpine
COPY apps/dist/apps /bin/
RUN chmod +x /bin/apps
RUN ls -al /bin | grep apps
CMD /bin/apps
And I think this should work.
The binary on its own seems to work on my host machine and I don't understand why it wouldn't on the docker image.
Anyways, the output I get is this:
docker build -t apps -f app.Dockerfile . && docker run apps
Sending build context to Docker daemon 287.5MB
Step 1/5 : alpine
---> d05cf6536f67
Step 2/5 : COPY apps/dist/apps /bin/
---> Using cache
---> c54d6d57154e
Step 3/5 : RUN chmod +x /bin/apps
---> Using cache
---> aa7e6adb0981
Step 4/5 : RUN ls -al /bin | grep apps
---> Running in 868c5e235d68
-rwxr-xr-x 1 root root 68395166 Dec 20 13:35 apps
Removing intermediate container 868c5e235d68
---> f052c06269b0
Step 5/5 : CMD /bin/apps
---> Running in 056fd02733e1
Removing intermediate container 056fd02733e1
---> 331600154cbe
Successfully built 331600154cbe
Successfully tagged apps:latest
/bin/sh: /bin/apps: not found
does this make sense, and am I just missing something obvious?
Your binary likely has dynamic links to libraries that don't exist inside the image filesystem. You can check those dynamic links with the ldd apps/dist/apps command.

Docker copy command failed?

I try to add to docker file, i simplified to very short one, that show the issue.
Simple Dockerfile - ddtest
FROM maven AS testdocker
COPY . /server
WORKDIR /server/admin
RUN mkdir target; echo "hello world" > ./target/test.txt
RUN pwd
RUN ls -la ./target/
COPY ./target/test.txt /test.txt
CMD ["/usr/bin/java", "-jar", "/server.jar"]
Building with command docker build . -f ddtest
Execution log:
docker build . -f ddtest
Sending build context to Docker daemon 245.8kB
Step 1/8 : FROM maven AS testdocker
---> e85864b4079a
Step 2/8 : COPY . /server
---> e6c9c6d55be1
Step 3/8 : WORKDIR /server/admin
---> Running in d30bab5d6b6b
Removing intermediate container d30bab5d6b6b
---> 7409cbc70fac
Step 4/8 : RUN mkdir target; echo "hello world" > ./target/test.txt
---> Running in ad507dfc604b
Removing intermediate container ad507dfc604b
---> 0d69df30d041
Step 5/8 : RUN pwd
---> Running in 72becb9ae3ba
/server/admin
Removing intermediate container 72becb9ae3ba
---> 7bde9ccae4c6
Step 6/8 : RUN ls -la ./target/
---> Running in ceb5c222f3c0
total 12
drwxr-xr-x 2 root root 4096 Aug 9 05:50 .
drwxr-xr-x 1 root root 4096 Aug 9 05:50 ..
-rw-r--r-- 1 root root 12 Aug 9 05:50 test.txt
Removing intermediate container ceb5c222f3c0
---> 3b4dbcb794ad
Step 7/8 : COPY ./target/test.txt /test.txt
COPY failed: stat /var/lib/docker/tmp/docker-builder015566471/target/test.txt: no such file or directory
copy to destination docker test.txt failed, why?
That ls command you invoked is running inside an intermediate container, which is not your host. So according to your WORKDIR you're listing files inside /server/admin/target of your container.
As the output of ls shows, this test.txt file is already inside your image
COPY src dst command copies a file/directory from your host to your image, and it seems that you don't have any file named test.txt inside ./target directory of your host.

When build beego docker image with default docker file, show error: `godep: No Godeps found (or in any parent directory)`

I'm new to Go & Beego.
When I build docker image with beego's default docker file, it shows this error :
godep: No Godeps found (or in any parent directory)
The build info is:
Sending build context to Docker daemon 13.6MB
Step 1/9 : FROM library/golang
---> 138bd936fa29
Step 2/9 : RUN go get github.com/tools/godep
---> Running in 9003355d967f
---> bae9e4289f9b
Removing intermediate container 9003355d967f
Step 3/9 : RUN CGO_ENABLED=0 go install -a std
---> Running in 63d367bd487e
---> 3ce0b2d47c0a
Removing intermediate container 63d367bd487e
Step 4/9 : ENV APP_DIR $GOPATH/src/TestProject
---> Running in 53ddc4661a07
---> 528794352eb0
Removing intermediate container 53ddc4661a07
Step 5/9 : RUN mkdir -p $APP_DIR
---> Running in 37718f358f5c
---> ef9332ca086c
Removing intermediate container 37718f358f5c
Step 6/9 : ENTRYPOINT (cd $APP_DIR && ./TestProject)
---> Running in 059c06321914
---> 8538ea070871
Removing intermediate container 059c06321914
Step 7/9 : ADD . $APP_DIR
---> df129482c662
Step 8/9 : RUN cd $APP_DIR && CGO_ENABLED=0 godep go build -ldflags '-d -w -s'
---> Running in 50b29d1307b5
godep: No Godeps found (or in any parent directory)
The command '/bin/sh -c cd $APP_DIR && CGO_ENABLED=0 godep go build -ldflags '-d -w -s'' returned a non-zero code: 1
The solution is very simple: run godep save in your project locally, and you will go a new folder Godeps in your project. it contains file:Godeps.json. After this, run docker build . again, you will got your docker image.

Resources