With the development of Docker, deploying web applications with tons of dependencies has been greatly simplified.
What previously would be a day-long process installing the various application components (e.g. database, web server, OS, etc) could now be simplifed to minutes.
For myself, I typically have a complete development environment inside Docker so that if I ever need to switch machines, I can simply export / import.
In the past, I would do web development and modify files inside the container using command line utilities such as vi. This was no problem, as I could open a shell inside the container directly.
However, I recently started development using graphical editors (such as VSCODE) on the host, which required the mounting of docker container filesystem on the host.
I was a bit surprised that there was not a really straightforward way to do this.
There is a way to mount host filesystem onto the container (guest) but no vice-versa.
With that, here's the way I was able to do so using samba.
Installing Samba into a Docker container (the example here is using Rocky 9 Docker GUEST running on MacOS HOST)
In this example, we have following Docker image:
REPOSITORY TAG IMAGE ID CREATED SIZE
rocky 9 xxxxxxx 3 weeks ago 28.2GB
$ docker container run -d -it -p 22:22 -p 80:80 -p 443:443 -p 443:443 -p 1521:1521 -p 137:137 -p 138:139 -p 139:139 -p 445:445 --name no-reservations rocky:9 /bin/bash
docker container start no-reservations
$ docker exec -it no-reservations /bin/bash
Note: The following commands are run inside the docker container:
# yum install samba samba-common -y
/etc/samba/smb.conf
Go to the bottom of the file and add the directory of the container which want to share back to the host:
[htdocs]
path = /usr/local/apache2/htdocs
writable = yes
browseable = yes
guest ok = no
create mask = 0755
# useradd svc_client
chown -R svc_client /usr/local/apache2/htdocs
smbpass -a svc_client
# /usr/sbin/nmbd -D
# /usr/sbin/smbd -D
At this point, you should be done with the setup of Samba under the container:
If you are on windows:
You should now be able to map the container share on the host by going to Map Network Drive->\\127.0.0.1\htdocs
If you are on a Mac
:
MacOS does not seem to allow drive mounts from 127.0.0.1, so you will need to create another loopback interface. Run the following command on the host.
$ sudo ifconfig lo0 127.0.0.2 alias up
You can them mount the share by Go->Connect to Server->smb://127.0.0.2/htdocs
In both cases, you will prompted for a login:
Enter svc_client and the password you set using the smbpasswd command;