1

I am new to docker and I have pulled docker image PredictionIO, I need to edit a file in it and re-run but I can't. docker image is not in my directories, too. how can I save the image to my host and edit it?

I use Ubuntu 17.04

thank you :)

MMRA
  • 337
  • 1
  • 3
  • 11

1 Answers1

3

There are 3 approaches to your problem:

  1. Get the Dockerfile and edit it, then build the image yourself.
  2. Run a container from the pulled image.

    Then docker exec -it into it and do your modifications.

    After that use docker commit <container id> repository/imagename:tag.

  3. Use bind mounts to map the file to a host directory and edit the file, this way you dont even need to modify the image.

    In order to do this, you need to specify the mount when creating the container:

    mkdir /path/to/host/config/folder
    

    create the required file(s) and then create the container:

    docker run -d --name mycontainer -v /path/to/host/config/folder:/path/to/container/config/folder/ <repository>/<image>:<tag> <command>
    

    Please note the -v switch. After this when you exec into container and navigate to /path/to/container/config/folder/ you will see the contents of the /path/to/container/config/folder/.

Farhad Farahi
  • 35,528
  • 7
  • 73
  • 70
  • I prefer to use 3, how can I do that? – MMRA Dec 03 '17 at 09:56
  • I think there should be an image name in command too because I get this error => "docker run" requires at least 1 argument. – MMRA Dec 03 '17 at 10:36
  • @Mahshid thats right, Its just a sample, Edited the answer for more clarity. feel free to add other switches required as well. – Farhad Farahi Dec 03 '17 at 10:38
  • now I have an empty folder, why is it empty? I replace "mycontainer" in command with my folder name in which I wanted to have the image. "/path/to/host/config/folder" is replaced with my folder path ,"/path/to/container/config/folder/" replaced with the folder name in my image – MMRA Dec 03 '17 at 10:43
  • Thats because your host folder is empty, its mounted on top of config folder in container, create another container without the bind mount, use `docker cp :/path/to/container/config/folder/ /path/to/host/config/folder` to prepopulate the files, then edit them and fire up the new container with the `-v` switch – Farhad Farahi Dec 03 '17 at 10:45