一、制作镜像
1. centos 容器
# 下载centos镜像
docker pull centos
# 创建一个容器
docker run --name centos -itd centos /bin/bash
# 进入已启动的容器
docker attach centos
2.下载安装包
# 安装wget、ssh等基础服务
yum install -y net-tools which openssh-clients openssh-server iproute.x86_64 wget passwd
# 下载jdk1.8:https://www.oracle.com/cn/java/technologies/javase-jdk8-downloads.html
wget https://download.oracle.com/otn/java/jdk/8u231-b11/5b13a193868b4bf28bcb45c792fce896/jdk-8u231-linux-x64.tar.gz?AuthParam=1586404625_30c185b984c1c247e5e9c10cb056d0a5
# 下载hadoop2.10:https://hadoop.apache.org/old/releases.html
wget https://mirrors.tuna.tsinghua.edu.cn/apache/hadoop/common/hadoop-2.10.0/hadoop-2.10.0.tar.gz
# 下载spark2.4:https:https://spark.apache.org/downloads.html
wget https://mirrors.tuna.tsinghua.edu.cn/apache/spark/spark-2.4.5/spark-2.4.5-bin-without-hadoop.tgz
# 下载scala2.12
wget https://downloads.lightbend.com/scala/2.12.3/scala-2.12.3.tgz
3.配置ssh
#修改root密码
passwd
修改配置文件
# 修改ssh配置文件
sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
# 重启ssh服务
systemctl start sshd.service
#这里会报错
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
#直接进行下面的命令就行,使用最后一步的命令启动就解决这个问题了
#退出容器
exit
# 将刚刚修改的容器保存为新的镜像
docker commit 6a5967a064bc my-ssh-centos
#启动容器(--privileged=true 和后面的 /sbin/init 必须要有,以特权模式启动容器,否则无法使用systemctl启动服务)
docker run -tid --privileged --name my-ssh-centos my-ssh-centos /usr/sbin/init
#进入容器
docker exec -it my-ssh-centos /bin/bash
设置ssh免密登录
cd ~;ssh-keygen -t rsa -P '' -f ~/.ssh/id_dsa;cd .ssh;cat id_dsa.pub >> authorized_keys
4.安装jdk
#创建安装目录
mkdir /usr/local/java/
解压文件至安装目录
tar -zxvf jdk-8u231-linux-x64.tar.gz -C /usr/local/java/
#设置环境变量
~/.bashrc中添加
export JAVA_HOME=/usr/local/java/jdk1.8.0_231
export JRE_HOME=$JAVA_HOME/jre
export PATH=$JAVA_HOME/bin:$PATH:$JRE_HOME/bin
#使环境变量生效
source ~/.bashrc
5.安装scala
#创建