0

There are existing resources on how to mount local directories inside of a docker container- but what I want to do is the opposite- I'd like to mount my Docker container on my local macOS machine (as I could do when I mount a USB drive) so that I can manipulate the files inside using Sublime Text.

Is this possible on OS X? If so- how to do it?

Maybe it can be achieved somehow with osxfx?

The following command will mount my local Desktop inside of my Docker container, which is the opposite of what I want — what I need is something along the lines of — my Docker container shows up on my local Desktop.

docker run -it -v ~/Desktop:/Desktop smatthewenglish/mico-botnet:aleph bash

The point is - editing files with nano or vim is really annoying - I want to edit files with my own version of Sublime Text, which is configured just the way I like it.

As I develop a Docker container- install different applications and configure the settings, etc. I want to do that in my preferred development environment which lives on my local machine.

halfer
  • 19,824
  • 17
  • 99
  • 186
smatthewenglish
  • 2,831
  • 4
  • 36
  • 72
  • There is no difference: in both cases you will have a directory shared between your OS and the container. If you start a container with a shared volume (e.g. /var/data on both side), you will see everything it will write inside the container /var/data, on your OS /var/data directory. The only different case I can image is if your container contains stored data before it starts... Am I wrong? – lifeisfoo Sep 06 '17 at 15:00
  • What I want to do is edit the files on my docker container inside of Sublime Text which lives on my local machine – smatthewenglish Sep 06 '17 at 15:04
  • Do you want to edit ALL files (from root /) of your container from your host OS? Or only a specific folder? – lifeisfoo Sep 06 '17 at 15:08
  • ideally I'd like to edit all the times from root – smatthewenglish Sep 06 '17 at 15:22
  • You should take a look at [this](https://stackoverflow.com/questions/16296753/can-you-run-gui-apps-in-a-docker-container) and [this](https://github.com/moby/moby/issues/8710) – lifeisfoo Sep 06 '17 at 15:34
  • [Cross-posted to Reddit](https://www.reddit.com/r/docker/comments/6yfxw9/how_to_mount_a_docker_container_locally_as_i/). – halfer Sep 08 '17 at 21:38

1 Answers1

2

That's not really how Docker works and not possible. You can't (not really but still) and (definitely) shouldn't edit files inside a container. You always mount a folder INTO a docker container, never FROM.

There's a few different possible scenarios:

  • You want to develop something: you mount the source folder inside a docker container and can edit locally
  • You want to publish something: with a Dockerfile you create a new image and copy your files inside the container

In the first case your container might provide a webserver or something like that (we work that way to host nginx + php in a container and our sources on the host). On the second case you want a self contained application to deploy on a server and all files needed should be inside the image.

Even if in some way you were able to edit files inside a running container, changes wouldn't be persisted unless you commit to a new image but that seems overly complicated and strange workflow.

hlidotbe
  • 888
  • 2
  • 9
  • 17
  • the thing is- editing files with nano or vim is really annoying- I want to edit files with Sublime Text, which is configured the way I like it- you know what I mean? So as I develop a docker container- install different applications and configure the settings, etc. I want to do that in my prefered development environment which lives on my local machine- you know what I mean? – smatthewenglish Sep 06 '17 at 15:24
  • Yes and as I said you don't edit files inside the container. You expose your local files into it if needed (during development) then build a new image and copy your files for deployment. – hlidotbe Sep 06 '17 at 15:26