Reputation: 6739
Installed docker on Cent OS using the steps mentioned here
So far I can run docker images of jetty and cassandra independently by following the steps mentioned Jetty & Cassandra
I want to create a docker container which will have Cassandra database
and a web application running in Jetty server
which interacts with this database.
I'm able to create docker container with Jetty and able to run some sample web application with in jetty using the following Dockerfile
content
FROM jetty
RUN mkdir /var/lib/jetty/webapps/test-app
COPY index.html /var/lib/jetty/webapps/test-app/
and once I save this file as Dockerfile I issue the following commands to create docker image and run the same
docker build -t test-docker .
docker run -d -p 8443:8080 test-docker
now I can see the same outcome of this application in my browser using
<ip_address>:8443/test-app/index.html
Question:
How I should be able to integrate Cassandra database with in this docker image and run the complete Jetty + Cassandra + Web Application
packaged as a group?
Upvotes: 2
Views: 1237
Reputation: 6739
As mentioned in the Docker Cassandra Documentation instead of running cassandra with
docker run --name some-cassandra -d cassandra:tag
mention all the ports that cassandra uses so that the same can be communicated or interacted from external resources like below
docker run --name some-cassandra -d -p 7000:7000 -p 7001:7001 -p 7199:7199 -p 9042:9042 -p 9160:9160 cassandra:tag
Now my web application running in Jetty Container can access the Cassandra database using Java Driver.
Note: if you are using Cassandra version > 3.0 then you should use cassandra-driver-core
of version >= 3.0
Maven dependency for cassandra-driver-core
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.0.0</version>
</dependency>
and cassandra-driver-mapping
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
<version>3.0.0</version>
</dependency>
Upvotes: 1
Reputation: 4562
You can use Cassandra Official Docker Image, to start cassandra database. Start your web application in a seperate container as you are doing right now.
You can link cassandra container with your web application container
docker run --name webapp --link cassandra:cassandra -d test-docker
You need to use cassandra hostname/container IP in the webapplication. You can pass the cassandra DB_URL as environment variable.
docker run --name webapp --link cassandra:cassandra -e DB_URL='cassandra:7000' -d test-docker
Read more about Docker container Linking
Upvotes: 0