Want to know differences between commit and volume

Hello

I’m new to docker, i have a questions about commit and volume. Some changes i made saved by committing but not all some changes that i made should be saved by volume. I want to know when i should use volume and commit to save data that i made changes to.

Thank you

Never use docker commit.

Do learn how docker build works. Write a custom Dockerfile for your application.

Now, to answer your original question: think about the first time you start your application. What data do you absolutely need to be present for it to start? That should probably be “baked in” to your image: COPY it in the Dockerfile, and it will always be there. Now think about the second time you start your application. What data do you need to have not lost? That should be in volumes, possibly provided via the docker run -v option.

You should expect, and plan for, the container itself to be deleted. So if you:

docker build -t me/something .
docker run --name x -v /here:/there me/something
docker rm x
docker run --name x -v /here:/there me/something

everything should still work as you expect, and you shouldn’t have lost data.

Hi thanks for replying

I understood what you said then i got two questions
My first plan was to start with ubuntu images to build my server cause i want to use it as like a virtual machine to test a lot of things.
So my question is that docker is not an appropriate to use for my cases?
From your answer i felt docker should be used after finish server settings to launch easily is it right?
Another question is that then why apt-get install command is saved by commit command

Thank you