JAVA client connection to hdfs deployed on docker

  docker, question

Hdfs application has been successfully deployed on docker, and jps command also shows that namenode and datanode start normally. The browser displays the host IP: 50070 page
I use java to connect hdfs in eclipse with the following code:

FileSystem hdfs;
 Configuration conf = new Configuration();
 try {
 hdfs = FileSystem.get(new URI("hdfs://"),conf);
 Path des =new Path("E:/AB4/hdfs/worksapce");
 String srcPath = "/abcloud";
 Path src = new Path(srcPath);
 hdfs.copyFromLocalFile(false,true,des, src);

Running results:

org.apache.hadoop.ipc.RemoteException( File /abcloud/test.txt could only be replicated to 0 nodes instead of minReplication (=1)  .  There are 1 datanode(s) running and 1 node(s) are excluded in this operation.
 at org.apache.hadoop.hdfs.server.blockmanagement.BlockManager.chooseTarget4NewBlock(
 at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getAdditionalBlock(
 at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.addBlock(
 at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.addBlock(
 at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(
 at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$
 at org.apache.hadoop.ipc.RPC$
 at org.apache.hadoop.ipc.Server$Handler$
 at org.apache.hadoop.ipc.Server$Handler$
 at Method)
 at org.apache.hadoop.ipc.Server$
 at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(
 at com.sun.proxy.$Proxy7.addBlock(Unknown Source)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at com.sun.proxy.$Proxy7.addBlock(Unknown Source)
 at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.addBlock(
 at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.locateFollowingBlock(
 at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.nextBlockOutputStream(
 at org.apache.hadoop.hdfs.DFSOutputStream$

Have you ever successfully deployed hdfs on docker and shared your experience with anyone who can use java api

Add: After I connected with eclipse-hadoop plug-in, there was that file in the file system, but there was no content.

Hello, I have the same problem. After uploading master command in docker, there is no problem. After mapping the 9000 port to the host 9000, accessing hdfs://localhost:9000 and uploading using java api, there is the same problem as you. The file was uploaded, but the size is 0.eclipse reported the same error as yours. Have you solved your problem? It’s been a long time since it was solved.