I would like to setup a Docker container using the following image: https://github.com/heroku/stack-images
I have installed the image inside Docker using
docker pull heroku/cedar:14
Which steps are required to start a Docker container that works in the same way Heroku does?
Communicate via Heroku ToolBelt cli in order to start and scale the application
Deploy applications using git and build using Java BuildPack
I've found an approach where you can turn an Heroku application into a Docker container but it is not the solution i'm looking for:
http://www.centurylinklabs.com/heroku-on-docker/
Checkout the Dokku project. It utilizes a docker project called buildstep to run Heroku buildpacks in a Cedar-like environment.
Have fun!
Related
I have a spring boot microservice in a docker container. The container runs locally just fine but it doesn't on EC2. My local Java version is 12. My local docker version is 18.06.1-ce, same as the EC2 instance docker version.
The dockerfile is as follows
FROM openjdk:12-alpine
VOLUME /tmp
COPY target/my-api-0.0.1.jar /app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
when I try to run this container on EC2 I get the error:
Error: Invalid or corrupt jarfile /app.jar
EC2's Java version is 1.7.0_231. But I imagine that since I'm using Java 12 in my docker container the container would execute the jar inside it in a java 12 environment.
I don't know why I'm still getting the "invalid or corrupt jar" error.
I have done mvn clean and mvn package before building the docker container locally.
Any help? Thanks!
I have a Java web app with Tomcat embedded in my jar file. I can containerize the app with Docker and run it with command java -jar -myapp.jar, but I can't run that container in Heroku. I tried using heroku CLI to dockerize and deploy, but Heroku gives me an error of "can't access jarfile".
I tried to fix this by using heroku deploy:jar to deploy my fat jar, but this erroneously gives me an error:
heroku deploy:jar target/*.jar -a medscanner2
-----> Packaging application...
- app: medscanner2
- including: target/medscanner2.jar
! ERROR: Could not get API key! Please install the Heroku CLI and run
`heroku login` or set the HEROKU_API_KEY environment variable.
! Re-run with HEROKU_DEBUG=1 for more info.
!There was a problem deploying to medscanner2.
!Make sure you have permission to deploy by running: heroku apps:info -a
medscanner2
I am signed into Heroku and I can use heroku auth:whoami to verify that, I can push containers and deploy them, so this error doesn't make any sense. I reran with HEROKU_DEBUG=1 and it did not return any more info.
I further tried to set the HEROKU_API_KEY variable in the CLI with a token I got from Heroku and this still caused the same error when I try to deploy the jar.
I am using a Procfile (although I am not sure it is necessary):
web: java -Dserver.port=$PORT -jar target/medscanner2.jar
Since the issue seems to be indicating there is an issue with access I don't see how the Procfile could be influencing it.
What is the best way for me to deploy a Java web app that does not using Spring Boot to Heroku? I have separately deployed the docker container successfully to Google app engine, so all this work for Heroku is very frustrating.
I ended up fixing this by using webapp-runner to deploy my app. It runs the webapp-runner jar which can run your .war files. This required adding the heroku-maven-plugin and maven-dependency-plugin.
I could then add a Procfile: web: java -jar target/dependency/webapp-runner.jar target/*.war --port $PORT
and use the Heroku CLI to add the app using git. The link with webapp-runner is a guide to deploying tomcat java apps with webapp-runner.
I'm looking for a way to run Heroku CLI commands within a java application hosted on Heroku.
I'd like to be able to run commands like heroku pg:backup heroku pg:restore etc
Is there a way to do that ?
EDIT : I added the Heroku CLI to my app, now I'm looking for a way to invoke heroku commands from my java code.
Maybe you could use something like this :
ProcessBuilder pb = new ProcessBuilder("/path/to/herokuCLI", "myCommand");
Problem is I don't know how to find the right path.
If you look at the file structure of your app on Heroku you can only find your .war + some "configuration files" which is quite normal as you only push a war to Heroku : Procfile system.properties target
Besides I don't think that's the right way to do that.
I'd like to avoid doing backup/restore operations in pure java code.
Maybe you can't rely on Heroku cmd to do the job for you after all.
You'll need to add the Heroku CLI buildpack to your application. You can do so with: heroku buildpacks:add heroku-community/cli
Push a new build after you've done so and you'll now be able to run CLI commands from inside your application dynos. You can see some additional information about this in the documentation.
I am quite new to Jenkins and Docker so I am stuck with trying to make them work together. What I want is to do next steps:
Build my project war-file on Jenkins (Done)
Update Docker image and container. In my case I want to stop running container (Tomcat on it), change war-file to the newest and then run it again.
I've already deploy my application on Docker, but this app is not updated by Jenkins.
I found some plugins, like docker-build-step or docker-plugin, however there are not enough information and tutorials about it and I find it really annoying spending hours and making random suggestions.
I would appetiate any useful tutorial as more spesific as possible.
Perhaps you don't need any of these plugins. You can implement it using command api of docker.
You need to install docker on the jenkins host machine.
Then in your Jenkins build config mvn plugin(or execute shell) to build target:
clean package assembly:assembly -Dmaven.test.skip=true
execute shell something like:
docker build --net=host -t reg.docker.xxx.com/xxx/xxx:latest ./
docker login --username=xxx --password=xxx reg.docker.xxx.com
docker push reg.docker.xxx.com/xxx/xxx:latest
execute shell bellow:
docker -H tcp://swarm.xxx.com:<port> --tlsverify --tlscacert=./ca.pem --tlscert=./cert.pem --tlskey=./key.pem run -v /home/admin/rc.local:/etc/rc.local:ro reg.docker.xxx.com/xxx/xxx:latest
------Edit-------
use docker upgrade if updating existing containers.
I was trying to build a JAVA web application using Docker. I was making a docker container to deploy and run the application. I am beginner. So I started with small POC for java application(jar) which was working fine. I made some changes for JAVA web application(war) and created a Dockerfile for the project which is as follows :
Dockerfile
---------------------------------------------------
FROM java:8
RUN apt-get update
RUN apt-get install -y maven
WORKDIR /code
ADD pom.xml /code/pom.xml
ADD src/main/webapp/WEB-INF/web.xml /codes/rc/main/webapp/WEB-INF/web.xml
RUN ["mvn", "dependency:resolve"]
ADD src /code/src
RUN ["mvn", "package"]
CMD ["usr/lib/jvm/java-8-openjdk-amd64/bin/java", "-war", "target/techpoint.war"]
----------------------------------------------------
Build was successful but when I run the application - It says
"Unrecognized option: -war | Error: Could not create the Java Virtual Machine | Error: A fatal exception has occurred. Program will exit"
And when I replaced "-war" with "-jar" - It says "no main manifest attribute, in target/myapp.war"
Can somebody tell me how can I make JAVA web application (war) compatible with Docker deployment process. That means what should be the actual Dockerfile (with commands) to make possible to build and run the application?
You need a web server or an application server container like tomcat or Jboss (and many others) to deploy and run your java based web application. Your "techpoint.war" files need to be copied to the specific folder depends on each web server. For example, if you are using Tomcat then you can copy it to the /webapps folder. Tomcat will extract and deploy the war file.
You can add the following to your DockerFile.
FROM tomcat:8.5.11-jre8
COPY /<war_file_location>/techpoint.war /usr/local/tomcat/webapps/techpoint.war
You can build the image using docker build command and start the container from the created image.
docker build -t techpoint.
docker run -it --rm -p 8091:8080 techpoint
Now Tomcat will extract and deploy your war file.How to access the deployed application depends on the webroot of your application. For example,
http://<ip_address>:8091/techpoint/index.html