Docker can't find OpenJDK - docker

I am experimenting with Docker for the first time, and am trying to get a Spring Boot web app to run inside a Docker container. I am building the app (which packages up into a self-contained jar) and then adding it to the Docker image (which is what I want).
I am following the instructions from the OpenJDK Docker base image here. You can find my SSCCE at this Bootup repo on GitHub, whose README has all the instructions to reproduce what I'm seeing. But basically:
I build the web app into a jar
Run docker build -t bootup . which succeeds
Run docker run -it --rm --name bootup bootup which gives me the error below and then exits
The error:
/bin/sh: 1: /bin/sh: [java,: not found
According to the Google Gods, this used to be a problem with the Oracle JDK images, but should not be happening with OpenJDK images.
Looking at my Dockerfile (which is also up in that GitHub repo), can anyone spot where I'm going awry:
FROM openjdk:8
RUN mkdir /opt/bootup
ADD build/libs/bootup.jar /opt/bootup
WORKDIR /opt/bootup
ENTRYPOINT ['java', '-jar', 'bootup.jar']
CMD ['']
Thanks in advance!
Update:
Output of docker ps:
CONTAINER ID IMAGE COMMAND CREATED
16bde964ff6b bootup "/bin/sh -c 'java -ja" 2 days ago
STATUS PORTS NAMES
Up 14 seconds 0.0.0.0:8080->8080/tcp bootup

I had it working fine using this dockerfile:
FROM openjdk:8
RUN mkdir /opt/bootup
ADD build/libs/bootup.jar /opt/bootup
WORKDIR /opt/bootup
EXPOSE 8080
ENTRYPOINT java -jar bootup.jar
It runs just fine with this commad:
docker run -it -p 8080:8080 --name bootup bootup
I am no java developer and I don't know why it ignores your configuration that requires it to start on port 9200, since your app starts on port 8080, but from a docker point of view everything is working with my config and I can connect to the app from my browser on localhost:8080
Here the screenshot:
Also, since you posted your github repo I suggest you to modify the readme so that users can start gradle from docker without the need of a java environment in the host machine running this one time command:
docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp openjdk:8 /usr/src/myapp/gradlew clean build

Related

docker file for tomcat

I wrote one docker file for tomcat installation, the file is
FROM openjdk:8-jre-alpine
RUN wget http://mirrors.fibergrid.in/apache/tomcat/tomcat-8/v8.5.34/bin/apache-tomcat-8.5.34.tar.gz
RUN gzip apache-tomcat-8.5.34.tar.gz
ADD https://github.com/spagop/quickstart/raw/master/management-api-examples/mgmt-deploy-application/application/jboss-as-helloworld.war /apache-tomcat-8.5.34/*/webapps
EXPOSE 8080
CMD ["catalina.sh", "run"]
And I built the above docker file by using
$ docker build -t tomacat -f docker file name .
And created the container by using above docker image, command is
$ docker run --name=tom1 -d -it -p 9090:8080 tomcat
After running the docker run container is up and running
But tomcat server is not up and running in background
I replaced the catalina.sh with startup.sh in CMD area and also i getting same problem
Please help me for resolving problem
As mentioned in the question, I did everything as stated and started a container. After that I accessed the tomcat through HOST_IP:HOST_PORT and I was able to access the Tomcat. The issue may be that you are not accessing the Tomcat correctly like HOST_IP is not correct.

JHipster docker image from DockerHub is not working

I am trying to run the JHipster in docker container and followed the steps mentioned in https://jhipster.github.io/installation/.
> docker pull jhipster/jhipster
> mkdir ~/jhipster
> docker run --name jhipster -v ~/jhipster:/home/jhipster/app -v ~/.m2:/home/jhipster/.m2 -p 8080:8080 -p 9000:9000 -p 3001:3001 -i -t jhipster/jhipster
As I am running it in interactive mode it showing the JHIPSTER ASCII art and shows :: JHipster :: Running Spring Boot :: :: http://jhipster.github.io ::. Thats it.
When I docker ps:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f0015bd63658 jhipster/jhipster "tail -f /home/jhipst" 2 minutes ago Up 2 minutes 0.0.0.0:3001->3001/tcp, 0.0.0.0:8080->8080/tcp, 0.0.0.0:9000->9000/tcp jhipster
Now when I try to access localhost:8080 I am getting This page isn't working ERR_EMPTY_RESPONSE.
I checked in my ~/jhipster folder, there is nothing.
I logged into container with docker exec -it jhipster bash, there is nothing in app folder.
OS: MacOS
Docker Version: Docker version 1.12.5, build 7392c3b
docker-compose version 1.9.0, build 2585387
What am I missing?
When using the JHipster Docker image, all of the software requirements are installed but you still need to run the generator and choose your options.
Following along the installation documentation, you should log into the container, change to the app folder, and run jhipster:
docker container exec -it jhipster bash
cd /home/jhipster/app
jhipster
Once your application is created, you can run all the normal webpack/gulp and maven commands. For example, the following commands will start your backend and your frontend (run in separate terminals).
./mvnw
yarn start

How do I run Apache 2 on Alpine in Docker?

According to Alpine wiki I have to run rc-service apache2 startafter installation of Apache 2. However, there's no rc-service in the Alpine running inside the container. How do I get the service command to run inside Docker container?
gliderlabs/docker-alpine issue 183 illustrate the docker Alpine image has no service or rc-service.
You can see instead nimmis/docker-alpine-apache based on nimmis/docker-alpine-micro, which includes a runit, used to handle starting and shutting down processes automatically started.
That initd will start the apache2 script, which calls:
exec /usr/sbin/httpd -D FOREGROUND -f /web/config/httpd.conf
Alpine does not have rc-service installed by default. You need to install it (either as part of your Dockerfile build process or manually in the container).
The secret invocation is:
apk add openrc --no-cache
If you want to run it from outside the container (say docker run), then use:
docker run [options etc] bin/ash -c "apk add openrc --no-cache"
PS: rc-service is good for other things and stuff like mariadb (also not included in alpine)

Installing packages for Rstudio Docker

I'm trying to use Rstudio on a DigitalOcean server using the Rstudio docker. Since my experience with linux servers is limited, it's been a bit of a challenge for me.
I'm able to get Rstudio up and running with:
docker run -dp 8787:8787 -v /root:/home/rstudio/ -e ROOT=TRUE rocker/hadleyverse
However, I'd like to be able to shut down the server and save it to a snapshot when I'm not using it, but not have to re-install packages each time I do so.
Using the the docker documentation on updating an image, I am able to create a container, install packages on that container, and then commit the changes:
docker run -t -i rocker/hadleyverse /bin/bash
install.r randomForest
exit
docker commit \<CONTAINER_ID> michael91/ms:v1
However, once I make the commit, I am unable to run the updated image properly. I try and run it as follows:
docker run -dp 8787:8787 -v /root:/home/rstudio/ -e ROOT=TRUE michael91/ms:v1
When I do so, Rstudio server is not activated, as it is when I run the original rocker/hadleyverse version. I've tried making commits with and without installing packages; either way it doesn't seem to work. Obviously I'm doing something incorrectly, but I'm not sure what. If anyone could offer me some guidance, I'd really appreciate it.
Edit: Thanks a lot VonC; that did the trick.
It could be because the new committed image has lost its CMD directive that was present in rocker-org/rocker/rstudio/Dockerfile#L58.
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d /supervisord.conf"]
Try and create a new Dockerfile:
FROM michael91/ms:v1
## Add RStudio binaries to PATH
ENV PATH /usr/lib/rstudio-server/bin/:$PATH
ENV LANG en_US.UTF-8
EXPOSE 8787
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
And build it as michael91/ms:v2.
Then see v2 works better than v1 when it comes to activating RStudio:
docker run -dp 8787:8787 -v /root:/home/rstudio/ -e ROOT=TRUE michael91/ms:v2

Docker add warfile to official Tomcat image

I pulled official Docker image for Tomcat by running this command.
docker run -it --rm tomcat:8.0
By using this as base image I need to build new image that contains my war file in the tomcat webapps folder. I created Dockerfile like this.
From tomcat8
ADD warfile /usr/local/tomcat
When I run this Dockerfile by building image I am not able to see Tomcat front page.
Can anybody tell me how to add my warfile to official Tomcat images webapp folder.
Reading from the documentation of the repo you would do something like that
FROM tomcat
MAINTAINER xyz
ADD your.war /usr/local/tomcat/webapps/
CMD ["catalina.sh", "run"]
Then build your image with docker build -t yourName <path-to-dockerfile>
And run it with:
docker run --rm -it -p 8080:8080 yourName
--rm removes the container as soon as you stop it
-p forwards the port to your host (or if you use boot2docker to this IP)
-it allows interactive mode, so you see if something get's deployed
Building on #daniel's answer, if you want to deploy your WAR to the root of tomcat, I did this:
FROM tomcat:7-jre7
MAINTAINER xyz
RUN ["rm", "-fr", "/usr/local/tomcat/webapps/ROOT"]
COPY ./target/your-webapp-1.0-SNAPSHOT.war /usr/local/tomcat/webapps/ROOT.war
CMD ["catalina.sh", "run"]
It deletes the existing root webapp, copies your WAR to the ROOT.war filename then executes tomcat.
docker run -it --rm --name MYTOMCAT -p 8080:8080 -v .../wars:/usr/local/tomcat/webapps/ tomcat:8.0
where wars folder contains war to deploy
How do you check the webapps folder?
The webapps folder is within the docker container.
If you want to access your webapps container you could mount a host directory within your container to use it as webapps folder. That way you can access files without accessing docker.
Details see here
To access your logs you could do that when you run your container e.g.
docker run -rm -it -p 8080:8080 **IMAGE_NAME** /path/to/tomcat/bin/catalina.sh && tail -f /path/to/tomcat/logs
or you start your docker container and then do something like:
docker exec -it **CONTAINER_ID** tail -f /path/to/tomcat/logs
If you are using spring mvc project then you require server to run your application suppose you use tomcat then you need base image of tomcat that your application uses which you can specify through FROM command.
You can set environment variable using ENV command.
You can additionally use RUN command which executes during Docker Image buiding.
eg to give read write execute permissions to webapps folder for tomcat to unzip war file
RUN chmod -R 777 $CATALINA_HOME/webapps
And one more command is CMD. Whatever you specifying in CMD command it will execute at a time of container running. You can specify options in CMD command using double quotes(" ") seperated by comma(,).
eg
CMD ["catalina.sh","start"]
(NOTE : Remember RUN command execute at a time of image building and CMD execute at a time of running container this is confusing for new users).
This is my Dockerfile -
FROM tomcat:9.0.27-jdk8-openjdk
VOLUME /tmp
RUN chmod -R 777 $CATALINA_HOME/webapps
ENV CATALINA_HOME /usr/local/tomcat
COPY target/*.war $CATALINA_HOME/webapps/myapp.war
EXPOSE 8080
CMD ["catalina.sh","run"]
Build your image using command
docker build -t imageName <path_of_Dockerfile>
check your docker image using command
docker images
Run image using command
docker run -p 9999:8080 imageName
here 8080 is tomcat port and application can access on 9999 port
Try accessing your application on
localhost:9999/myapp/

Resources