Docker Community Forums

Share and learn in the Docker community.

Running an existing database (in a CentOS VM) as a Docker container

build
docker
virtualbox

(Nicketuttarwar) #1

Hey folks, I’ve got to find a way of translating my database which is housed in a CentOS vm with oracle EE and tomcat to Docker. Essentially I need a container which I can make API calls to.

Now I know that the 2 ways to tackle this are by:

  1. Creating my own Docker image with a CentOS base, and oracle, java, tomcat, etc on top
  2. Moving over the entire VM in a Docker image and maintain the same functionalities.

I’m really stuck because I looked at Rancher, and VBox images which just didn’t let me open up my .vmx file (p.s. They only let me use existing vm images). Another issue was that I couldn’t find a good base image which had normal cli functionality like sudo/yum/rpm.

Any recommendations or images that I should use to get this task done? I could really use the help!


(David Maze) #2

Based only on this description, I’d approach this by:

  1. Find a prebuilt Oracle container (this one seems to be popular).
  2. Somehow copy the data from your existing database into the container (maybe there’s a data directory you can copy; maybe you need to create and restore a dump).
  3. Find a prebuilt Tomcat container (like this official one).
  4. Write a Dockerfile that starts FROM tomcat:8.5, COPY your application into it, and configures it (probably to talk to the database on a fixed hostname); docker build it
  5. Write a Docker Compose file that starts both pieces, making sure to start the database as the name the application expects

General Docker best practice is to run only one thing in a container and to connect together multiple containers. In your case, this helps reusability: none of my steps above started with “install Oracle”.

In particular trying to directly translate a VM into a Docker container tends to not be recommended. For it to work at all you frequently need to give up all of the host/container isolation, and things like network setup are really different between a container and a VM. If you have an existing VM, probably just running it as-is is both easier and better than trying to directly run the same filesystem image under Docker.


(Nicketuttarwar) #3

Thanks David. I’m using that image with an oracle Java image on top of it.
I think this is going to work. Thanks a ton man!