Reputation: 35
I may have not followed best practices, I believe, and I am kinda trying to correct myself
I have created a container starting from the Rust docker image for a project. I have been using this container more like a small VM rather than a container. Through the docker dashboard I start it every morning and work on it, either by docker -it exec my-container bash
or using docker exec
from scripts.
Since I created it from the Rust image, I have added users, installed crates and packages etc.
Is there a way to create a Dockerfile from an existing docker container, that will contain all this, so I can use it to create ephemeral copies of this container to run specific jobs?
Upvotes: 1
Views: 15041
Reputation: 3611
docker export [OPTIONS] CONTAINER
It'll export a container’s filesystem as a tar archive.
Note: The docker export
command does not export the contents of volumes associated with the container. If a volume is mounted on top of an existing directory in the container, docker export will export the contents of the underlying directory, not the contents of the volume.
sudo docker ps -aqf "name=containername"
or docker inspect --format="{{.Id}}" container_name
$ docker export CONTAINERID > <your_exported_image>.tar
$ docker import <your_exported_image>.tar your-new-image:latest
$ docker commit CONTAINERID your-new-image:latest
Upvotes: 0
Reputation: 1020
No, you can't. Since Docker doesn't keep track of your executed commands in interactive mode, it cannot generate a Dockerfile with your history. What you can do, though, is use docker commit
to save your changes as an image, or docker export
to save your container as a tarball which can be later transformed in an image with the docker import
command. The whole process follows:
CONTAINER ID
from the container you wish to export with the docker ps
command.$ docker export CONTAINERID > img.tar
$ docker import img.tar my-new-image:latest
$ docker commit CONTAINERID my-new-image:latest
Upvotes: 9