Cygwin is not working while creating image in docker - image

I am new to docker technology.
We are automating build process using make build.
We are creating a image out of dockerfile which should accept shell script(build.sh) as parameter. but it always says build.sh not found.
I tried with various versions of commands inside docker still no luck.
Here is my code for dockerfile:
# Install node
RUN apk update && apk add
RUN apk add --update nodejs nodejs-npm
RUN apk add --update curl
RUN mkdir /build
COPY ./build.sh /build
RUN chmod +x /build/build.sh
WORKDIR /build
CMD build/build.sh
I am making use of cygwin since I am using windows OS.

Related

failed to compute cache key: failed to create hash for <DIR>: operation not supported

while attempting to build an image in Docker/macOS, I get the following error:
failed to compute cache key: failed to create hash for
/app-temp/client/dist: operation not supported
My Dockerfile looks like this:
FROM node:lts-alpine as ui-build
WORKDIR /app-temp
COPY client/ ./client/
RUN cd client && npm install
RUN cd client && npm run build
FROM node:lts-alpine as api-build
WORKDIR /app
COPY --from=ui-build /app-temp/client/dist ./client/dist
COPY server/ ./server/
RUN cd server && npm install
EXPOSE 3000
CMD ["node", "/app/server/src/index.js"]
And the docker command that I am using is:
docker build -t test-image .
Now, note that the image is successfully built in a Linux machine. However, the above-mentioned error persists in a macOS machine.
I am running macOS Big Sur 11.2.1.
Any ideas as to how solve this problem?
Thanks in advance.
just in case someone else finds himself here
Look in your .dockerignore file if dist is in the list
Also, try building with BUILDKIT disabled
DOCKER_BUILDKIT=0 docker build ....
Im gonna throw my solution out there.
Setup: .net 5 web app with docker enabled, contains a dockerfile that was created by visual studio.
There was a step where the docker file was saying to copy my csproj up to the parent folder. I edited the source directory to from parent/myproject.csproj to myproject.csproj then I ran docker build and it worked.
Im assuming that when I run docker build I was down one level in the child folder where the dockerfile lives, and the paths just werent lining up.

"Exec format error" with docker run command

I have this Golang based Dockerfile:
FROM golang:latest
RUN mkdir -p /app
WORKDIR /app
COPY bin/huru .
CMD ./huru
I checked and the huru binary file is in the working dir. I get this error:
/bin/sh: 1: ./huru: Exec format error
anyone know what that is about? "docker build" succeeds, but "docker run" fails with that error.
The "Exec format error" was simply because I was copying the binary file built on OSX/MacOS into the Docker image and trying to run that binary file in the Linux container. That don't work.
Here is the Dockerfile that worked for me:
FROM golang:latest
RUN mkdir -p /app
WORKDIR /app
COPY . .
ENV GOPATH /app
RUN go install huru
ENTRYPOINT /app/bin/huru
and my project structure like so on my host fs:
$GOPATH/
src/
huru/
.dockerignore
Dockerfile
I run:
docker build -t foo .
docker run foo
my .dockerignore file contains:
.vscode
bin
pkg
If you want to run the docker image on Macos then just specifying the target OS is sufficient:
Assuming there is a src and bin folder, execute in the src folder:
env GOOS=linux go build -o ../bin
(this works with m1, uses the arm64 architecture)
BTW
I would not use latest, I see that there is a docker image based on 1.20 which is not yet officially released at time of writing.
You could build your application (huru) for the target architecture in MacOS and then copy it into the docker image. To build for the target architecture you have to use command in the following format:
env GOOS=linux GOARCH=amd64 go build -o application main.go
This has the added advantage of having a clean dockerfile and smaller image.

docker entrypoint running bash script gets "permission denied"

