guettli
guettli

Reputation: 27806

Create Dockerfile interactive?

If you look at dockerfiles the often contains lines like this:

sed 's/main$/main universe/' -i /etc/apt/sources.list

I think it is difficult to set up things like this.

Is it possible to launch a default OS image, then enter it interactive with a shell, do some modifications, and then print out the diff (filesystem diff)?

The diff should be used as the dockerfile to recreating the image.

But maybe I am missing something, since I am new to docker.

Upvotes: 1

Views: 2750

Answers (3)

Abel Muiño
Abel Muiño

Reputation: 7761

If you do not want to run sed (which is used to preserve the default file and of minimal changes to it), you can simply ADD the modifies file.

For that you can docker run -it --rm thebaseimage /bin/sh (or any other shell that is provided) and edit it in place. Then just copy it outside the container (or docker export it) and use it on your build.

The downside of ADD vs RUN sed… is that, if something changes in a new version of your base image, you will overwrite those changes.

Upvotes: 1

xeor
xeor

Reputation: 5455

You can create docker images several ways.

I tend to have two windows open when I create a new docker image. One for my docker run -i -t centos bash, where I am writing all my commands to get it the way I want, and the other one with the Dockerfile, so I can put in whatever I do. When it comes to config files, I am putting them in the files/folders that matches the one on the image.

Example, if I change /etc/something/file.conf, I will create the file in etc/something/file.conf in the same directory as my Dockerfile, and then use Dockers ADD command to add it whenever I do a build.

This works perfectly, since I can have all this in a git repository with a README.md containing the info I need for running/building the image.


The other thing you can do is to is to run docker ps -a after you are done with the changes you wanted to create an image on, and get the docker ID of the image of the container you just configured. You can tag this new image, or start it with docker run abc0123 bash just like you would a normal docker image.

The problem with this is that you wont be able to easily build it next time without bringing the whole image.

Dockerfiles with ADD is the way to go!

Upvotes: 5

Andy
Andy

Reputation: 38187

The Dockerfile is (mostly) equivalent to a series of docker run and docker commit commands. You wouldn't want to look at the docker diff to see what files changed -- you'd want to see what docker run commands had occurred. You could get these from your host shell history and process these into a Dockerfile.

Upvotes: 0

Related Questions