docker-compose

Jasmin shahrzad
Jasmin shahrzad used Ask the Experts™
on
is it possible to commit docker in docker-compose file?
what i want is when i say docker-compose stop want to commit before stop.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
nociSoftware Engineer
Distinguished Expert 2018

Commented:
Docker has no commit AFAIK.
So what do you mean with "commit" ... A database commit?  commit in some application?
if so waht DB / Application do you mean?

OTOH you may mean a way to stop applications "nicely" / "gracefully"
Then please read this blogpost: https://www.ctl.io/developers/blog/post/gracefully-stopping-docker-containers/

Which explains the shutdown in fair detail and how to use the pre warning you get with docker[-compose] stop to stop gracefully
(catching the SIGINT).
David FavorFractional CTO
Distinguished Expert 2018

Commented:
As noci asked, describe more clearly what you mean by "commit docker".

Also what you mean by "commit before stop", specifically state what you're trying to commit.

If you're talking about application data, then you simply do this...

docker stop <container-id/name>

Open in new window


Which will in turn run all the normal service shutdowns. In the case of MariaDB/MySQL, for example, the service will be do a normal shutdown flushing/committing all memory buffers to disk.
David FavorFractional CTO
Distinguished Expert 2018

Commented:
Note: If you have some custom application code you've written, then best you write a normal service management stub for your application.

This will likely be either systemd or OpenRC, depending on what Distro you use.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
i mean commit container. There are command docker commit "container" name.
if i create a change on container i want to commit (save statement) before i say docker-compose stop.
Software Engineer
Distinguished Expert 2018
Commented:
then make a script: mydocker-stop

#!/bin/bash

docker commit "$1" "$2"
docker stop "$1"

Open in new window


Usage:
mydocker-stop "containername"   "repo:tag"
Not sure why you want to store the new image...., [ which would be copy from the original ].
When generated from an compose file it will be the same any time when started from ...
You need to create a new docker container from the image to run the next time,

If your system crashes or the container stops without a commit you will loose any changes so somehow it doesn't look like a reliable method for "saving" information.
IMHO you'd be better off using lxc containers or full VM's (KVM, VirtualBox, VM-Ware)  for systems depending on persistence of  data.
Docker is better suited for data that may get lost, or stateless systems.

Author

Commented:
@noci,
my issue is when i stop docker-compose "container_name", i do not want to lose data from container.
fx. if i create user in my sftp container, how to be sure i do not lose what i did in container. i need to commit and save this step.
or am i wrong? of course it better to use LXC/D but not in case now.
nociSoftware Engineer
Distinguished Expert 2018

Commented:
All files in the container are stored on disk somewhere... as long as the container is not DELETED the data is kept.
you could provide virtual mounts ( -v ) then the data is stored in the context of the host.

the normal use should be to create an image (once).... (or upgrade it).
Then create a container from that image, use docker run / docker start / docker stop  to manage the container.
Upgrade is remove container (here can be loss of data) , and create a new one.
To propagate data with those upgrades one can use virtual mounts from within the container to the host filesystem.

(that way you will only loose data like when rebooting a  host. Where you don't neatly stop all programs... What is in ram buffers will be lost.)
David FavorFractional CTO
Distinguished Expert 2018
Commented:
You said, "my issue is when i stop docker-compose "container_name", i do not want to lose data from container."

As noci stated, with Docker, all persistent data lives outside the container... well... should live outside the container to persist... Docker has no concept of persistent data inside a container. All data lives outside the container + is accessed by -v (volumes)... as noci stated...

If you have many containers with persistent data, say LAMP Stacks running WordPress sites. Docker can be used for this + you'll end up wasting massive time managing external volumes... because you'll have to arrange to spin up one container to create the databases, then another container to access the databases, then you'll have yet another procedure to retire related volumes with containers are deleted.

This level of complexity and time thrash is fine for a single container. For 1000s of containers running across 100s of machines, you'll require an army of people to manage this.

With LXD, you spin up a container, install all your software, initialize your database + run your LAMP Stack.

Since all data lives inside the container, management operations like... moving a container to another machine or destroying the container become simple, because all management operations occur on one entity, the container.

With Docker, containers dependent on external volumes... all management operations (move/destroy) must occur on the container along with every related volume.

To me using LXD for persistent data containers if far easier to manage.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial