Link to home
Start Free TrialLog in
Avatar of Jasmin shahrzad
Jasmin shahrzad

asked on

docker-compose

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.
Avatar of noci
noci

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).
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.
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.
Avatar of Jasmin shahrzad

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of noci
noci

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@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.
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.)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial