HDFS as volume in cloudera quickstart docker

2019-05-07 19:29发布

问题:

I am fairly new to both hadoop and docker.

I haven been working on extending the cloudera/quickstart docker image docker file and wanted to mount a directory form host and map it to hdfs location, so that performance is increased and data are persist localy.

When i mount volume anywhere with -v /localdir:/someDir everything works fine, but that's not my goal. But when i do -v /localdir:/var/lib/hadoop-hdfs both datanode and namenode fails to start and I get : "cd /var/lib/hadoop-hdfs: Permission denied". And when i do -v /localdir:/var/lib/hadoop-hdfs/cache no permission denied but datanode and namenode, or one of them fails to start on starting the docker image and i can't find any useful information in log files about the reason for that.

Mayby someone came across this problem, or have some other solution for putting hdfs outside the docker container?

回答1:

You should run a

docker exec -it "YOUR CLOUDERA CONTAINER" chown -R hdfs:hadoop /var/lib/hadoop-hdfs/ 


回答2:

I've the same problem and I've managed the situation copying the entire /var/lib directory from container to a local directory

From terminal, start the cloudera/quickstart container without start all hadoop services:

docker run -ti cloudera/quickstart /bin/bash

In another terminal copy the container directory to the local directory :

mkdir /local_var_lib
docker exec your_container_id tar Ccf $(dirname /var/lib) - $(basename /var/lib) | tar Cxf /local_var_lib -

After all files copied from container to local dir, stop the container and point the /var/lib to the new target. Make sure the /local_var_lib directory contains the hadoop directories (hbase, hadoop-hdfs, oozie, mysql, etc).

Start the container:

docker run --name cloudera \
  --hostname=quickstart.cloudera \
  --privileged=true \
  -td \
  -p 2181:2181 \
  -p 8888:8888 \
  -p 7180:7180 \
  -p 6680:80 \
  -p 7187:7187 \
  -p 8079:8079 \
  -p 8080:8080 \
  -p 8085:8085 \
  -p 8400:8400 \
  -p 8161:8161 \
  -p 9090:9090 \
  -p 9095:9095 \
  -p 60000:60000 \
  -p 60010:60010 \
  -p 60020:60020 \
  -p 60030:60030 \
  -v /local_var_lib:/var/lib \
  cloudera/quickstart /usr/bin/docker-quickstart