Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker commit data container with VOLUME #6999

Closed
winggundamth opened this issue Jul 13, 2014 · 59 comments
Closed

docker commit data container with VOLUME #6999

winggundamth opened this issue Jul 13, 2014 · 59 comments
Labels
exp/expert kind/enhancement Enhancements are not bugs or new features but can improve usability or performance.

Comments

@winggundamth
Copy link

I'm not sure anyone has a way or requesting this but this is my use case.

I knew that there's a way to backup data container with --volumes-from, bind mount with host with tar as describe here. But it should be good if Docker have a way to commit data container to image with data in Volumes. So I can use it for snapshot/backup data and push/pull it to transfer data across server.

Use case example

Dockerfile

VOLUME /home/web/app/uploads

On host

docker run -d app
docker run -d --volumes-from app app-data
docker commit --with-volumes=true app-data app-backup:201407131628
docker push app-backup #this will push only diff

On dev or another host

docker pull app-backup:201407131628
docker run --with-volumes=true -d app-data
docker run -d --volumes-from app-data app

Do you have a plan for this feature or any work around to do snapshot on volume?
I know this will be very complicated but it will be the very nice to have feature for sure :)

@thaJeztah
Copy link
Member

+1 Volumes are useful in many cases, for example, for running database-storage. However, since volumes are not 'part' of a container, it makes containers no longer portable - which seems in direct conflict with the slogan Build once... Run anywhere...

@crosbymichael
Copy link
Contributor

+1 i need this @cpuguy83

@cpuguy83
Copy link
Member

@crosbymichael I thought about this, and potentially enabling it for all docker builds.
Currently a volume specified in a build creates an immutable directory.

@thaJeztah
Copy link
Member

I was thinking about this the other day; some things to take into account;

  • Should bind-mounted volumes also be considered 'volumes' in this case?
  • If so; how to exclude sockets etc.?
  • Should there be an option to exclude irrelevant volumes (temp/log volumes?)
  • Docker export should support this as well (docker export --with-volumes)
  • --snapshot may be a more generic name?

cpuguy83 added a commit to cpuguy83/docker that referenced this issue Jul 21, 2014
Fixes moby#6999

Docker-DCO-1.1-Signed-off-by: Brian Goff <cpuguy83@gmail.com> (github: cpuguy83)
@wasseem-redboxdigital
Copy link

+1 for the request by winggundamth
Now, can anyone update us if this request has been granted?

At the time of this writing, I have noticed that $ docker commit does not commit the data within the volume mounted (in the case of a data-only container).
And also the statement $docker commit --with-volumes=true is not there too.

It would be nice to have this request fulfilled in the case of a data-only container, it's much easier+faster to commit & run VS backup & restore.

@jessfraz jessfraz added kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. exp/expert labels Feb 26, 2015
@Georges0013
Copy link

there a proposal about it right here, but it's closed now : #8484

@kojiromike
Copy link
Contributor

+1 I take it the black-belt label means this is going to be harder than breaking boards with one's chin?

@ain
Copy link

ain commented Jun 22, 2015

👍

1 similar comment
@soupdiver
Copy link

+1

@thaJeztah
Copy link
Member

ping @icecrime @calavera wondering what the current position is on this proposal, also in light of the volume-drivers etc.

@Matvey-Kuk
Copy link

+1!!!

@crosbymichael
Copy link
Contributor

I think going forward the work on top level volume objects will replace data containers and allow more advanced management of volumes with things like export.

@cpuguy83 should have a PR somewhere or it is already merged in the experimental branch.

@cpuguy83
Copy link
Member

cpuguy83 commented Jul 8, 2015

#14242 for top-level volumes.

@jessfraz
Copy link
Contributor

Hello!
We are no longer accepting patches to the Dockerfile syntax as you can read about here: https://github.com/docker/docker/blob/master/ROADMAP.md#22-dockerfile-syntax

Mainly:

Allowing the Builder to be implemented as a separate utility consuming the Engine's API will open the door for many possibilities, such as offering alternate syntaxes or DSL for existing languages without cluttering the Engine's codebase

Then from there, patches/features like this can be re-thought. Hope you can understand.

@rakesh-james
Copy link

Is this Fixed ? Still need to work round? Any one please update...

@sbrennion
Copy link

I would also appreciate such a feature. Docker is flexible and there is not only one way to use it.
I want also being able to seperate the data in a volume, but perhaps at some point push the container with volume data in it , and deploy it

@moylop260
Copy link

👍

@NZhuravlev
Copy link

Hello!
We are no longer accepting patches to the Dockerfile syntax as you can read about here:
Then from there, patches/features like this can be re-thought. Hope you can understand.

Well.. why would you even mention Dockerfile syntax? The issue is about run command.

There is now direct answer to this issue, no merged PR, no opened PR, no info about why you can't do that, nothing.

@thaJeztah reopen this issue, maybe?

@omorillo
Copy link

👍

@cvrod
Copy link

cvrod commented Feb 27, 2017

+1

9 similar comments
@linshenqi
Copy link

+1

@ropnom
Copy link

ropnom commented Apr 12, 2017

+1

@paulz1
Copy link

paulz1 commented Apr 18, 2017

+1

@neocortical
Copy link

+1

@inlineHamed
Copy link

+1

@rikvermeer
Copy link

+1

@tabbi89
Copy link

tabbi89 commented Jun 9, 2017

+1

@eeezyy
Copy link

eeezyy commented Jul 18, 2017

+1

