Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker - cannot move file between volumes from java

I have two docker containers: producer and consumer.

Consumer container has two volumes:

VOLUME      ["/opt/queue/in", "/opt/queue/out"]

docker-compose.yml

consumer:
    image: consumer
producer:
    image: producer
    volumes_from:
    - consumer

Producer puts file in /opt/queue/in directory and consumer reads file from that dir and moves it to the /opt/queue/out. The problem is that consumer is written in Java and following Java code returns -1 (operation failed).

new File('/opt/queue/in/in_file').renameTo(new File('/opt/queue/in/in_file'));

When I try to move file from command line there is no error. File is moved correctly. Why this is happening? How can I diagnose what is the problem?

like image 943
lbednaszynski Avatar asked Mar 11 '23 07:03

lbednaszynski


1 Answers

The javadoc for File.renameTo specifically says that it may not be able to move a file between different volumes, and that you should use Files.move if you need to support this case in a platform independent way.

like image 121
Ian Roberts Avatar answered Mar 20 '23 00:03

Ian Roberts