I have a spring-boot project and I want automatically redeploy my jar in the container.
How to do it correctly?
So far, all I see is this way. It's the right way?
# cd /home/jdev;
# sudo docker stop ca_spring_boot;
# sudo docker rm ca_spring_boot;
# sudo docker rmi ca_app_image;
# sudo docker build -t ca_app_image .;
# sudo docker run -d -p 8888:8080 --name ca_spring_boot ca_app_image
And my Dockerfile
FROM java:8
VOLUME /tmp
EXPOSE 8080
ADD docker-storage/jenkins/workspace/CA/build/libs/ca-1.0.jar app.jar
RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Dspring.profiles.active=container","-jar","/app.jar"]
Thanks.
You could mount a volume and put your app.jar in there. So you do not need to rebuild the image, you just restart the container.
Dockerfile
FROM java:8
ENTRYPOINT [ "sh", "-c", "java -jar /mnt/app.jar" ]
Put your app.jar in /docker/spring/
Build and run:
docker build -t spring_test .
docker run -d -v /docker/spring/:/mnt -p 12384:8080 --name spring_test_running spring_test
If you update your spring application you just do:
docker restart spring_test_running
The previous answer is good. But there is need to restart container every time when you want to test your code. But we can avoid this problem. Just use Spring dev tool
And mount destination directory as described above.
Related
I built a Docker container for my JBoss application. Container ran in AWS EKS Fargate. I found that an OutOfMemory error occurred after the application ran for several minutes. However, it would be fine if the root user is used rather than the created user.
My Dockerfile:
FROM openjdk:8u342-oraclelinux8
ENV WILDFLY_VERSION 11.0.0.Final
ENV JBOSS_HOME /usr/local/jboss_api
ENV HOME /usr/local
RUN groupadd -r jboss && useradd -ms /bin/bash -l -r -g jboss jboss \
&& chown jboss /usr/local
USER jboss
WORKDIR ${HOME}
COPY ./wildfly .
RUN tar -xvf wildfly-$WILDFLY_VERSION.tar.gz
RUN rm ./wildfly-$WILDFLY_VERSION.tar.gz
RUN mv ./wildfly-$WILDFLY_VERSION ./jboss_api \
&& mkdir ${JBOSS_HOME}/standalone/configuration/properties
WORKDIR ${JBOSS_HOME}
COPY ./script ./bin
COPY ./properties ./standalone/configuration
COPY ./configurations/standalone.conf ./bin/standalone.conf
COPY ./ROOT.war ./standalone/deployments/ROOT.war
WORKDIR ${JBOSS_HOME}
CMD ./bin/server.sh start
I figured out there is a memory issue for JVM. Therefore -Xmx2500m is set in java config.
-XX:+UnlockExperimentalVMOptions and -XX:+UseCGroupMemoryLimitForHeap are also added by reading some reference articles but the problem still cannot be solved.
Does anyone have an idea about this?
Build docker images using docker file for maven project
When try running docker run getting error saying Unable to access jarfile.
Can some one assist on whats wrong with .
FROM openjdk:8-jre-alpine as release
RUN addgroup -g 1001 -S user1 && user1 -u 1001 -S user1 -G user1
WORKDIR /home/app
COPY --from=builder /home/app/service-1.0.0.jar .
RUN chown -R user1:user1 /home/app
USER user1
ENTRYPOINT ["java", "-jar" ,"/home/app/service-1.0.0.jar"]
but when i go for docker run with local config files as build mount
docker run -it --mount type=bind,source=D:/Java/service/docker/config,target=/home/app services
Unable to access jarfile /home/app/service-1.0.0.jar
Can someone assist on this or is something wrong i did??
I am not sure if you are looking for multistage docker build. If not, you need not use "COPY --from=builder" as it tires to copy the build artifact from your previous stage to this new stage. If it is a single stage docker build, you might just use the copy as follows -
COPY /home/app/service-1.0.0.jar .
Able to resolve the same, Issue was due to mound of config files not happened properly.
instead of docker run -it --mount type=bind,source=D:/Java/service/docker/config,target=/home/app services changes it to docker run -it --mount type=bind,source=D:/Java/service/docker/config/app.config,target=/home/app services which made service to load and work
I can properly launch this Java 8 application using this command from a bash shell:
java -cp "simple-queue-0.1-SNAPSHOT.jar:jms-1.1.jar:commons-logging-1.2.jar:activemq-all-5.13.3.jar"
-Dserver1="my1.domain.com"
-Dserver2="my2.domain.com"
-Dusername="user"
-Dpassword="passwd"
com.fusesource.activemq.exercises.simple.queue.SimpleProducer
I want to containerize this application, so here is my Dockerfile:
FROM store/oracle/serverjre:8
MAINTAINER <me#myco.com>
EXPOSE 4567
VOLUME /data
COPY build/libs/*.jar /usr/local/bin/
COPY /app/simple-queue-0.1-SNAPSHOT.jar /usr/local/bin/
CMD ["java", "-cp", "/usr/local/bin/simple-queue-0.1-SNAPSHOT.jar:/usr/local/bin/jms-1.1.jar:/usr/local/bin/commons-logging-1.2.jar:/usr/local/bin/activemq-all-5.13.3.jar", "-Dserver1=$SERVER1", -Dserver2="$SERVER2", -Dusername="$USER", -Dpassword="$PASSWORD"]
I start my container like this:
docker run -it --rm -e SERVER1=my1.domain.com -e SERVER2=my2.domain.com -e USER=user -e PASSWORD=passwd ecosystem/simple-queue-client:1.1 com.fusesource.activemq.exercises.simple.queue.SimpleProducer
And I get this error message:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"com.fusesource.activemq.exercises.simple.queue.SimpleProducer\": executable file not found in $PATH": unknown.
When I get into that container, I can see that my jar files are in fact inside /usr/local/bin directory which is in the PATH. The CLASSPATH in the container is empty...
What do I need to do to fix this?
I used info from the link provided by midelb above and ended up with two containers: one for SimpleProducer and another for SimpleReceiver.
Here is the Docker file for one:
FROM store/oracle/serverjre:8
MAINTAINER <james.depaul#maxar.com>
VOLUME /data
COPY build/libs/*.jar /usr/local/bin/
COPY /app/simple-queue-0.1-SNAPSHOT.jar /usr/local/bin/
ENTRYPOINT java -classpath /usr/local/bin/simple-queue-0.1-SNAPSHOT.jar:/usr/local/bin/jms-1.1.jar:/usr/local/bin/commons-logging-1.2.jar:/usr/local/bin/activemq-all-5.13.3.jar -Dserver1=$SERVER1 -Dserver2=$SERVER2 -Dusername=$USER -Dpassword=$PASSWORD com.fusesource.activemq.exercises.simple.queue.SimpleConsumer
Build
docker build -t mysystem/simple-client-consumer:1.0
And I call it like this now:
docker run -d --rm -e SERVER1=server-b0.domain.com -e SERVER2=server-b1.domain.com -e USER=user -e PASSWORD=passwd mysystem/simple-client-consumer:1.0
I have two docker images: imageA and imageB.
ImageA Dockerfile
FROM openjdk:11-jre-slim
COPY ./target/java-app.jar /java-application/
ImageB Dockerfile
FROM imageA
# Install Python.
RUN \
apt-get update && \
apt-get install -y python python-dev python-pip python-virtualenv && \
rm -rf /var/lib/apt/lists/*
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
ENTRYPOINT ./startPythonServiceAndJavaApp.sh
startPythonServiceAndJavaApp.sh - is the scrip to start both java app and python app.
java -XX:+UseContainerSupport $JAVA_OPTIONS -jar ./java-application/java-app.jar & python app.py;
Then I build imageA - docker build -t imageA .. It builds successfully.
Then I build imageB and start the container. The python app starts successfully, but I get error
Error: Unable to access jarfile ./java-application/java-app.jar
When I ssh to the running container (note, it is running), I go into app directory. I ran ls and I saw these files:
C:\Users\user>docker exec -it 12345 bash
root#12345:/app# ls
Dockerfile app.py deploy.sh requirements.txt java-app.jar startPythonServiceAndJavaApp.sh
My question, why did java-app.jar end up in the app directory? In the Dockerfile of the imageA I told it to be in java-application directory:
COPY ./target/java-app.jar /java-application/
My question can be rephrased COPY and WORKDIR together. As a quick solution, I put the jar file into root of the docker context. Then I started both application from that context.
Here are the changes:
ImageA Dockerfile - just copy to the root of container.
COPY ./target/java-app.jar /
startPythonServiceAndJavaApp.sh
java -XX:+UseContainerSupport $JAVA_OPTIONS -jar ./java-app.jar & python app.py;
Both applications are running now in the single container. Hope this will help others. Please, correct me if I am wrong or share your ideas.
Is it possible to copy an existing WebSphere profile and run it on WebSphere in Docker?
I am doing some research on containerization, virtualization, etc. and am currently working with Docker. Getting WebSphere up and running on Docker is simple enough:
docker run --name wasserver -h wasserver -p 9043:9043 -p 9443:9443 -d ibmcom/websphere-traditional:install
What I'd like to do is use a profile from another WebSphere instance and run that on the Docker WebSphere. I have tried to do the following in an attempt to mount a directory that contains the profile in question, and to run same:
docker run -v /opt/WebSphere/WAS8_5/:/WASDIR --name myprofileserver -h myprofileserver -p 9043:9043 -p 9443:9443 -d ibmcom/websphere-traditional:install -e PROFILE_NAME=/WASDIR/profiles/myprofile1
The end result of this command is that the container is created, but does not run:
docker: Error response from daemon: oci runtime error: exec: "-e": executable file not found in $PATH
Perhaps there is a switch, setup, or other configuration I am missing here?
The last argument to docker run is the command you want to run inside the container (or the name of the image if you're running the default entrypoint / cmd). You just need to move your environment variable definition back in the command like this:
docker run -v /opt/WebSphere/WAS8_5/:/WASDIR --name myprofileserver -h myprofileserver -p 9043:9043 -p 9443:9443 -d -e PROFILE_NAME=/WASDIR/profiles/myprofile1 ibmcom/websphere-traditional:install