I want to add camunda-bpm-wildfly with active mq and run in same docker container.
First I added them to two containers and tried to run as follows. It was OK.
1. Running camunda-bpm-wildfly.
Dockerfile :
FROM camunda/camunda-bpm-platform:wildfly-latest
ADD standalone.xml standalone/configuration/
ADD bin/ bin/
ADD fusepatch/ fusepatch/
ADD modules/ modules/
ADD hawtio-wildfly-1.5.3.war standalone/deployments/
Commands :
docker build my-wildfly .
docker images
sudo docker run -d --name my-wildfly --net="host" -p 7070:7070 my-wildfly
2. Running activemq.
Dockerfile :
FROM webcenter/activemq:latest
Commands :
docker build amq-alone .
docker images
docker run --name='amq-alone' -d -p 8161:8161 -p 61616:61616 -p 61613:61613 amq-alone
Then I searched for a way to add two images to the same container and noted that we can't add multiple images to the same container[Ref : Docker - container with multiple images.
Then I downlaoded the activemq and I tried to extend it as follows.
It builds correctly and when I run also it runs correctly. But only wildfly runs in port 7070 not the activemq.
Dockerfile :
FROM camunda/camunda-bpm-platform:wildfly-latest
ADD standalone.xml standalone/configuration/
ADD bin/ bin/
ADD fusepatch/ fusepatch/
ADD modules/ modules/
ADD hawtio-wildfly-1.5.3.war standalone/deployments/
ADD apache-activemq-5.15.2/ apache-activemq-5.15.2/
RUN apache-activemq-5.15.2/bin/activemq start
Commands :
docker build my-wildfly-amq .
docker images
sudo docker run -d --name my-wildfly-amq --net="host" -p 7070:7070 -p 8161:8161 -p 61616:61616 -p 61613:61613 my-wildfly-amq
Log :
me#my-pc:~/$ docker build -t=my-wildfly-amq .
Sending build context to Docker daemon 375.8MB
Step 1/8 : FROM camunda/camunda-bpm-platform:wildfly-latest
---> 274d119b1660
Step 2/8 : ADD standalone.xml standalone/configuration/
---> Using cache
---> 41c2f6d423ec
Step 3/8 : ADD bin/ bin/
---> Using cache
---> 27c1952f442e
Step 4/8 : ADD fusepatch/ fusepatch/
---> Using cache
---> 66419d22d6b7
Step 5/8 : ADD modules/ modules/
---> bbdee5ab8ea2
Step 6/8 : ADD hawtio-wildfly-1.5.3.war standalone/deployments/
---> 237821cdb2c8
Step 7/8 : ADD apache-activemq-5.15.2/ apache-activemq-5.15.2/
---> 309b552b5150
Step 8/8 : RUN apache-activemq-5.15.2/bin/activemq start
---> Running in ce0e55cfd13b
INFO: Loading '/camunda/apache-activemq-5.15.2//bin/env'
INFO: Using java '/usr/bin/java'
INFO: Starting - inspect logfiles specified in logging.properties and log4j.properties to get details
INFO: pidfile created : '/camunda/apache-activemq-5.15.2//data/activemq.pid' (pid '46')
---> f903dc0b2db5
Removing intermediate container ce0e55cfd13b
Successfully built f903dc0b2db5
Successfully tagged my-wildfly-amq:latest
What am I missing here? How to add active mq with the camunda-bpm-wildfly running in same docker container?
UPDATE#1 :
With the #bluescore 's answer I tried to use CMD as follows and it worked. Both activemq and wildfly was started. But one problem is there. Normally when we start camunda-bpm-wildfly we invokes start-camunda.sh (not the wildfly bin/standalone.sh). But here I can't see that file in -ti mode also. How to start the camunda as the image starts itself? (I checked in the dockerhub and github also but couldn't find a tip)
Dockerfile :
FROM camunda/camunda-bpm-platform:wildfly-latest
ADD standalone.xml standalone/configuration/
ADD bin/ bin/
ADD fusepatch/ fusepatch/
ADD modules/ modules/
ADD hawtio-wildfly-1.5.3.war standalone/deployments/
ADD apache-activemq-5.15.2/ apache-activemq-5.15.2/
ADD my-wildfly-amq.sh my-wildfly-amq.sh
CMD bash my-wildfly-amq.sh
my-wildfly-amq.sh
apache-activemq-5.15.2/bin/activemq start
bin/standalone.sh
Docker version 17.09.0-ce
Ubuntu 16.04
You're misunderstanding how RUN works. Use an ENTRYPOINT or CMD script in place of the final RUN command of the container you extended. RUN executes a command during a build, not during a docker run. CMD and ENTRYPOINT tell the container what to execute when it's actually ran.
Check out the Dockerfile for the camunda-bpm-platform image you're using as a base. Notice that CMD at the end, which executes a shell script.
If you want to run both ActiveMQ and wildfly, you should write a shell script that runs both of them, then replace your final RUN with a CMD or ENTRYPOINT to execute that script. Something like:
CMD ["/usr/local/bin/your_script.sh"]
When your container starts up with docker run, this script will run.
Related
Currently I am running windows with docker for windows installed.
I have made a java application in Spring Boot that I want to build an image of and run in a docker container.
What am I doing wrong?
When I run the bellow and can see in my cmd prompt that the application starts and run. But there is no image in in docker and nothing running there.
#
# Build stage
#
FROM maven:3.8.4-openjdk-17 AS build
COPY src /test/src
COPY pom.xml /test
#RUN mvn -f /test/pom.xml clean package
RUN mvn -f /test/pom.xml clean package
#
# Package stage
#
FROM openjdk:17-alpine
COPY --from=build /test/target/test-0.0.1-SNAPSHOT.jar /usr/local/lib/test.jar
ENTRYPOINT ["java","-jar","/usr/local/lib/test.jar"]
What am I missing?
I have the application in a folder /test and the Dockerfile is also under /test. I go to this location in the cmd prompt and enter:
docker build -t testapp .
The command you are running, docker build -t testapp ., only creates the docker image that you can check with the command someone stated in the comments : docker images -a.
To run the image in a docker container you must use the run command : docker run testapp. Then you will see the container in the Docker app.
docker build will only build docker image
if you want to run the image in your docker try running the command
docker run testapp
docker build builds a new image from the source code.
docker create creates a writeable container from the image and prepares it for running.
docker run creates the container (same as docker create) and runs it.
I was doing everything correct except for that when I thought the image was ready/built I run test of my java application that looked as the application had started.
By setting <maven.test.skip>true</maven.test.skip> I skipped the test and the build was finished. I got the image which I now can start. Thank you all for your question and assistance.
I have a Ubuntu server with a WildFly standalone installation configured, here i have a Java app that is accesible on port 80, i want to dockerize it. When create the container, i'm copying the entire WildFly directory from my local storage to the container, when i run the command docker run -d --name dej_website -p 80:80 wildfly_dej_website:2.0 the container start, but when try to access in my local machine localhost doesn't works.
What am i doing wrong? How can i do to access to this container, with the configured server?
This is my dockerfile
FROM centos
#INSTALL JAVA
RUN yum -y install java-11-openjdk
RUN java -version
RUN mkdir /opt/DEJ_Wildfly/
#SET OPT AS WORK DIRECTORY
WORKDIR /opt/DEJ_Wildfly/
#COPY WILDFLY SERVER FILES
COPY wildfly-11.0.0.Final .
#DEFINE ENVIRONMENT VARIABLE
ENV JBOSS_HOME /opt/DEJ_Wildfly/wildfly-11.0.0.Final/
#EXECUTE SH FILE
CMD JBOSS_HOME/bin/standalone.sh -b=0.0.0.0
CMD tail -f /var/log/lastlog
#EXPOSE 80
This is the log of docker build --tag wildfly_dej_website:2.0 . command:
Sending build context to Docker daemon 597.4MB
Step 1/9 : FROM centos
---> 300e315adb2f
Step 2/9 : RUN yum -y install java-11-openjdk
---> Using cache
---> f333f6149e02
Step 3/9 : RUN java -version
---> Using cache
---> 0110143899c7
Step 4/9 : RUN mkdir /opt/DEJ_Wildfly/
---> Running in 88bc6f0632c1
Removing intermediate container 88bc6f0632c1
---> c0ab7cc8a364
Step 5/9 : WORKDIR /opt/DEJ_Wildfly/
---> Running in 84705355ac2c
Removing intermediate container 84705355ac2c
---> 6986f8229cb0
Step 6/9 : COPY wildfly-11.0.0.Final .
---> 3caf8ec0e5d0
Step 7/9 : ENV JBOSS_HOME /opt/DEJ_Wildfly/wildfly-11.0.0.Final/
---> Running in b5f649e4e2e0
Removing intermediate container b5f649e4e2e0
---> 27d775c3d0cb
Step 8/9 : CMD JBOSS_HOME/bin/standalone.sh -b=0.0.0.0
---> Running in c7ffddb4bcdf
Removing intermediate container c7ffddb4bcdf
---> 533d3836f94d
Step 9/9 : CMD tail -f /var/log/lastlog
---> Running in f92aca5a63ba
Removing intermediate container f92aca5a63ba
---> 974e6ec6c415
Successfully built 974e6ec6c415
Successfully tagged wildfly_dej_website:2.0
This is the list of containers:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
95ee0139f42c wildfly_dej_website:2.0 "/bin/sh -c 'tail -f…" 4 seconds ago Up 2 seconds 0.0.0.0:80->80/tcp dej_website
The problem here is in your dockerfile.
You need to add a CMD at the end of your dockerfile to run the command you want and keep it running for the docker file to stay alive and provide you with logs through docker logs command.
Add a line like this to your dockerfile:
RUN ./standalone.sh -b 0.0.0.0
CMD tail -f /var/log/syslog
And to make the port accessible on the local machine you'll need to use -p option when issuing the docker run command like this:
docker run -d -p 127.0.0.1:80:8080 <image>
you can find out more here:
https://docs.docker.com/engine/reference/commandline/run/
I am trying to edit the standalone.xml through docker and trying to add but the keycloak is taking its standalone.xml . But I am able to see the changes inside the standalone.xml file. I need to add this line in standalone.xml file
<provider>module:org.keycloak.examples.event-sysout</provider>
Also tried hot deployement but then can't fetch third party libraries code
First, it seems in a docker container by default standalone-ha.xml is used. You can find this in /opt/jboss/tools/docker-entrypoint.sh.
Second, I think after changing configuration file you'll have to restart keycloak server (container).
Not sure what do you mean by "dynamically". But it will be easier to modify the file locally and build a custom docker image. Dockerfile may look like:
FROM jboss/keycloak:6.0.1
ADD <path on your system>/standalone-ha.xml /opt/jboss/keycloak/standalone/configuration/standalone-ha.xml
You can not replace or overwrite standalone-ha.xml/standalone.xml without jboss-cli on docker image. Only need to create a sh file and put inside startup-script folder. During initializing it will start and configure your file.
keycloak-cli
embed-server --server-config=standalone-ha.xml --std-out=echo
batch
/subsystem=keycloak-server:list-add(name=providers, value=module:org.keycloak.examples.event-sysout)
run-batch
stop-embedded-server
Dockerfile
FROM jboss/keycloak:latest
COPY keycloak.cli /opt/jboss/startup-scripts/keycloak.cli
Might be a little late . but I found out you can edit on the dockerfile.
FROM quay.io/keycloak/keycloak:11.0.0
RUN sed -i -E "s/(<staticMaxAge>)2592000(<\/staticMaxAge>)/\1\-1\2/" /opt/jboss/keycloak/standalone/configuration/standalone.xml
RUN sed -i -E "s/(<cacheThemes>)true(<\/cacheThemes>)/\1false\2/" /opt/jboss/keycloak/standalone/configuration/standalone.xml
RUN sed -i -E "s/(<cacheTemplates>)true(<\/cacheTemplates>)/\1false\2/" /opt/jboss/keycloak/standalone/configuration/standalone.xml
RUN sed -i -E "s/(<staticMaxAge>)2592000(<\/staticMaxAge>)/\1\-1\2/" /opt/jboss/keycloak/standalone/configuration/standalone-ha.xml
RUN sed -i -E "s/(<cacheThemes>)true(<\/cacheThemes>)/\1false\2/" /opt/jboss/keycloak/standalone/configuration/standalone-ha.xml
RUN sed -i -E "s/(<cacheTemplates>)true(<\/cacheTemplates>)/\1false\2/" /opt/jboss/keycloak/standalone/configuration/standalone-ha.xml
ref : https://github.com/anthonny/kit-keycloak-theme/blob/master/Dockerfile
You should go to that running docker container and change in there.
The best is, use docker manager like Kitematic https://kitematic.com/
Select running keycloak container, click EXEC icon, cd keycloak/standalone/configuration, vi standalone.xml, :wq to exit, restart docker image through Kitematic, should work
I have an sbt project that spins up a server on a specified port. Here is related excerpt from build.sbt:
port in container.Configuration := sys.env.getOrElse("MY_VAR_SEARCH_PORT", 8080).toString.toInt
When I run the project from sbt, $MY_VAR_SEARCH_PORT gets picked up, and all is good.
However, for prod I use sbt-assembly and run a jar in a docker container, so the launch command looks like this:
docker run -it -p 80:80 -e MY_VAR_SEARCH_PORT=80 mydockerhubrepo/myimageid /docker-entrypoint.sh java -Djava.io.tmpdir=/tmp/jetty -Drun.mode=production -Denv=prod -jar /usr/local/jetty/start.jar
I can see that var gets passed to the container, but it is not being picked up by the jar, as it spins up a server on default port.
What would be a good way to make sbt-assembly jar access environment variables? Or maybe I can pass this var as java argument - then, how to access it from build.sbt file?
Move java startup command to a shell script that would access env vars without a problem:
In your project, add api_startup.sh:
#!/bin/sh
echo "API startup script running... with ENV=$ENV"
java -Djava.io.tmpdir=/tmp/jetty -Drun.mode=production -Denv=$ENV -Drun.port=$MY_VAR_SEARCH_PORT -jar /usr/local/jetty/start.jar
In your Dockerfile, add lines:
ADD api_startup.sh /api_startup.sh
RUN chown jetty:jetty /api_startup.sh
CMD ["/api_startup.sh"]
Now you can run it like this:
docker run -it -p 80:80 -e MY_VAR_SEARCH_PORT=80 mydockerhubrepo/myimageid
I have docker file
FROM java:8
# Install maven
RUN apt-get update
RUN apt-get install -y maven
WORKDIR /code/
# Prepare by downloading dependencies
#ADD pom.xml /mmt/CouchBaseClient/CB-RestAPI/CacheService/pom.xml
#RUN ["mvn", "dependency:resolve"]
#RUN ["mvn", "verify"]
ADD cacheService-0.0.1-SNAPSHOT.jar /code/cacheService-0.0.1-SNAPSHOT.jar
ADD couchclient-0.0.1-SNAPSHOT.jar /code/couchclient-0.0.1-SNAPSHOT.jar
EXPOSE 4567
CMD ["/usr/lib/jvm/java-8-openjdk-amd64/bin/java", "-jar", "couchclient-0.0.1-SNAPSHOT.jar server cacheService.yml" ]
When I build this file I get the following output
Sending build context to Docker daemon 35.46 MB
Step 1 : FROM java:8
---> 736600fd4ae5
Step 2 : RUN apt-get update
---> Using cache
---> a3466698c29d
Step 3 : RUN apt-get install -y maven
---> Using cache
---> d0fb8e77f89a
Step 4 : WORKDIR /code/
---> Using cache
---> 197735d2da02
Step 5 : ADD cacheService-0.0.1-SNAPSHOT.jar /code/cacheService-0.0.1-SNAPSHOT.jar
---> 9ba30f5a2144
Removing intermediate container bd3c072ebbc6
Step 6 : ADD couchclient-0.0.1-SNAPSHOT.jar /code/couchclient-0.0.1-SNAPSHOT.jar
---> ef59315ed7fe
Removing intermediate container 0da1a69bdb51
Step 7 : EXPOSE 4567
---> Running in a2b32799dd6c
---> 3fb2b534d7c5
Removing intermediate container a2b32799dd6c
Step 8 : CMD /usr/lib/jvm/java-8-openjdk-amd64/bin/java -jar couchclient-0.0.1-SNAPSHOT.jar server cacheService.yml
---> Running in efb44e2bcdb3
---> 56637dfacc0d
Removing intermediate container efb44e2bcdb3
Successfully built 56637dfacc0d
But no directory named code is being made and so no files are being added even though it is giving no compilation error
Used method suggested by #VonC
ENTRYPOINT ["/usr/lib/jvm/java-8-openjdk-amd64/bin/java", "-jar", "couchclient-0.0.1-SNAPSHOT.jar" ]
and then used this command to run the image
docker run <image> -d <arguments>
First, don't forget that ADD <src>... <dest> can invalidate the cache for all following instructions from the Dockerfile if the contents of <src> have changed. See "Best practices" and use COPY instead of ADD.
In both cases (ADD or COPY), if <dest> doesn’t exist, it is created along with all missing directories in its path.
So no mkdir necessary.
COPY cacheService-0.0.1-SNAPSHOT.jar /code/
COPY couchclient-0.0.1-SNAPSHOT.jar /code/
Otherwise, the file cacheService-0.0.1-SNAPSHOT.jar in the folder /code/cacheService-0.0.1-SNAPSHOT.jar/!
Finally, to be sure that the files are where they should be, open a bash:
docker run --rm -it <yourImage> bash
Or, if you have a running container:
docker exec -it <yourContainer> bash
And check what ls /code returns.
Also:
docker run --rm -it --entrypoint /bin/sh <yourImage> -c "ls -alrt"
The OP Legendary Hunter confirms in the comments the files are there.
The issue comes from the CMD which is not fully in exec form.
Each parameter should be in its own quotes:
CMD ["/usr/lib/jvm/java-8-openjdk-amd64/bin/java", "-jar", "couchclient-0.0.1-SNAPSHOT.jar", "server", "cacheService.yml" ]
If the last parameters are grouped together, CMD tries to access the jar file named "couchclient-0.0.1-SNAPSHOT.jar server cacheService.yml", which obvioulsy does not exist.
Hence the error message:
"Error: Unable to access jarfile couchclient-0.0.1-SNAPSHOT.jar server cacheService.yml"
Instead of using CMD, use ENTRYPOINT (with the sa me exec form, each arg in its own double-quotes), and leave CMD undefined.
That way, the arguments you will add to your docker run command will be passed to the ENTRYPOINT (which runs java -jar ...)
Since "server", "cacheService.yml" are the two arguments to be passed to the running container:
ENTRYPOINT ["/usr/lib/jvm/java-8-openjdk-amd64/bin/java", "-jar", "couchclient-0.0.1-SNAPSHOT.jar" ]
Build and then:
docker run --rm -it <image> server cacheService.yml
Once you know it is working, launch it in detached mode:
docker run -d <image> server cacheService.yml
Try this before WORKDIR line:
RUN mkdir /code