0

I successfully retrieved an image called k8s.gcr.io/guestbook:v3 from a public repository and ran it as a container on a local Windows devbox using Docker Toolbox. (I have to use Docker Toolbox because the devbox in question does not meet the pre-requisites for installing Docker for Windows)

What specific commands do I need to type in order to locate and open the files that were used to create the image?

I want to examine the code for the app that is inside the container, then make a few changes here and there, then run the revised image as a container to see the revised code in action. But I cannot very well do that if I cannot first access the code.


Downloading The Image and Running The Container

The following are the steps I took to retrieve and validate the container/image:

User@pc MINGW64 /c/Program Files/Docker Toolbox  
$ docker run -d -p 3000:3000 k8s.gcr.io/guestbook:v3  
Unable to find image 'k8s.gcr.io/guestbook:v3' locally
v3: Pulling from guestbook  
a3ed95caeb02: Pull complete  
300273678d06: Pull complete  
de2a362ef050: Pull complete  
06d5067149bd: Pull complete  
7a38a4e8f983: Pull complete  
10af2c65b7d4: Pull complete  
Digest: sha256:8f333d5b72677d216b4eb046d655aef7be9f1380e06ca1c63dfa9564034e7e26  
Status: Downloaded newer image for k8s.gcr.io/guestbook:v3
953785bda17b0396fa3f3812a9b8ad8e2038120336895dfe1d57343adb917cce

User@pc MINGW64 /c/Program Files/Docker Toolbox
$ curl $(docker-machine ip default):3000
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <meta charset="utf-8">
    <meta content="width=device-width" name="viewport">
    <link href="style.css" rel="stylesheet">
    <title>Guestbook</title>
  </head>
  <body>
    <div id="header">
      <h1>Guestbook</h1>
    </div>

    <div id="guestbook-entries">
      <p>Waiting for database connection...</p>
    </div>

    <div>
      <form id="guestbook-form">
        <input autocomplete="off" id="guestbook-entry-content" type="text">
        <a href="#" id="guestbook-submit">Submit</a>
      </form>
    </div>

    <div>
      <p><h2 id="guestbook-host-address"></h2></p>
      <p><a href="env">/env</a>
      <a href="info">/info</a></p>
    </div>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="script.js"></script>
  </body>
</html>

User@pc MINGW64 /c/Program Files/Docker Toolbox
$
CodeMed
  • 9,527
  • 70
  • 212
  • 364
  • Possible duplicate of [How to generate a Dockerfile from an image?](https://stackoverflow.com/questions/19104847/how-to-generate-a-dockerfile-from-an-image) – David Maze Jul 10 '18 at 02:34

1 Answers1

0

one can "apply Dockerfile instruction to the created image" with docker commit.

here it's explained, what you might want to do: https://www.techrepublic.com/article/how-to-commit-changes-to-a-docker-image/ nevertheless, editing the Dockerfile and building the container might be the better approach; see https://docs.docker.com/compose/gettingstarted/

Community
  • 1
  • 1
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • The recommended way to answer is to list the steps of the solution in your answer and then include the links only as supporting materials. The reason for this is that links change. If all you do is post links as you do here, then this answer will be worthless to future users when the underlying links change. – CodeMed Jul 10 '18 at 00:43
  • @CodeMed there's still `docker --help` & `docker-compose --help` ...while I won't support questionable approaches with copy & paste tutorials. it is not that it's "not possible", it just circumvents the whole idea of containerization (unless wanting to reverse engineer one container). – Martin Zeitler Jul 10 '18 at 00:51
  • `docker --help` does not give a command for extracting the `Dockerfile`. And your links are similarly nebulous. Opening a shell into the running container mentioned in one of your links is only marginally helpful as an idea. Please be more specific and thereby increase the quality of this answer. – CodeMed Jul 10 '18 at 00:53
  • https://stackoverflow.com/questions/19104847/how-to-generate-a-dockerfile-from-an-image ... `docker history --no-trunc` is the closest one can get (this is not the actual `Dockerfile`); else one can find them on GitHub, when publicly available. – Martin Zeitler Jul 10 '18 at 00:57
  • for example https://github.com/kubernetes/examples/tree/master/guestbook – Martin Zeitler Jul 10 '18 at 01:06
  • I am marking this as the answer because you 1 pointed out that it is not possible to simply decompile the image and 2 you found the github source for the specific app i am working with. However, your answer is so poorly written that this will not help anyone else in the future. All you have are disorganized links to content that will change later as time goes by. Another reader would have to invest a lot of time piecing together what you are trying to say here, even if the content in the links is still there at the time when a ready finds this. For these reasons I am NOT giving +1 – CodeMed Jul 13 '18 at 22:31
  • I could have simply answered "not possible" ...while the link to GitHub was a mere guess (within the results which Google turned up); they still enable you to do exactly what you were asking for. – Martin Zeitler Jul 15 '18 at 01:02