Using SMB Volumes with Windows Apps
search cancel

Using SMB Volumes with Windows Apps

book

Article ID: 297687

calendar_today

Updated On:

Products

VMware Tanzu Application Service for VMs

Issue/Introduction

This article explains the steps to mount a SMB volume for your applications for PAS.

Environment


Cause

Starting in PAS for Windows 2.3.5+ or 2.4.0+, you can mount Server Message Block (SMB) volumes into the application container. However, this is not done automatically by the platform and it requires a bit of manual work.

Resolution

The following steps can be used to mount a SMB share into an existing container.

1. Push your application without any SMB volumes mounted. When it starts, cf ssh into the app.

2. Run net use to list attached shares. You should see none.

3. Run net use \\<ip>\<share> /u:<user> <pass>, where <ip> is the IP of your SMB server, <share> is the name of the volume being shared, and <user> or <pass> are the credentials for the volume.

For example: 
net use \\10.10.10.10\public /u:myuser hackm3
4. Run net use again. You should now see your SMB volume mounted. Please note that you must use an IP address and not a DNS name. This is a limitation in the current implementation which will likely go away in a future release.

IMPORTANT NOTE: If your application needs the SMB volume to be mounted when the application starts or you would like to automate the process, please follow these additional steps:

6. Create a .profile.bat script at the root of your application. This should be the directory from which you are running cf push or the directory you set with the cf push -p argument.

7. In the script, add the following:
timeout 2
net use \\<ip>\<share> /u:<user> <pass>
8. Save the file & push your application. The .profile.bat script should run prior to your application and mount the volume.


Additional Information

  • The example script above has timeout 2 as the first command. This is sometimes necessary as there is a race which can cause the mount to fail. This happens if the network stack in the container is not up before the command to mount the SMB volume runs. To remove this race condition, you can just have the script sleep for a short period of time (two seconds).
  • If timeout 2 does not work for some reason, you can use the command powershell "Start-Sleep -s 2" instead.
  • If net use is not working, you can try `powershell "New-SmbMapping"`. See the docs for details on the arguments required for this command. 
  • PASW still supports using Steeltoe & the options documented in the .NET Cookbook here. If you'd prefer to use this method, that is perfectly acceptable and will continue to be supported.
  • This is not supported in PAS for Windows or Windows 2012R2.