I'm trying to dockerize my node.js app. When the container is built I want it to run a git clone and then start the node server. Therefore I put these operations in a .sh script. And run the script as a single command in the ENTRYPOINT:
FROM ubuntu:14.04
RUN apt-get update && apt-get install -y build-essential libssl-dev gcc curl npm git
#install gcc 4.9
RUN apt-get install -y software-properties-common python-software-properties
RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test
RUN apt-get update
RUN apt-get install -y libstdc++-4.9-dev
#install newst nodejs
RUN curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
RUN apt-get install -y nodejs
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ADD package.json /usr/src/app/
RUN npm install
ADD docker-entrypoint.sh /usr/src/app/
EXPOSE 8080
ENTRYPOINT ["/usr/src/app/docker-entrypoint.sh"]
My docker-entrypoint.sh looks like this:
git clone git#<repo>.git
git add remote upstream git#<upstream_repo>.git
/usr/bin/node server.js
After building this image and run:
docker run --env NODE_ENV=development -p 8080:8080 -t -i <image>
I'm getting:
docker: Error response from daemon: oci runtime error: exec: "/usr/src/app/docker-entrypoint.sh": permission denied.
I shell into the container and the permission of docker-entrypoint.sh is:
-rw-r--r-- 1 root root 292 Aug 10 18:41 docker-entrypoint.sh
three questions:
Does my bash script have wrong syntax?
How do I change the permission of a bash file before adding it into an image?
What's the best way to run multiple git commands in entrypoint without using a bash script?
Thanks.
"Permission denied" prevents your script from being invoked at all. Thus, the only syntax that could be possibly pertinent is that of the first line (the "shebang"), which should look like #!/usr/bin/env bash, or #!/bin/bash, or similar depending on your target's filesystem layout.
Most likely the filesystem permissions not being set to allow execute. It's also possible that the shebang references something that isn't executable, but this is far less likely.
Mooted by the ease of repairing the prior issues.
The simple reading of
docker: Error response from daemon: oci runtime error: exec: "/usr/src/app/docker-entrypoint.sh": permission denied.
...is that the script isn't marked executable.
RUN ["chmod", "+x", "/usr/src/app/docker-entrypoint.sh"]
will address this within the container. Alternately, you can ensure that the local copy referenced by the Dockerfile is executable, and then use COPY (which is explicitly documented to retain metadata).
An executable file needs to have permissions for execute set before you can execute it.
In your machine where you are building the docker image (not inside the docker image itself) try running:
ls -la path/to/directory
The first column of the output for your executable (in this case docker-entrypoint.sh) should have the executable bits set something like:
-rwxrwxr-x
If not then try:
chmod +x docker-entrypoint.sh
and then build your docker image again.
Docker uses it's own file system but it copies everything over (including permissions bits) from the source directories.
I faced same issue & it resolved by
ENTRYPOINT ["sh", "/docker-entrypoint.sh"]
For the Dockerfile in the original question it should be like:
ENTRYPOINT ["sh", "/usr/src/app/docker-entrypoint.sh"]
The problem is due to original file not having execute permission.
Check original file has permission.
run ls -al
If result get -rw-r--r-- ,
run
chmod +x docker-entrypoint.sh
before docker build!
Remove Dot [.]
This problem take with me more than 3 hours finally, I just tried the problem was in removing dot from the end just.
problem was
docker run -p 3000:80 --rm --name test-con test-app .
/usr/local/bin/docker-entrypoint.sh: 8: exec: .: Permission denied
just remove dot from the end of your command line :
docker run -p 3000:80 --rm --name test-con test-app
Grant execution rights to the file docker-entrypoint.sh
sudo chmod 775 docker-entrypoint.sh
This is a bit stupid maybe but the error message I got was Permission denied and it sent me spiralling down in a very wrong direction to attempt to solve it. (Here for example)
I haven't even added any bash script myself, I think one is added by nodejs image which I use.
FROM node:14.9.0
I was wrongly running to expose/connect the port on my local:
docker run -p 80:80 [name] . # this is wrong!
which gives
/usr/local/bin/docker-entrypoint.sh: 8: exec: .: Permission denied
But you shouldn't even have a dot in the end, it was added to documentation of another projects docker image by misstake. You should simply run:
docker run -p 80:80 [name]
I like Docker a lot but it's sad it has so many gotchas like this and not always very clear error messages...
This is an old question asked two years prior to my answer, I am going to post what worked for me anyways.
In my working directory I have two files: Dockerfile & provision.sh
Dockerfile:
FROM centos:6.8
# put the script in the /root directory of the container
COPY provision.sh /root
# execute the script inside the container
RUN /root/provision.sh
EXPOSE 80
# Default command
CMD ["/bin/bash"]
provision.sh:
#!/usr/bin/env bash
yum upgrade
I was able to make the file in the docker container executable by setting the file outside the container as executable chmod 700 provision.sh then running docker build . .
If you do not use DockerFile, you can simply add permission as command line argument of the bash:
docker run -t <image> /bin/bash -c "chmod +x /usr/src/app/docker-entrypoint.sh; /usr/src/app/docker-entrypoint.sh"
If you still get Permission denied errors when you try to run your script in the docker's entrypoint, just try DO NOT use the shell form of the entrypoint:
Instead of:
ENTRYPOINT ./bin/watcher write ENTRYPOINT ["./bin/watcher"]:
https://docs.docker.com/engine/reference/builder/#entrypoint

