java not found error when running docker container - docker

I have simple Dockerfile as below :
FROM centos:centos7
FROM adoptopenjdk/openjdk8:jre8u352-b05-ea-ubuntu-nightly
EXPOSE 8080
WORKDIR /home/centos
COPY ./abc.jar /tmp/abc.jar
CMD ["java" "-jar", "/tmp/abc.jar"]
Now, after building the image , trying to run the container using docker run command , but it is giving error
/bin/sh: 1: [java: not found
I simply don't understand what's the issue here. I'm assuming that , openjdk image will create the java environment and set all PATHS .
Please suggest

Related

java not found error when running docker container [duplicate]

I have simple Dockerfile as below :
FROM centos:centos7
FROM adoptopenjdk/openjdk8:jre8u352-b05-ea-ubuntu-nightly
EXPOSE 8080
WORKDIR /home/centos
COPY ./abc.jar /tmp/abc.jar
CMD ["java" "-jar", "/tmp/abc.jar"]
Now, after building the image , trying to run the container using docker run command , but it is giving error
/bin/sh: 1: [java: not found
I simply don't understand what's the issue here. I'm assuming that , openjdk image will create the java environment and set all PATHS .
Please suggest

Docker - Getting manifest for openjdk:8-java-alpine not found

I tried small docker application.
This is my Dockerfile:
FROM openjdk:8-java-alpine
ADD target/hello-world-rest-api.jar hello-world-rest-api.jar
ENTRYPOINT ["java","-c","java -jar /hello-world-rest-api.jar
Getting the below error when I tried to run build cmd.
C:\Docker-SpringBoot-Projects\docker-crash-course-master\01-hello-world-rest-api>docker build -t dowlathbasha/hello-world-rest-api:dockerfile1 .
Sending build context to Docker daemon 16.97MB
Step 1/3 : FROM openjdk:8-java-alpine
manifest for openjdk:8-java-alpine not found
Pls, suggest.
There is no image named, openjdk:8-alpine hosted in Docker Hub
Try using alternative image such as FROM openjdk:8-alpine in Dockerfile
you may use following docker image for java8
FROM adoptopenjdk/openjdk8:x86_64-alpine-jre8u232-b09
RUN mkdir /app
COPY ./target/hello-world-rest-api.jar /app/hello-world-rest-api.jar
WORKDIR /app
CMD ["java", "-jar", "hello-world-rest-api.jar"]
source:- https://hub.docker.com/r/adoptopenjdk/openjdk8

Docker unable to run a shell script inside a container using dockerfile

I am facing a highly trivial problem wherein the shell script "httpd-service.sh" is not getting executed in the below Dockerfile.
FROM localhost:5000/httpd_custom_image:v6
WORKDIR /opt
ADD httpd-service.sh .
EXPOSE 80
CMD ["/bin/sh","/opt/httpd-service.sh"]
Below is the content of the httpd-service.sh
#!/bin/bash
/usr/local/apache2/bin/httpd
The script httpd-service.sh is getting copied inside /opt in container and has permissions.
Below is the docker version,
[root#vfecare-3 temp]# docker --version
Docker version 17.03.0-ce, build 3a232c8
Can someone let me know what is breaking here?
Got it working in the foreground with the below lines in the Dockerfile.
CMD ["-D", "FOREGROUND"]
ENTRYPOINT ["/usr/sbin/httpd"]

Running simple Java Gradle app in Docker

I have a simple Java server app with a Gradle build. It works perfectly with gradle run on my host machine. However, I want to build this in a docker image and run as a docker container.
I'm using docker-machine (version 0.13.0):
docker-machine create --driver virtualbox --virtualbox-memory 6000 default
docker-machine start
eval $(docker-machine env default)
I have the following Dockerfile image build script in ./serverapp/Dockerfile:
FROM gradle:4.3-jdk-alpine
ADD . /code
WORKDIR /code
CMD ["gradle", "--stacktrace", "run"]
I can build perfectly:
➜ docker build -t my-server-app .
Sending build context to Docker daemon 310.3kB
Step 1/4 : FROM gradle:4.3-jdk-alpine
---> b803ec92baec
Step 2/4 : ADD . /code
---> Using cache
---> f458b0be79dc
Step 3/4 : WORKDIR /code
---> Using cache
---> d98d04eda627
Step 4/4 : CMD ["gradle", "--stacktrace", "run"]
---> Using cache
---> 869262257870
Successfully built 869262257870
Successfully tagged my-server-app:latest
When I try to run this image:
➜ docker run --rm my-server-app
FAILURE: Build failed with an exception.
* What went wrong:
Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().
> Could not create service of type CrossBuildFileHashCache using BuildSessionScopeServices.createCrossBuildFileHashCache().
* Try:
Run with --info or --debug option to get more log output.
* Exception is:
org.gradle.internal.service.ServiceCreationException: Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().
at org.gradle.internal.service.DefaultServiceRegistry$FactoryMethodService.invokeMethod(DefaultServiceRegistry.java:797)
<snip>
... 60 more
Caused by: org.gradle.api.UncheckedIOException: Failed to create parent directory '/code/.gradle/4.3' when creating directory '/code/.gradle/4.3/fileHashes'
at org.gradle.util.GFileUtils.mkdirs(GFileUtils.java:271)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.open(DefaultPersistentDirectoryStore.java:56)
Why would it have trouble creating that directory?
This should be a very easy task, can anyone tell me how they get this simple scenario working?
FYI, running current versions of everything. I'm using Gradle 4.3.1 on my host, and the official Gradle 4.3 base image from docker hub, I'm using the current version of JDK 8 on my host and the current version of docker, docker-machine, and docker-compose as well.
The fix was to specify --chown=gradle permissions on the /code directory in the Dockerfile. Many Docker images are designed to run as root, the base Gradle image runs as user gradle.
FROM gradle:4.3-jdk-alpine
ADD --chown=gradle . /code
WORKDIR /code
CMD ["gradle", "--stacktrace", "run"]
Ethan Davis suggested using /home/gradle rather than code. That would probably work as well, but I didn't think of that.
The docker image maintainer should have a simple getting started type reference example that shows the recommended way to get basic usage.
Based on the openjdk base image to the gradle image we can see that gradle projects are setup to run in /home/gradle. Check the code out here. gradle run is having trouble running in your new working directory, /code, because the .gradle folder is in the /home/gradle folder. If you copy/add your code into /home/gradle you should be able to run gradle run. This worked for me.

Running .net core docker image, says application started, but on browsing gives "This site can’t be reached" error

I am having Windows 10 Home operating system. I have installed Docker toolbox.
My docker file is as follows:
FROM microsoft/dotnet:1.1-sdk-projectjson
COPY . /app
WORKDIR /app
RUN ["dotnet", "restore"]
RUN ["dotnet", "build"]
EXPOSE 5000/tcp
ENV ASPNETCORE_URLS http://*:5000
ENTRYPOINT ["dotnet", "run"]
I have created docker image by using following command:
$ docker build -t test:webApp3 .
I tried running the image by using following commands:
$ docker run -d -p 8080:5000 -t test:webApp3
$ docker run test:webApp3
Command says application started, but on browsing gives "This site can’t be reached" error.
Can someone please tell me, why its giving me specified error?
Plus can someone tell me, where does docker save created images on Windows 10 OS?
I was able to fix this by referring to following link:
https://medium.com/trafi-tech-beat/running-net-core-on-docker-c438889eb5a#.s3krizvtw
I was required to add, .UseUrls("http://*:5000/") in Main() of Program.cs.
Then I was able to browse, by using following URL:
http://192.168.99.100:5000/api/values

Resources