Dockerfile CMD ignored arguments - docker

I'm trying to run an containerized image locally using google cloud shell docker daemon:
> PORT=8080 && docker run -p 9090:${PORT} -e PORT=${PORT} gcr.io/gbl-tpd-endetec-dev1/simplest-helloworld
However i got this error :
> docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"app.py\": executable file not found in $PATH": unknown.
ERRO[0001] error waiting for container: context canceled
When I check container status and in the COMMAND column, i don't have what i expect :
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
977b0ee4b04d gcr.io/gbl-tpd-endetec-dev1/simplest-helloworld "app.py" 11 minutes ago Created 0.0.0.0:9090->8080/tcp youthful_williams
I should have "python ./app.py" since I've written it in my Dockerfile CMD instruction :
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.7-slim
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8080
CMD ["python", "./app.py"]
Can someone help me about what I am missing?

Related

docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process

I am trying to build this dockerfile and then run it but I'm getting this error docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "./deployment-service": permission denied: unknown.
This is my docker file, I've created the volumes and networks
FROM golang:1.19.2-alpine as builder
RUN apk add bash
RUN apk add --no-cache openssh-client ansible git
RUN mkdir /workspace
WORKDIR /workspace
COPY go.mod ./
COPY go.sum ./
RUN go mod download
COPY . ./
RUN go build -o deployment-service cmd/deployment-service/main.go
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /workspace .
ARG DEFAULT_PORT=8080
ENV PORT $DEFAULT_PORT
EXPOSE $PORT
CMD ["./deployment-service"]
this is my run command,
docker run --name=${CONTAINER_NAME} -d --rm -p ${PORT}:80 -e DEPLOYMENT_SERVICE_DATABASE_CONNECTION_URI=mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}#${MONGO_CONTAINER_NAME}:27017/ -e DEPLOYMENT_SERVICE_SERVER_SECRET_KEY=${SECRET_KEY} -e ANSIBLE_CONFIG='./jam-ansible/ansible.cfg' -e DEPLOYMENT_SERVICE_ANSIBLE_SUBMISSION_ROOT=${DEPLOYMENT_ROOT} -v ${DEPLOYMENT_VOLUME}:${DEPLOYMENT_ROOT} --network=${NETWORK_NAME} server:latest
help to get my issue solved.
looks like you need to edit the permissions of the deployment-service file.
try running
chmod a+x ./deployment-service
in the terminal then trying again.
Sometimes you may end up getting this error because you have not specified an entrypoint for your container.
You can do that using ENTRYPOINT inside the Dockerfile
Below is a .NET example:
ENTRYPOINT ["dotnet", "application.dll"]
It seems lack of permission to execute deployment-service. You can add
RUN chmod +x deployment-service
before CMD ["./deployment-service"]
In my case, I got the below error while trying to run the container using the command:
docker container run -p portnumber:portnumber amazoncorretto:17-alpine-jdk
ERROR:
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "bash": executable file not found in $PATH: unknown.
I used amazoncorretto:17-alpine-jdk docker image and in dockerfile instead of bash, I changed it to sh and it worked as bash didn't work with alpine.
Command changed from:
CMD ["bash", "-c", "java -jar test.jar"]
to:
CMD ["sh", "-c", "java -jar test.jar"]

Running a docker Image of Golang failed, with error 'starting container process caused: exec: "/path": permission denied'

I build a Go docker image from docker file successfully, but docker run -p port:port --name imagename imageid gives me permission denied error.
This is my docker file
FROM golang:1.17.2-alpine3.13 as build
WORKDIR /app
COPY . .
RUN go build -o app
FROM alpine:3.7
COPY --from=build /app /usr/local/bin/go_webhooks
RUN chmod +x /usr/local/bin/go_webhooks
ENTRYPOINT ["/usr/local/bin/go_webhooks"]
I tried using chmod but still could not solve it.
The actual error message is:
docker run -p 8000:8000 --name go_webs3 d5f30e8f9703
docker: Error response from daemon: OCI runtime create failed:
container_linux.go:380: starting container process caused: exec:
"/usr/local/bin/go_webhooks": permission denied: unknown.
ERRO[0000] error waiting for container: context canceled
A past similar error message pointed out to a go build issue.
But in your case, copying a folder to /usr/local/bin/go_webhooks would make go_webhooks a folder.
WORKDIR /app
# means /app is a folder
You cannot directly execute a folder.
Your Entrypoint needs to reference an executable inside that folder.
You might needs to copy the built file inside /app:
COPY --from=build /app/app /usr/local/bin/go_webhooks

Building clean Go application in Docker

