[带有Docker-compose的Java]:java.io.FileNotFoundException:/var/lib/data/17.txt(无此类文件或目录)

时间:2020-01-18 01:06:39

标签: java docker file docker-compose

我的使用docker-compose的Java应用程序在Linux中找不到根路径。我想卷的路径有问题。你能帮我吗?

Cannot save user's book: java.io.IOException: java.io.FileNotFoundException: /var/lib/data/17.txt (No such file or directory)

方法:

@Override
    public ResponseEntity saveBook(MultipartFile file, String filename) {
        try {
            file.transferTo(new File("/var/lib/data/" + fileName));
        } catch (IOException e) {
            throw new LibraryException("Cannot save user's book: " + e);
        }

        return ResponseEntity.ok().build();
    }

Docker-compose:

version: '3.1'

volumes:
  mysql-data:
    driver: local
  mysql-log:
    driver: local
  mysql-conf:
    driver: local
  postgres_data:
    driver: local

services:
  dictionary_app_prod:
    container_name: dictionary_app_prod
    build:
      context: .
      dockerfile: Dockerfile
    restart: always
    ports:
      - 8888:8082
    volumes:
      - /var/lib/data:/var/lib/data

1 个答案:

答案 0 :(得分:0)

- /var/lib/data:/var/lib/data

在读取的行上方,从主机绝对/var/lib/data路径装载到容器/var/lib/data的路径检查是否正确

您可以在docker-compose中了解有关主机安装的更多信息 details