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.

  • Passing bash code through the environment (for docker-compose)
  • Limitations of Docker Ambassador? Syslog on other Docker machine filling up quickly
  • Push docker image to amazon ecs repository
  • How to use ebtables inside Docker?
  • docker boto3 AWS was not able to validate the provided access credentials
  • Boot2Docker doesn't recognize “sudo”, “tce-load”
  • How could I map that same folder on Mac?

  • How to use env attribute of Vagrant Docker provider?
  • How to allow users to run (but not manage) docker containers?
  • Dokku and log management
  • Docker: how to see output/error of CMD [ “python”, “./some_python.py” ]
  • Curl command to install docker-machine and/or docker-compose does not work in Ubuntu Xenial
  • docker native networking vs weave net/flux/show
  • 2 Solutions collect form web for “How can I map a shared folder from my container 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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.