skip to Main Content

I want to edit the source code in docker containers, but I don’t know where the source code files are stored in my computer (I use docker desktop on windows 11)

How to find source code file

2

Answers


  1. Container file systems are not persistent, therefore, there is no user facing location of where it’s files lay.

    However, what you can do is docker exec into the container and edit the files from there.

    Additionally, you can "bind mount" a directory which pretty much means that a directory or file on your host is "symlinked" to a specific directory or file in the container. Do note however that this will overwrite that directory in your container, a hacky solution would be to first copy out the source to your directory and then mount that folder in.

    Login or Signup to reply.
  2. The source code is not necessarily in the image and you should not look for it there. Even if it is, do not try to edit the source code in the container. Look for it somewhere like GitHub, or by contacting the original author.

    A well-built Docker image will contain the minimum necessary to run its application. That frequently doesn’t include any sort of text editor at all; you may have access to ed or a minimal version of vi, especially on an Alpine-based image, but not any sort of richer IDE. Also, the container filesystem is intrinsically temporary, so anything you do change in the container will be lost.

    Let’s hypothesize that your image is written in an interpreted language (Javascript, Python, Ruby, …) and you’ve used docker exec to get a debugging shell inside the container. You apt-get update && apt-get install vim-tiny to get some sort of editor, and start editing files. Then you discover that you need to change something, maybe publish an additional port to access a debugger. This requires deleting and recreating the container, at which point you’ve lost the local file changes and the editor; you need to start over completely.

    It’s also very possible that the source code simply isn’t in the image. Using a compiled language (C++, Go, Rust, Java, Elixir, …) an image will generally contain the compiled binary and any libraries or language runtimes needed to run the application, but not the source code. It’s even possible that the image contains only the compiled binary and absolutely nothing else, not even a standard Bourne shell that docker exec could run. This approach will give you a very small image that’s fast to start up, and (usually considered a benefit!) it does not include the source code in the image at all.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search