My Dockerfile looks like below:
FROM scratch
RUN skype
I have skype installed in my OS and when I try to build the docker with below command:
sudo docker build -t tryskyped .
It says
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM scratch
--->
Step 2/2 : RUN skype
---> Running in 0ecf7c719567
container_linux.go:247: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory"
oci runtime error: container_linux.go:247: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory"
If I am not wrong it should have executed like /bin/sh -c skype. When I manually try this , I can see the skype opens
I am very new to this and I am just trying out docker.Please help
Your Dockerfile does nothing, as it does not have a CMD or ENTRYPOINT to execute.
A Dockerfile has a configuration phase (the RUN, ADD, COPY and so) and a start phase, with ENTRYPOINT and CMD
As an example, the last line of the Dockerfile for the Nginx image reference contains
extract from
https://github.com/nginxinc/docker-nginx/blob/0c7611139f2ce7c5a6b1febbfd5b436c8c7d2d53/mainline/jessie/Dockerfile
CMD ["nginx", "-g", "daemon off;"]
Check What is the difference between CMD and ENTRYPOINT in a Dockerfile?
The doc for CMD
https://docs.docker.com/engine/reference/builder/#cmd
for ENTRYPOINT
https://docs.docker.com/engine/reference/builder/#entrypoint
Related
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?
FROM scratch
RUN mkdir hello
This is my Dockerfile, and i am unable to build image for this.
Build command is docker build -t sample .
Below is the output
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM scratch
--->
Step 2/2 : RUN mkdir hello
---> Running in faafa9f9aa98
OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown
A scratch image contains nothing, not even /bin/sh or /usr/bin/mkdir.
So you can't RUN anything unless you COPY in into the image first.
I have an image that is built using this dockerfile.
# vi Dockerfile
FROM openjdk:8
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
I can login to container in interactive mode and type this command that works as expected.
java -jar /usr/src/myapp/dist/some.jar
But if I add this line to Dockerfile, I get an error:
CMD ["/usr/src/myapp/dist/some.jar", "java"]
docker: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \" -jar /usr/src/myapp/dist/some.jar\": stat -jar /usr/src/myapp/dist/some.jar: no such file or directory".
How do I add the java command to dockerfile?
You are using thus wrongly. It should be
CMD ["java", "-jar", "/usr/src/myapp/dist/some.jar"]
or
CMD java -jar /usr/src/myapp/dist/some.jar
Why don't you use the same command as you would type in?
CMD ["java", "-jar", "/usr/src/myapp/dist/some.jar"]
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.
I am very new to Docker and I am able to successfully create an Image from Docker file but when I pulled it and ran a docker start on that it threw following error:
Error response from daemon: oci runtime error:
container_linux.go:247: starting container process caused "exec: \"./Myfolder\": stat ./Myfolder: no such file or directory".
The only place that I mentioned /Myfolder is in docker File ENTRYPOINT
as below ENTRYPOINT ["./Myfolder"]
While my Dockerfile looks like following:
FROM microsoft/dotnet:1.1.1-runtime
WORKDIR /opt/outputDirectory
ENTRYPOINT ["./Myfolder"]
COPY output /opt/outputDirectory
and this is assuming my entry point is the ENTRYPOINT project's directory name (the one containing /bin) what could I be missing?
ENTRYPOINT specify the program that runs inside the container. You've put a directory.
See this example:
FROM microsoft/dotnet:1.0-runtime
WORKDIR /app
COPY out ./
ENTRYPOINT ["dotnet", "dotnetapp.dll"]