ERRO[0001] error waiting for container: context canceled - docker

Getting error while running docker image. It seems to look like the problem is on my pc.
I'm using MacOS 10.13.6.
I have followed steps to create a docker image.
Sanjeet:server-api sanjeet$ docker build -t apicontainer .
Sending build context to Docker daemon 24.01MB
Step 1/2 : FROM alpine:3.6
---> da579b235e92
Step 2/2 : CMD ["/bin/bash"]
---> Running in f43fa95302d4
Removing intermediate container f43fa95302d4
---> 64d0b47af4df
Successfully built 64d0b47af4df
Successfully tagged apicontainer:latest
Sanjeet:server-api sanjeet$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
apicontainer latest 64d0b47af4df 3 minutes ago 4.03MB
alpine 3.6 da579b235e92 2 weeks ago 4.03MB
Sanjeet:server-api sanjeet$ docker run -it apicontainer
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory": unknown.
Sanjeet:server-api sanjeet$ ERRO[0001] error waiting for container: context canceled
Inside Dockerfile
FROM alpine:3.6
CMD ["/bin/bash"]

alpine does not include bash by default.
If you want to include bash, you should add RUN apk add --no-cache bash in your Dockerfile.

Issues while running/re-initialize Docker
ERRO[0000] error waiting for the container: context canceled
Steps to Stop the Running Docker Container Forcefully
docker ps
//copy the CONTAINER ID of the running process, ex: CONTAINER ID: 37146513b713
docker kill 37146513b713
docker rm 37146513b713

alpine does not provide glibc. alpine is that small because it uses a stripped down version of libstdc called musl.libc.org.
So we'll check statically linked dependencies using ldd command.
$ docker run -it <image name> /bin/sh
$ cd /go/bin
$ ldd scratch
Check the linked static files, do they exist on that version of alpine? If the do not from, the binaries perspective, it did not find the file-- and will report File not found.
The following step depends on what binaries were missing, you can look it up on the internet on how to install them.
Add RUN apk add --no-cache libc6-compat to your Dockerfile to add libstdc in some Golang alpine image based Dockerfiles.
In you case the solution is to either
disable CGO : use CGO_ENABLED=0 while building
or add
RUN apk add --no-cache libc6-compat
to your Dockerfile
or do not use golang:alpine

I get this error when the network doesn't exist.
docker: Error response from daemon: network xxx not found.
ERRO[0000] error waiting for container: context canceled
It's quite easy to miss the output line after a long docker command and before the red error message.

Related

tar -xvf failing in dockerfile

I want to create my own Docker image using the following Dockerfile
FROM scratch
COPY apache-cassandra-3.11.6-bin.tar.gz .
RUN tar -xzf apache-cassandra-3.11.6-bin.tar.gz
When I run the command, the tar instruction fails. Why? I am on Windows 10.
C:\Users\manuc\Documents\manu\cassandra_image_test>docker build -f CassandraImageDockerFile.txt -t manucassandra .
Sending build context to Docker daemon 184.8MB
Step 1/3 : FROM scratch
--->
Step 2/3 : COPY apache-cassandra-3.11.6-bin.tar.gz .
---> Using cache
---> deda426d6948
Step 3/3 : RUN tar -xzf apache-cassandra-3.11.6-bin.tar.gz .
---> Running in 3edfb1031c06
OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown
Could it be that because I am not using an existing image, tar is not present in the image and thus tar is failing?
stat /bin/sh: no such file or directory
You started from a scratch image that has nothing. Then you told Docker to RUN a command, but you have no shell.
So you can't run any command, much less tar.
Why not start with alpine?
It looks like, whatever base image "scratch" is, it doesn't have /bin/sh, let alone tar or anything else. I would consider starting from a known OS image, or even the Cassandra official image on DockerHub. https://hub.docker.com/_/cassandra
A Dockerfile that starts FROM scratch starts from a base image that has absolutely nothing at all in it. It is totally empty. There is not a set of base tools or libraries or anything else.

Binary build in OpenShift does not work but locally works

I have the following situation. I created a build in OpenShift:
oc new-build --strategy docker --binary --docker-image centos:centos7 --name myapp
And locally there is nothing fancy. I have a .war file and Dockerfile:
FROM registry.access.redhat.com/jboss-webserver-3/webserver31-tomcat7-openshift
COPY pdf-maker##1.2.war /opt/webserver/webapps/
COPY pdfmaker1.0.properties /opt/webserver/conf/
COPY fop.xconf /opt/webserver/_fop/conf/fop.xconf
COPY logo.gif /opt/webserver/_fop/img/
COPY PDF_Transformation.xslt /opt/webserver/_fop/transformation/
RUN mkdir -p /opt/webserver/fop
WORKDIR /opt/webserver
EXPOSE 8080
CMD ["/opt/webserver/bin/catalina.sh", "run"]
And I run the build like:
oc start-build myapp --from-dir . --follow
So far so good... but the application never starts in OpenShift. It says that: "Error: failed to start container "myapp": Error response from daemon: oci runtime error: container_linux.go:235: starting container process caused "exec: \"/opt/webserver/bin/catalina.sh\": stat /opt/webserver/bin/catalina.sh: no such file or directory" I tried to skip the CMD line but with no success. I am 100% the path is correct.
I have tried to build the Docker image from the Dockerfile locally and start it. Locally works as expected but in OpenShift - does not work. I am doing something wrong but I don't know what.
I would much appreciate if someone points me the problem.
SOLVED
It turned out I was relying on centos which was the culprit. The solution was to to use this:
oc new-build --strategy docker --binary --docker-image registry.access.redhat.com/jboss-webserver-3/webserver31-tomcat7-openshift --name sinergia-pdf-maker

starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory":

I am trying to build an docker image on centos 7 from SCRATCH. I have performed following steps :
FROM scratch
RUN rpm -ivh https://address/app.rpm
RUN YUM install tools
...
...
CMD ["rpm","start"]
After executing this , I tried to build this dockerfile with command
"docker build -t testsid -f ./dockerfile ."
Now I see following error :
Sending build context to Docker daemon 3.072kB
Step 1/16 : FROM scratch
--->
Step 2/16 : RUN rpm -ivh https://address/app.rpm
---> Running in d25a0a879d9e
OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown
Please let me know whether anyone has suggestion regarding this. ?
Any input will be really helpful.
Thank you.
FROM scratch starts from a totally empty image. The only things that will be in the container filesystem at all are files in /dev, /proc, and /etc that Docker automatically provides. When you say rpm, that command doesn't exist. A string-form RUN command gets wrapped in /bin/sh -c ..., but there is no /bin directory.
FROM scratch is a somewhat advanced use of Docker. If you're very comfortable with concepts like statically-linked binaries and the differences between bare-string and JSON-array CMD, you can use it to make an extremely small image. For most typical uses you'll want to at least start from something with some sort of distribution and package manager.
If you need Red Hat's package management tools, the easiest Docker Hub image to start from will be centos:
FROM centos:8 # includes rpm, yum, /bin directory
RUN rpm -ivh https://address/app.rpm
RUN yum install tools
...

OCI runtime create failed: container_linux.go:296 - no such file or directory

End of my Dockerfile:
ENTRYPOINT ["ls /etc"]
Terminal:
...Rest of the building above is fine
Step 8/8 : ENTRYPOINT ["ls /etc"]
---> Using cache
---> ea1f33b8ab22
Successfully built ea1f33b8ab22
Successfully tagged redis:latest
k#Karls ~/dev/docker_redis (master) $ docker run -d -p 6379:6379 --name red redis
71d75058b94f088ef872b08a115bc12cece288b53fe26d67960fe139953ed5c4
docker: Error response from daemon: OCI runtime create failed: container_linux.go:296: starting container process caused "exec: \"ls /etc\": stat ls /etc: no such file or directory": unknown.
For some reason, it won't find the directory /etc. I did a pwd and the current working directory is /. I also did a ls / on the entrypoint and that displayed the /etc directory fine.
OCI runtime create failed: container_linux.go:296
In my experience this is an error with the docker daemon itself, not the container you are trying to run. Try deleting all containers, restarting the daemon. I think we also had to clean up the docker networks.
I appear to be having the same issue. Here is what I am doing.
Dockerfile
FROM gcc:7.2.0
COPY src/ /usr/src/myapp
WORKDIR /usr/src/myapp
RUN set -x gcc -o myapp main.c
CMD ["./myapp"]
Build
$ docker build -t test .
Sending build context to Docker daemon 3.584kB
Step 1/6 : FROM gcc:7.2.0
...
---> 3ec35c7d2396
Successfully built 3ec35c7d2396
Successfully tagged test:latest
SECURITY WARNING: You are building a Docker image from Windows against a
non-Windows Docker host. All files and directories added to build context
will have '-rwxr-xr-x' permissions. It is recommended to double check and
reset permissions for sensitive files and directories.
Run
$ docker run -it test
D:\Docker Toolbox\docker.exe: Error response from daemon: OCI runtime create
failed: container_linux.go:296: starting container process caused "exec:
\"./myapp\": stat ./myapp: no such file or directory": unknown.
Changed CMD to ENTRYPOINT and removed the set -x seemed to resolve the problem. Though we are still unsure what the cause was or if this will also work for you.
Make sure that /etc exists or is created as the main.c wasn't compiling.
Dockerfile
FROM gcc:7.2.0
COPY src/ /usr/src/myapp
WORKDIR /usr/src/myapp
RUN gcc -o myapp main.c
ENTRYPOINT ["./myapp"]
On OSX, I fixed it by clearing the volume data manually. Close docker, and remove everything in ~/Library/Containers/com.docker.docker
I've expirienced the same issue after updating my Windows credentials, try following: Docker settings > Shared Drives > Reset credentials > Select drives again > Apply and re-enter your credentials. This solved the problem for me multiple times
The command you are trying to execute inside the container does not exist. In this case ls /etc does not exist in the image. There's a /bin/ls binary, but not a /bin/"ls /etc" binary, which itself would be invalid since the name of a file on the filesystem cannot include a /, though it can include a space.
Of course what you wanted to run was ls with the argument /etc, and for that, you need to separate each argument if you run with the exec syntax.
ENTRYPOINT ["ls", "/etc"]
Or if you wanted to allow a shell to parse the string, same way as if you were at a bash prompt inside the container running ls /etc on the command line, then switch to the string syntax that runs a shell:
ENTRYPOINT ls /etc

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