Search code examples
dockerdocker-machineboot2docker

Extract and change code from image using Docker Toolbox


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
$

Solution

  • 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/