A client wants a docker app delivered. I have two questions regarding best practices.
First, I need to deliver an app with tomcat, a webapp, a database, and some tables. I understand how to set up tomcat and the database, but what do you do with their assets (ie webapp and tables)? Do you include them in the image and then push this to hub.docker.com? If the webapp and database tables are proprietary, how do you deal with that? Do you create a private image and share it somehow?
Second, as the app runs, the database tables may change. As I understand it (and tested), docker containers are stateless so once it's stopped, the data is reset. How do you maintain the same state between restarts? I know you can map folders between the container and host, but do I really ship a separate database folder containing the data and have the docker container map it? What's the best practice here?
Thanks in advance
Edit First of all, thank you to everyone who replied back. Both @RicardoBranco and @kstromeiraos have good suggestions for how to distribute the image. I don't know which the client prefers yet and while I'd like to award both of you the checkmark, SO only allows me to award one answer. So I've upvoted you both and will let the internet decide which answer prevails in the long run.
Second, I'm an idiot. I was using the "docker run" command to "start" my container, which I now realize is creating a new container, making me believe that I had lost all my data from the previous session. It was only after I realized that you should be calling "docker start" to "start" a container that I noticed my mistake in understanding.
Thank you all
You have two options to distribute the images.
As @Ricardo Branco said, use a private registry.
Use docker save
to save images to tar files and then, share that with your client whom can use them by loading them using docker load
(https://docs.docker.com/engine/reference/commandline/save/).
You should have a volume in which your DB data persists. You can map a host directory.
To backup volumes, take a look to this useful tool which allows you to do that. https://github.com/discordianfish/docker-backup
https://docs.docker.com/registry/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With