Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modifying a docker image

I have recently started working on docker. I have downloaded a docker image and I want to change it in a way so that I can copy a folder with its contents from my local into that image or may be edit any file in the image.

I thought if I can extract the image somehow, do the changes and then create one image. Not sure if it will work like that. I tried looking for options but couldn't find a promising solution to it.

The current Dockerfile for the image is somewhat like this:

FROM abc/def
MAINTAINER Humpty Dumpty <@hd>


RUN sudo apt-get install -y vim

ADD . /home/humpty-dumpty
WORKDIR /home/humpty-dumpty
RUN cd lib && make

CMD ["bash"]

Note:- I am looking for an easy and clean way to change the existing image only and not to create a new image with the changes.

like image 617
qwerty Avatar asked Apr 14 '17 16:04

qwerty


1 Answers

As an existing docker image cannot be changed what I did was that I created a dockerfile for a new docker image based on my original docker image for its contents and modified it to include test folder from local in the new image. This link was helpful Build your own image - Docker Documentation

FROM abc/def:latest

The above line in docker file tells Docker which image your image is based on. So, the contents from parent image are copied to new image

Finally, for including the test folder on local drive I added below command in my docker file

COPY test /home/humpty-dumpty/test

and the test folder was added in that new image.

Below is the dockerfile used to create the new image from the existing one.

FROM abc/def:latest

# Extras
RUN sudo apt-get install -y vim

# copies local folder into the image 
COPY test /home/humpty-dumpty/test

Update:- For editing a file in the running docker image, we can open that file using vim editor installed through the above docker file

vim <filename>

Now, the vim commands can be used to edit and save the file.

like image 147
qwerty Avatar answered Sep 30 '22 07:09

qwerty