Docker unable to find file in Alpine Linux container - docker

I have an application I'm creating a docker image for, the image is created but when I run it the container errors saying it cannot find the executable file.
Here is my docker file:
FROM alpine:3.14
WORKDIR /
EXPOSE 3000
COPY ./weather-api /weather-api
CMD ["/weather-api"]
I've included a RUN ls -la immediately above the CMD which shows the file is there whilst building the image is being built, and I've included a shell script with la -la as the CMD which has shows that the files is there when the image is being ran.
This is the error I'm getting:
standard_init_linux.go:228: exec user process caused: no such file or directory
When I try to call the weather-api from a shell script I get the standard file not found error.
I've tried using an absolute and relative path for the command, copying the file to /usr/local/bin which I think should put it on the PATH so it would be callable from anywhere, changing COPY to ADD.
I'm still new to docker so any help would be greatly appreciated.

Related

Troubleshoot directory path error in COPY command in docker file

I am using COPY command in my docker file on top of ubuntu 16.04. I am getting error as no such file or directory eventhough the directory is present. In the below docker file I want to copy the directory "auth" present inside workspace directory to the docker image (at path /home/ubuntu) and then build the image.
FROM ubuntu:16.04
RUN apt-get update
COPY /home/ubuntu/authentication/workspace /home/ubuntu
WORKDIR /home/ubuntu/auth
a Dockerfile COPY command can only refer to files under the context - the current location of the Dockerfile, aka .
so you have a few options now:
if it is possible to copy the /home/ubuntu/authentication/workspace/ directory content to somewhere inside your project before the build (so now it will be included in your Dockerfile context and you can access it via COPY ./path/to/content /home/ubuntu) it can be great. but sometimes you dont want it.
instead of copying the directory, bind it to your container via a volume:
when you run the container, add a -v option:
docker run [....] -v /home/ubuntu/authentication/workspace:/home/ubuntu [...]
mind that a volume is designed so any change you made inside the container dir(/home/ubuntu) will affect the bound directory on your host side (/home/ubuntu/authentication/workspace) and vice versa.
i found a something over here: this guy is forcing the Dockerfile to accept his context- he is sitting inside the /home/ubuntu/authentication/workspace/ directory, and running there
docker build . -f /path/to/Dockerfile
so now inside his Dockerfile he can refer to /home/ubuntu/authentication/workspace as his context (.)

Docker starts looking for src folder in wrong directory

So, I am new to Docker but after trying a couple of times I can't get this to work.
Basically I have a simple script like this:
Dockerfile
from centos:7
.....
COPY /C:/Users/Kalin/Drive/web/sites/foo.com/ /var/www
EXPOSE 80
Whenever I run docker build everything works as planned except at the COPY part I get this error:
Step 10/11 : COPY /C:/Users/Kalin/Drive/web/sites/foo.com/ /var/www
COPY failed: stat /var/lib/docker/tmp/docker-builder646917435/C:/Users/Kalin/Drive/web/Kalin/foo.com: no such file or directory
I get the error is about not finding a directory, but instead of looking for it starting from C:/.. foldedr it is looking from /var/...
I don't know what mistake I am doing
I would strongly suggest to make relative path in COPY command so if you have your docker file in /C:/Users/Kalin and you are running docker build from that folder, just place Drive/web/sites/foo.com/ in COPY command

Docker COPY issue while building the docker image

I have a project which is Maven based multi module project
It has various modules with in, like common-utils, web, theme, etc, etc
And also in the root location it has the Dockerfile which is not default one but I have named it Dockerfile.cli due to some requirements
Dockerfile.cli contents here:-
FROM tomcat
ENV NEUW_LOG_HOME /neuw/web/logs
RUN echo "running the image, making it a container :-)"
RUN mkdir -p "/neuw/web/theme-v4"
COPY web/target/web.war /usr/local/tomcat/webapps/ROOT.war
COPY theme-v4 /neuw/web/theme-v4
CMD ["catalina.sh", "jpda", "run"]
Now why I am here -> am getting the below error while building the image:-
COPY failed: stat /var/lib/docker/tmp/docker-builder838877607/web/target/web.war: no such file or directory
The command I use to run the image build is like below and running it on the root of the project which contains both theme and web folder:-
docker build -f Dockerfile.cli -t neuw/web:snapshot-30 .
Any hints and help for the issue?
Which directory are you in when you run this command? Could you do ls /web/target/ from that directory? I ask because I think your Dockerfile is expecting to find a web.war in ./web/target relative to the directory you are running in.
Edit (to save anyone digging through the comments on this): The target directory did contain the file but it was invisible to docker due to a .dockerignore file with **/target.

docker run complains file not found

I am running following command for build docker image from /etc/docker and all files I want to copy inside the container are at this same location
docker build -t user/testapp .
Following is the content of my Dockerfile:-
FROM openjdk:alpine
COPY . /usr/src/testapp/
WORKDIR /usr/src/testapp/
CMD TestAppStart
Image builds fine but when running it uwing following command it says:-
/bin/sh: /usr/src/testmq/TestAppStart
I also tried absolute path in CMD but same error.
I have verified that the files are getting copied by changing CMD to /bin/sh the container starts and I get a shell inside it and I can navigate to that directory and see all the files and can even run the TestAppStart from there manually.
Need help!
The /usr/src/testapp/ directory is not in the PATH environment variable, so /bin/sh complains.
Change the last line to:
CMD ./TestAppStart

Cannot start docker container from scratch

Nowadays I am trying to learn about the Docker but still have some ideas not clear;
I have tried to run an image that I just created, here is the directory;
hello (directory) :
Dockerfile
start.sh
And the Dockerfile :
FROM scratch
ADD start.sh /var/
CMD ["/var/start.sh"]
start.sh :
#!/bin/bash
echo "hello world"
I have tagged as using :
docker build -t mozer/hello .
Once I run the command;
docker run mozer/hello
no such file or directory
Error response from daemon: Cannot start container f22019aabc81f29fe17e849a2c040902ccadefe6cb8a8fe2612c83fe8eda40ea: [8] System error: no such file or directory
and once I run the command:
docker run mozer/hello /bin/sh -c
exec: "/bin/sh": stat /bin/sh: no such file or directory
Error response from daemon: Cannot start container 3b54584092e70b639671aca66122a0b1f6b1e4327cb2471a8792c3b2337b0bcc: [8] System error: exec: "/bin/sh": stat /bin/sh: no such file or directory
Can you please give me some ideas to find the solution ?
P.S. : I am working on a machine which is not connected to internet !
FROM scratch is a completely empty filesystem. You have no installed libraries, and no shell (like /bin/sh) included in there. To use this as your base, you'd need a statically linked binary, or you'll need to install all of the normal tools that are included with a linux distribution.
The latter is what is prepackaged in the various busybox, debian, ubuntu, centos, etc images on the docker hub. The fast way to make your image work with a minimal base image is to change the from to FROM busybox and change your /bin/bash to /bin/sh.
Scratch image is an empty file system, there is not /bin/sh inside it.
Look at Creating a simple base image using scratch
You can use Docker’s reserved, minimal image, scratch, as a starting
point for building containers. Using the scratch “image” signals to
the build process that you want the next command in the Dockerfile to
be the first filesystem layer in your image.
You can add an executable compiled program and run it.

Resources