@blachawk
Copy link

+1

@lavvy
Copy link

lavvy commented Aug 14, 2017

+1. How else can we snapshot volumes

@pokapow
Copy link

pokapow commented Aug 28, 2017

+1

4 similar comments
@qinshulei
Copy link

+1

@evanfchan
Copy link

+1

@farokojil
Copy link

+1

@vguna
Copy link

vguna commented Sep 16, 2017

+1

@cdaringe
Copy link

woo wee, that took forever to figure out why my commits weren't "working" as expected.

@thaJeztah, or anyone else really, i am not necessarily seeking to commit a volume, but remove the volume declaration, and perhaps recreate it later?

for instance, couchdb ships with a VOLUME declared. my objective is to ship a container with some prebaked data in it, but i can't run any migrations and recommit them because of this volume.

if there is a recipe for the operation, i'd love to hear it.

@7c
Copy link

7c commented Oct 15, 2017

+1

@thaJeztah
Copy link
Member

While I commented to be "positive" on this issue in the past, I've since gotten more insight into the complexity and design problems this feature would bring, and implementing this as a feature would be very problematic.

A volume is really separate from a container that's using it; commiting that data into an image will unlikely be implemented. Let me first try to illustrate what's happening when using a volume;

If an image declares a VOLUME, or a --volume is used on docker run;

  • docker creates a volume (if a non-existing volume is specified)
  • if the volume is empty (and the nocopy option is not set), the data from the path inside the container (where the volume is mounted) is copied from the container to the volume.
  • the container is started, and the volume is mounted inside the container (masking the files that are there)

When commiting a container to an image, only changes to the container's filesystem are committed; because the volume is not part of that, those files are not committed. This is the intended behavior for most use-cases; volumes are designed to;

  • decouple data from the application (see bullets below)
  • persist data beyond the container's lifecyle; this allows you to replace/upgrade a container, reuse the volume from before upgrading, and continue working with the data that was there
  • similar; when deleting a container, your important data isn't lost (it's still in the volume)
  • volumes prevent the overhead that copy-on-write filesystems cause (volume data is not using a copy-on-write filesystem)

Complexity

Implementing this feature would introduce a lot of additional complexity;

  • Before the container is committed, it must be stopped, otherwise data may still be written to the volume. Not only does this stop the container itself, this will likely affect other containers depending on it.
  • The volume must be unmounted (this can cause a race condition; at this moment, the volume is no longer marked as "in use", thus can be deleted, for example when running docker volume prune)
  • The data from the volume must be copied back into the container (how to deal with the existing files? Should those be merged, deleted?)
  • Comitting a container now actually modifies the container; starting the container again after committing is effectively starting a different container than was stopped.
  • When starting, the volume has to be attached/mounted again.
  • Restarting a container leads to new ports to be assigned (in case of "random" published ports - -p 80 or -P)

What use-case would be resolved by this feature?

The main use-case mentioned in this thread is to be able to ship an image that contains (default) data to use at runtime. There's a number of ways to realize this;

  • As an example, the official MySQL image allows you to automatically intialize the database by providing scrips or SQL dumps in the docker-entrypoint-initdb.d directory (see the readme at https://hub.docker.com/_/mysql/). Other images offer this feature as well
  • Change the configuration of the software running inside the container to use a data-path outside of a path that's using a volume. At runtime, you can still use a volume through the -v or --mount flag.
  • Consider using a separate image containing just the data to put in the volume; you can use that image to populate the volume. The advantage of this approach is that the data is decoupled from the image (so it's easier to upgrade the software running, without having to update the data)

There are improvements to be made, for example: allow a VOLUME that was defined in a parent image to be unset; see #3465

With the information above, I think it'll be very unlikely this feature will get enough support among the maintainers to be implemented.

@gudge25
Copy link

gudge25 commented Jan 4, 2019

so is there a way to commit docker image with files from volumes?

@thaJeztah
Copy link
Member

No there isn't, other than copying the files out of the volume to another location in the container before committing

@eaglet3d
Copy link

These manual overview steps might work:
Let's say you have an image (i.e. source image), and volume that mounts to a specific directory for the containers of that image.

  1. Run a container 'WithVol' from the source image with the volume mounted.
  2. Exec to create tar file of the volume directory on the container 'WithVol'
  3. Copy the tar file locally
  4. Run a container 'NoVol' from the same source image without the volume mounted.
  5. Copy the tar file to the container 'NoVol'
  6. Exec to extract the tar file to the target directory on the container 'NoVol'
  7. Commit the container 'NoVol' to a target image
  8. Create a new container from the target image
  9. Exec to ls the files in the target directory on the new container
  10. Confirm that all of the files are there.

Let me know how you make out.

@hemangjoshi37a
Copy link

Is this already solved? Can we commit now with persistent data to a image?
Please help.

@lamba
Copy link

lamba commented Nov 8, 2020

Not solved. See the workaround described in the Jan 4, 2019 comment.

@sungaok
Copy link

sungaok commented Jul 24, 2023

+1, could provide this feature, and leave users to decide how to use it.

@sungaok
Copy link

sungaok commented Jul 24, 2023

could you provide me any idea, how to modify this feature in my own git code, I will try my own environment.
thks
@eaglet3d

@b4shtirk1n
Copy link

+1

1 similar comment
@CatIIIIIIII
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exp/expert kind/enhancement Enhancements are not bugs or new features but can improve usability or performance.
Projects
None yet
Development

No branches or pull requests