第一步,拉镜像
docker pull registry.cn-hangzhou.aliyuncs.com/hadoop_test/hadoop_base
改个镜像名,太长了改成hadoop_base
docker tag registry.cn-hangzhou.aliyuncs.com/hadoop_test/hadoop_base hadoop_base
第二步,把容器跑起来
进入容器后,看worker,它不是五个机器,是三个,分别是Master、Slave1、Slave2

先建立hadoop用的内部网络
docker network create --driver=bridge --subnet=172.19.0.0/16  hadoop
创建master容器,开放端口
docker run -it --network hadoop -h Master --ip=172.19.0.2 --name Master -p 9870:9870 -p 8088:8088 -p 9083:9083 -p 10000:10000 hadoop_base bash
 同样的,创建slave1容器
docker run -it --network hadoop -h Slave1 --ip=172.19.0.21 --name Slave1 hadoop_base bash
创建slave2容器
docker run -it --network hadoop -h Slave2 --ip=172.19.0.22 --name Slave2 hadoop_base bash
第三步,启动hadoop
三台机器,根据实际IP 修改host vim /etc/hosts
172.19.0.2 Master
172.19.0.21 Slave1
172.19.0.22 Slave2
进入master,启动hadoop,先格式化hdfs
root@Master:/usr/local/hadoop/bin# ./hadoop namenode -format
启动全部,包含hdfs和yarn
root@Master:/usr/local/hadoop/sbin# ./start-all.sh
如果中途有什么问题,可以关闭全部,包含hdfs和yarn
root@Master:/usr/local/hadoop/sbin# ./stop-all.sh


如果看到服务起来,就可以了
Starting namenodes on [Master]
Master: Warning: Permanently added 'master,172.19.0.2' (ECDSA) to the list of known hosts.
Starting datanodes
Slave2: Warning: Permanently added 'slave2,172.19.0.21' (ECDSA) to the list of known hosts.
Slave1: Warning: Permanently added 'slave1,172.19.0.22' (ECDSA) to the list of known hosts.
Slave1: WARNING: /usr/local/hadoop/logs does not exist. Creating.
Slave2: WARNING: /usr/local/hadoop/logs does not exist. Creating.
Starting secondary namenodes [Master]
Starting resourcemanager
Starting nodemanagers
访问本机的 8088 与 9870 端口就可以看到监控信息了


http://localhost:8088/cluster/cluster
localhost:8088/cluster/cluster
http://localhost:9870/dfshealth.html#tab-overview
localhost:9870/dfshealth.html#tab-overview


可查看分布式文件系统的状态
root@Master:/# ./usr/local/hadoop/bin/hadoop dfsadmin -report


docker 退出导致Master Slave1 Slave2停止运行,怎么重新启动这三个集群?
直接docker run -d 后台运行容器。想要进入容器再docker exec -ti进去。这样,退出就不会停止运行了。