Docker Service Mount Host Machine Directory Not Work

I work on a Spring Boot project that connects to remote machine and save files to the machine in a directory. Project works well when running project locally. The project code related to saving files:

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.springframework.web.multipart.MultipartFile;

public static final Path ROOT = Paths.get(“\\IP_ADDRESS\Upload\files”);

private static void saveFileToFileSystem(MultipartFile file, String fileName) throws IOException {

Runtime.getRuntime().exec("net use \"\\\\"+IP_ADDRESS+"\" "+USER_PASSWORD+" /user:"+USER_NAME);

Files.copy(file.getInputStream(), ROOT.resolve(fileName));

Runtime.getRuntime().exec("net use \"\\\\"+IP_ADDRESS+"\" /delete");

}

The Dockerfile of the project is below:

FROM openjdk:22-slim-bullseye
ADD target/project.name.jar project.name.jar
ENTRYPOINT [“java”,“-jar”,“/project.name.jar”]

I create Docker service to deploy project on the remote machine, namely Docker service host machine as shown below in PowerShell. However, the service cannot access the host machine file system.

docker service create --name project-service
–replicas 2 --publish mode=host,target=8080,published=9100,protocol=tcp project_image:1.0

Then I try to mount the directory with running the code below in PowerShell.

docker service create --mount type=volume,source=“//e/Upload”,destination=“/home” --name project-service
–replicas 2 --publish mode=host,target=8080,published=9100,protocol=tcp project_image:1.0

But I get the error below:

invalid mount target, must be an absolute path: /home

How to solve the problem?

I think you are using volume to do a bind mount. Try

--mount type=bind,source=C:/temp,target=/tmp 

You seem to expose a port, but using 2 replicas.