I'm trying to create Go web server into small Docker images. Ideally the clean image contains only the Go application itself (and maybe supporting web components, but not the Go-building environment).
Here is my Dockerfile:
# golang:latest as build-env
FROM golang:latest AS build-env
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN cd /app && GO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o myapp .
# go build -o myapp
FROM scratch
COPY --from=build-env /app/myapp /app/images /
EXPOSE 8080
ENTRYPOINT /myapp
It uses the Docker Builder Pattern and scratch image, which is a special docker image that's empty.
It builds OK, but when I run it, I'm getting:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown.
UPDATE:
So the ENTRYPOINT need to be changed to the exec form:
ENTRYPOINT ["/myapp"]
Having done that, I'm getting a new error:
standard_init_linux.go:207: exec user process caused "no such file or directory"
Having use a small footprint Linux image as the base (i.e. Alpine Linux) instead of scratch wouldn't help either:
$ docker run -it -p 8080:8080 go-web-docker-small
standard_init_linux.go:207: exec user process caused "no such file or directory"
$ docker run -it -p 8080:8080 go-web-docker-small /bin/sh -i
standard_init_linux.go:207: exec user process caused "no such file or directory"
How to fix it? Thx!
The last line of your Dockerfile is
ENTRYPOINT /myapp
There are two forms of the ENTRYPOINT (and CMD and RUN) instructions. An "exec form" looks like a JSON list, and provides an uninterpreted list of arguments to run as the main container process. A "shell form" does not look like a JSON list, and is implicitly wrapped in /bin/sh -c '...'.
Your ENTRYPOINT uses the shell form, and a FROM scratch image doesn't have a shell, producing the error you get. You can change this to the exec form
ENTRYPOINT ["/myapp"]
While building Dockerfile provided by you, I am getting following error:
COPY failed: stat /var/lib/docker/overlay2/cc1f8144192760ce7bf9cda7a7dfd0af16065901594c38609c813ea103cfd8d7/merged/app/images: no such file or directory
Fixed copy command and few others and image is building with following in Dockerfile
# golang:latest as build-env
FROM golang:latest AS build-env
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN cd /app && GO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o myapp .
# go build -o myapp
FROM scratch
COPY --from=build-env /app/myapp .
EXPOSE 8080
ENTRYPOINT ["./myapp"]

Docker : OCI runtime create failed: executable file not found in $PATH

The error message I am getting while running the container:
Docker: Error response from daemon: OCI runtime create failed:
container_linux.go:348: starting container process caused "exec:
\"mkdir NNEEWW\": executable file not found in $PATH": unknown
My Dockerfile:
FROM python:3
COPY . /
RUN pip install --no-cache-dir -r /requirements.txt
EXPOSE 5678
CMD ["mkdir NNEEWW", "&", "jupyter", "notebook", "--ip=0.0.0.0",
"--port=5678", "--allow-root"]
You need to extract "mkdir NNEEWW", "&"* outside the CMD as in docker CMD is used to run the executable, you can anyway create a new folder before the CMD command if you need by using the command RUN mkdir NNEEWW.

How do I run a Bash script in an Alpine Docker container?

I have a directory containing only two files, Dockerfile and sayhello.sh:
.
├── Dockerfile
└── sayhello.sh
The Dockerfile reads
FROM alpine
COPY sayhello.sh sayhello.sh
CMD ["sayhello.sh"]
and sayhello.sh contains simply
echo hello
The Dockerfile builds successfully:
kurtpeek#Sophiemaries-MacBook-Pro ~/d/s/trybash> docker build --tag trybash .
Sending build context to Docker daemon 3.072 kB
Step 1/3 : FROM alpine
---> 665ffb03bfae
Step 2/3 : COPY sayhello.sh sayhello.sh
---> Using cache
---> fe41f2497715
Step 3/3 : CMD sayhello.sh
---> Using cache
---> dfcc26c78541
Successfully built dfcc26c78541
However, if I try to run it I get an executable file not found in $PATH error:
kurtpeek#Sophiemaries-MacBook-Pro ~/d/s/trybash> docker run trybash
container_linux.go:247: starting container process caused "exec: \"sayhello.sh\": executable file not found in $PATH"
docker: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"sayhello.sh\": executable file not found in $PATH".
ERRO[0001] error getting events from daemon: net/http: request canceled
What is causing this? I recall running scripts in debian:jessie-based images in a similar manner. So perhaps it is Alpine-specific?
Alpine comes with ash as the default shell instead of bash.
So you can
Have a shebang defining /bin/bash as the first line of your sayhello.sh, so your file sayhello.sh will begin with bin/sh
#!/bin/sh
Install Bash in your Alpine image, as you seem to expect Bash is present, with such a line in your Dockerfile:
RUN apk add --no-cache --upgrade bash
This answer is completely right and works fine.
There is another way. You can run a Bash script in an Alpine-based Docker container.
You need to change CMD like below:
CMD ["sh", "sayhello.sh"]
And this works too.
Remember to grant execution permission for all scripts.
FROM alpine
COPY sayhello.sh /sayhello.sh
RUN chmod +x /sayhello.sh
CMD ["/sayhello.sh"]
By using the CMD, Docker is searching the sayhello.sh file in the PATH, BUT you copied it in / which is not in the PATH.
So use an absolute path to the script you want to execute:
CMD ["/sayhello.sh"]
BTW, as #user2915097 said, be careful that Alpine doesn't have Bash by default in case of your script using it in the shebang.

Resources