简体   繁体   中英

How can I map a shared folder from my container on Mac?

I have a folder insider a Docker container that is shared through Samba. I can map this folder on Windows without problem running something like:

net use z: \\vm_ip\folder

In the case above, z: is the drive that I created with the content from the shared folder.

How could I map that same folder on Mac?

Step 1 - Sharing folder using Samba

The first thing that you need to do is let the folder that contains the files (project, source codes, settings, etc) that you want to share, visible for MacOS.

To do that, you'll need to share the folder on Docker Container using Samba. I won't describe how to do this here because there are a lot of resources on Internet.

Step 2 - Redirecting the Samba ports on Kitematic

Kitematic is a platform that helps you to configure the container and other settings on Docker. It can be downloaded here: https://www.docker.com/products/docker-toolbox . You DON'T need Kitematic to create the rules to redirect the Samba ports, however, you won't spend 2 minutes for that (instead trying to discover how to do that in the CLI).

Having Kitematic installed on MacOS:

Start Kitematic; Select the container (panel on left with the title Container) that contains the folder that you shared using Samba; Image of Panel on Docker

Click on the Settings tab and then the select the tab below called Hostname/Ports Image of Settings panel on Docker

Now, we add the ports 137, 138, 139 and 445 and redirects it to the same port on localhost.

Step 3 - Mounting the Samba shared folder on MacOS

The last thing that is needed to edit your files on MacOS,is just map on MacOS the folder that is shared on Samba (inside the Docker container). To map that, open the terminal and run the following command:

$ mount_smbfs //guest@localhost:/SharedFolderOnSamba source/

What we're doing is using the method mount_smbfs, telling that we'll connect to the @localhost in the folder SharedFolderOnSamba using the user guest and then, we'll map (create a new Drive) in the source/ folder on the currenct directory of you terminal session on MacOS.

So, pay attention:

You can use any other user to use instead guest; You must have a source/ folder or define another folder that will be used; The SharedFolderOnSamba must be change to the name of the folder that you've shared using Samba. To confirm the name of the folder, go to /etc/samba/ and open smb.conf and search by the folder that you've shared.

If you are using Docker For Mac, the /Users folder from your mac is already mounted inside the virtual machine inside the Docker For Mac application runs. It is accessible via /Users inside the vm. That means you can do: docker run -v /Users/some/path:/folder ... in the container's /folder will meant to /Users/some/path in the vm, which maps back to your mac's /Users/some/path.

If you want some other location other than /Users, click on the whale icon at the top of your screen, choose Preferences, and then click on the File Sharing tab. If you have mounted a samba/cifs share somewhere on your mac, you can add that path here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM