I run a container and, say, install vim. I exit out of the container. I would then like to re-run the container and have still have vim installed.
Is there a way to do this, because every time I restart a container vim is never there.
I run a container and, say, install vim. I exit out of the container. I would then like to re-run the container and have still have vim installed.
Is there a way to do this, because every time I restart a container vim is never there.
In Docker there are images and containers . When ever you
docker run
something, the something is an original copy and that is the image and is unmodified no matter what happens in the container. The copy running in the container acquires a new layer in the container's filesystem that isolates any changes to that one container.You can use
docker commit <containerid> <imagename>
to save changes from the temporary container to a new permanent image.However, for reproduction and documentation purposes it is better to do builds from a Dockerfile.
Here are the docs for docker commit.
You should build this container from a Dockerfile. So something like
That way the containers you run from this image have vim.
EDIT 1
Additionally, you can commit your container to an image, that way the current state of that container is saved to an image that you can spawn additional containers with the same state.
They are still there. when you run
You should see all of them, some of them are not in running status, but in exited status.
There are two ways to re-use the same container. For example,
List all containers with
docker ps -a
run with
docker exec
You should be fine to login and run vim if you installed it before.
run with
docker attach
, if the container start with bash