Binary build in OpenShift does not work but locally works - docker

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

Related

Run the program in a Linux environment on Windows using Docker

I need to find out how a simple C console application will work in Ubuntu. I have Windows installed on my machine. In order not to run the virtual machine, I decided to use Docker, it seems to be intended for this purpose. But I don't understand how to do it.
I downloaded and installed Docker Toolbox from here https://docs.docker.com/toolbox/toolbox_install_windows/
Then I run Docker Quickstart Terminal and write $ docker run ubuntu gcc-o hello hello.c there and get an error:
C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"gcc\": executable file not found in $PATH": unknown.
hello.c - source code in C that prints "hello world" to the screen. This file is located in the same directory as docker.exe
Other commands from ubuntu, such as $ docker run ubuntu echo 'Hello world' work
I'm new to Docker. Am I using Docker as intended? If so, why doesn't it work ?
Create a file and name it dockerfile next to your hello.c. Your folder should look like this
- tempdir
|_ hello.c
|_ dockerfile
In the dockerfile file you will give instructions to docker on how to build your container image. Paste into dockerfile theses instructions
FROM gcc
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
RUN gcc -o myapp hello.c
CMD ["./myapp"]
Then you can build your image using this command
C:\tempdir> docker build . --tag helloworldfromgcc
note: make sure you are in the dockerfile folder
and last, run your container :)
docker run helloworldfromgcc
Explanations on the dockerfile instructions
# Here you are telling docker that as a base image it should use gcc.
# That image will be downloaded from here: https://hub.docker.com/_/gcc
# that gcc image has the linux kernel and gcc installed on it (not accurate, but good enough to understand)
FROM gcc
# This line will copy your files from your machine disk to the container virtual disk.
# This means the hello.c file will be copied into /usr/src/myapp folder inside the container
COPY . /usr/src/myapp
# This is like doing 'cd /usr/src/myapp'
WORKDIR /usr/src/myapp
# You know this one :) just call gcc with the standard params
RUN gcc -o myapp hello.c
# CMD differs from run because it will be executed when you run the container, and not when you are building the image
CMD ["./myapp"]

"docker run --rm hello" run into "failed: No such file or directory" error

I am new to docker, and follows the instructions at https://docs.docker.com/develop/develop-images/baseimages/ to create a docker image and tried to run:
My docker file is as follows:
FROM scratch
ADD hello.sh /
CMD ["/hello.sh"]
The hello.sh file is as follows. I have applied dos2unix to hello.sh to ensure the right encoding:
#!/bin/sh
echo "this is a test"
I followed the instruction in the doc to run the following command to build an image:
docker build --tag hello .
Then when I ran docker run --rm hello I got the following error:
[FATAL tini (8)] exec /hello.sh failed: No such file or directory
Have searched online and tried solutions from various posts. But none of them worked. Any insights on where I did wrong?
related non-helpful threads:
1. https://forums.docker.com/t/standard-init-linux-go-175-exec-user-process-caused-no-such-file/20025/4
Building an image from 'scratch' means your resulting container is just an empty filesystem. Especially being new to Docker, you should build from a small image like 'alpine' instead of 'scratch' then run your script using sh.
If you are set on building from scratch you will need to compile your own binary then add it as the ENTRYPOINT or CMD of the image Install Bash on scratch Docker image
docker documentation example on building from scratch https://docs.docker.com/develop/develop-images/baseimages/

ERRO[0001] error waiting for container: context canceled

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.

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

Docker- Image and Container to build and run an Executable file

Am new to Docker technologies, I have build an executable file in Visual Studio 2015 on Windows 10 machine.
Am looking to dockerize this executable file. I have build an Image and Container but the exe file is not being execute.
Here is my work so far:
Docker file:
FROM microsoft/aspnetcore:1.1
COPY . /app
WORKDIR /app
ENTRYPOINT ["dotnet","Controller.exe"]
CMD ["Controller.exe","RUN"]
Command used to create Image:
docker build -t imagename:version
Command used to create controller:
docker run -it --name Controller_name Image_ID run
Am trying to start the controller, but the controller is not starting
I have performed docker logs and here is the information in the log file.
A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\app'.

Resources