Reputation: 1417
I am currently looking at Docker to see what it can do for me. The use case I have is a test/dev server that will run for example Tomcat & My-SQL. What I don't understand is what is the best way to set this up?
Do I create one image for TomCat and another for MySQl? Or do I put them both in the same image?
If it is separate images, should they be separate containers?
Upvotes: 1
Views: 148
Reputation: 81
It is recommended to isolate the database and web server to their own containers or simulate how your architecture is going to look like in prod, which would probably be separate containers for the web and the db.
Key points to research/learn if you choose separate containers:
I hope this helps. Have a good day.
Upvotes: 1
Reputation: 897
Preferred way is to use official images from Docker Hub. MySQL https://hub.docker.com//mysql/ Tomcat https://hub.docker.com//tomcat/
Then, if you want to persist data in MySQL for long time, you would need another "data container" to store MySQL data. Otherwise, every time you recreate MySQL container you will lose all databases.
You can start MySQL container as easy as
docker run -d --name mysql -e MYSQL_ROOT_PASSWORD=[put your password] mysql
and Tomcat container as easy as
docker run -d -p 8888:8080 --link mysql:mysql tomcat:8.0
Then you can refer to your mysql server from within tomcat application simply as mysql (this hostname will resolve to proper IP)
Upvotes: 1
Reputation: 1212
Yes, make use of pre-existing images for each application. You can get "official" ones from Docker Hub.
If you have the ability, simply install a virtual machine with the Linux flavour of your choice. Choose the appropriate Docker package for that flavour.
Then have a browse on Docker Hub for images you may find useful, follow their instructions to get going and you're off!
Dive into the docs - maybe go and get a few (e)books.
Invariably, you will start with something like
docker pull <image>
docker run <options> <image>
<image>
is the Docker image you get from the Hub - mySQL and Tomcat in your case.
<options>
are varied and will depend on what you want to do and you'll be experimenting.
A concrete example for your case:
docker pull mysql
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
docker pull tomcat:8.0
docker run -it --name tomcat --link some-mysql:mysql -p 8888:8080 tomcat:8.0
This will start up mySQL and then Tomcat, while linking those two containers together. Just to show you what can be done.
Note, when downloading a new image from the Hub, you don't have to run docker pull
first. I generally do to have more control over the image tag/version.
Upvotes: 1