Docker Community Forums

Share and learn in the Docker community.

Dockerfile/compose/link which one to use?

docker

(Siddharth67) #1

Hi guys, locally I have an Nodejs service querying data from Cassandra DB.
Now I want to achieve the same through docker and create a image.

I have created a container for my nodejs service and another container running Cassandra DB.(I have done this with commands, I did not use a DockerFile)
How can my service connect to DB? and How can I get one image which has both my service and DB?

Dockerfile,compose and links can do this?

Which is the easiest way? If possible can anyone give a sample file/example on how to do it?
Kindly guide me, I’m confused

Thanks


(Siddharth67) #2

bump
Need a solution…Quick response is appreciated.
Thanks


(Sharath Kumar) #3

I think you can achieve your goal by building a docker-compose.yml file. In this file you can link your Cassandra DB with Nodejs service. Just go through docker compose file reference https://docs.docker.com/compose/compose-file/ . It might help you. And also refer this docker-compose.yml file. It seems to be pretty helpful.
Thank you, Good luck :slightly_smiling:


(Siddharth67) #4

Hi Sharath thanks for an solution, my bad I couldn’t write a decent Dockerfile, ending up with many errors.
If possible can you kindly provide me an sample Dockerfile for my usecase.

Usecase: Ubuntu which runs nodejs npm and a pokle/Cassandra image linking that nodejs app.

Thanks


(Sharath Kumar) #5

siddharth67 you can refer this [dockerfile] (https://github.com/nodejs/docker-node/blob/31bb0d89ab3d67ddb9a998e4bf655c3cd98f445c/5.5/wheezy/Dockerfile) for constructing your own image of nodejs and this dockerfile for image of cassandra. Try to make it work this way and later you can try to merge both images into a single dockerfile. And later you can try to build a docker-compose.yml file for your usecase. I will try to find out a usecase which meets your requirements but till then keep trying it this way.


(Siddharth67) #6

Hi Sharat did you find out any usecase which is similar to my requirement.
I succeeded in created a Docker file for Nodejs and for Cassandra i found one in Docker hub.
How should I proceed to merge them and make one docker file.


(Sharath Kumar) #7

@siddharth67 i tried to find a usecase for your requirements but i couldn’t find anything interesting for you. Anyways as you have succeeded in creating your own dockerfiles you can just work with your own images. When it comes to merging, just copy and paste the 2 dockerfiles into a single file and do some necessary modifications. Then you can build the image which will contain both Nodejs and Cassandra. But i cant guarantee you that it will work the way you want.
Another way is to spin up these containers using docker-compose. Its the best tool to run multi-container applications. Just go through docker documentation for more on docker compose.

Thanks.