Archive for June, 2021

Map a Docker volume to a Windows network path

June 24, 2021

If you have an API that makes use of Windows file system and is running inside a Linux container then you need to find a way to access the Windows file system.

The solution for this problem was to create a volume that was attached to the service. This volume was pointing to the shared network path (like in the picture below):

Other options are:

  • Bind mounts (dependent on the folder structure and OS of the host machine)
  • tmpfs mounts (in memory)

Volumes are usually the preferred way to persist data that is generated by and used by Docker containers.

Other advantages of using volumes:

  • can be migrated and backed-up very easily
  • can be managed using CLI commands or the Docker API
  • can work on both Linux and Windows containers

Steps to do that:

  1. Update the docker-compose.yml file to declare a volume:

The volume is using CIFS (Common Internet File System) which is a filesystem protocol used for shared access to files and printers between machines on the network.

2. Attach the volume to the API:

2. Update the .env file with the needed variables.

STORAGE_DISK_PATH=//hostname/Labels

STORAGE_USERNAME=your_username

STORAGE_PASSWORD=your_password

STORAGE_FILE_MODE=0777

STORAGE_DIR_MODE=0777

When you run the API you should see the /data folder being mapped to the Windows network path.