How to specify current directory for Docker?

I'm following this part of the Docker tutorial (on a Mac): https://docs.docker.com/mac/step_four/. I'm getting an error when I try to run the docker-whalesay image because it can't find fortunes.
I started off in the Dockerfile using /user/games/fortunes. Then I changed to just fortunes. Neither work.
How do I specify in the Dockerfile to use the current folder (mydockerbuild)?
The Dockerfile in that example does not rely on files that are present on your computer, basically, the only steps needed are;
Create an empty directory (you named it mydockerbuild)
mkdir mydockerbuild
Change to that directory
cd mydockerbuild
Create a Dockerfile
Edit the Dockerfile to look like this;
FROM docker/whalesay:latest
RUN apt-get -y update && apt-get install -y fortunes
CMD /usr/games/fortune -a | cowsay
Build the Dockerfile, and name the built image "docker-whale"
docker build -t docker-whale .
Run the image you just built
docker run --rm docker-whale
The /usr/games/fortunes path in the Dockerfile is referring to a path inside the container. In this case, the /usr/games/fortunes is created by the fortune package that it's installed by apt-get install -y fortunes.

ADD Command for Docker Toolbox on Mac

I have Docker Toolbox installed on my Mac, but I'm having issues adding a file to a container during build. I'm using the ADD command in the Dockerfile. I can't seem to add any local files. I understand that Docker Toolbox uses VirtualBox under the hood, but I am not sure how to get those files into the VM to build the container. Is there a way I can do it that allows me to keep a clean OS-agnostic Dockerfile without any absolute paths?
Here is my Dockerfile. It's built from the Node.js container with some additional dependencies.
FROM node:4.2.2
RUN apt-get update
RUN apt-get install -y libvips-dev libgsf-1-dev libkrb5-dev
RUN apt-get clean
ADD app/ /app
RUN cd /app && npm install --production
RUN npm install forever -g
Turns out this does work, but only for my current directory. My Dockerfile and the files I wanted to add were not in the same directory. Moving the shell to the files I wanted, and then manually specifying the Dockerfile worked.
docker build -f my/other/Dockerfile .
Since docker will use a VirtualBox VM on Mac (with boot2docker or with docker-machine), it will use VirtualBox Guest Additions, which is there for the express purpose of using VirtualBox folder sharing.
Make sure to be in such a shared path, typically in /Users/....
If app/ is in /Users/path/to/app, then ADD should work.
You can mount other paths with boot2docker, but it can be problematic with docker machine (see issue 13).
Of course, for ADD app ... to work, you need to be in the parent folder of app/.
From docker ADD:
The <src> path must be inside the context of the build; you cannot ADD ../something /something

Resources