docker镜像制作

/ Docker / 没有评论 / 106浏览

大数据学习过程中,采用docker搭建环境,方便快速。

制作centos-ssh-root镜像

Dockerfile

# 选择一个已有的os镜像作为基础
FROM centos

# 镜像的作者
MAINTAINER xuanbo

# 安装openssh-server和sudo软件包,并且将sshd的UsePAM参数设置成no
RUN yum install -y openssh-server sudo
RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config

# 安装openssh-clients
RUN yum  install -y openssh-clients

# 添加测试用户root,密码root,并且将此用户添加到sudoers里 
RUN echo "root:root" | chpasswd
RUN echo "root	ALL=(ALL)	ALL" >> /etc/sudoers

# 下面这两句比较特殊,在centos6上必须要有,否则创建出来的容器sshd不能登录
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key

# 启动sshd服务并且暴露22端口
RUN mkdir /var/run/sshd
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]

Build

docker build -t "centos-ssh-root" .

制作centos-ssh-root-jdk镜像

下载jdk8

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u142-linux-x64.tar.gz"

Dockerfile

FROM centos-ssh-root
ADD jdk-8u142-linux-x64.tar.gz /usr/local/
RUN mv /usr/local/jdk1.8.0_142 /usr/local/jdk1.8
ENV JAVA_HOME /usr/local/jdk1.8
ENV PATH $JAVA_HOME/bin:$PATH

Build

docker build -t "centos-ssh-root-jdk" .

制作centos-ssh-root-jdk-hadoop镜像

下载hadoop-2.6.0-cdh5.14.2

wget http://archive.cloudera.com/cdh5/cdh/5/hadoop-2.6.0-cdh5.14.2.tar.gz

Dockerfile

FROM centos-ssh-root-jdk

# hadoop
ADD hadoop-2.6.0-cdh5.14.2.tar.gz /usr/local
RUN mv /usr/local/hadoop-2.6.0-cdh5.14.2 /usr/local/hadoop
ENV HADOOP_HOME /usr/local/hadoop
ENV PATH $HADOOP_HOME/bin:$PATH

VOLUME ["/usr/local/hadoop/tmp"]

Build

docker build -t "centos-ssh-root-jdk-hadoop" .

Run

docker run --name hadoop0 --hostname hadoop0 -d -P -p 50070:50070 -p 8088:8088 -v /usr/local/hadoop/tmp:/usr/local/hadoop/tmp centos-ssh-root-jdk-hadoop

Exec

docker exec -it hadoop0 /bin/bash

制作centos-ssh-root-jdk-hadoop-hive镜像

下载hadoop-2.6.0-cdh5.14.2

wget http://archive.cloudera.com/cdh5/cdh/5/hadoop-2.6.0-cdh5.14.2.tar.gz

下载hive-1.1.0-cdh5.14.2.tar.gz

wget http://archive.cloudera.com/cdh5/cdh/5/hive-1.1.0-cdh5.14.2.tar.gz

Dockerfile

FROM centos-ssh-root-jdk

# hadoop
ADD hadoop-2.6.0-cdh5.14.2.tar.gz /usr/local
RUN mv /usr/local/hadoop-2.6.0-cdh5.14.2 /usr/local/hadoop
ENV HADOOP_HOME /usr/local/hadoop
ENV PATH $HADOOP_HOME/bin:$PATH

# hive
ADD hive-1.1.0-cdh5.14.2.tar.gz /usr/local
RUN mv /usr/local/hive-1.1.0-cdh5.14.2 /usr/local/hive
ENV HIVE_HOME /usr/local/hive
ENV PATH $HIVE_HOME/bin:$PATH

VOLUME ["/usr/local/hadoop/tmp", "/usr/local/hive/tmp"]

Build

docker build -t "centos-ssh-root-jdk-hadoop-hive" .

Run

docker run --name hive0 --hostname hadoop0 -d -P -p 50070:50070 -p 8088:8088 -p 10000:10000 -v /usr/local/hadoop/tmp:/usr/local/hadoop/tmp -v /usr/local/hive/tmp:/usr/local/hive/tmp centos-ssh-root-jdk-hadoop-hive

Exec

docker exec -it hive0 /bin/bash

制作centos-ssh-root-jdk-kafka镜像

下载

Dockerfile

FROM centos-ssh-root-jdk

# kafka
ADD kafka_2.11-1.1.0.tgz /usr/local/
RUN mv /usr/local/kafka_2.11-1.1.0 /usr/local/kafka
ENV KAFKA_HOME /usr/local/kafka
ENV PATH $KAFKA_HOME/bin:$PATH
EXPOSE 9092

# monitor
COPY KafkaOffsetMonitor-assembly-0.4.6-SNAPSHOT.jar /usr/local/

EXPOSE 9092 8088

Build

docker build -t "centos-ssh-root-jdk-kafka" .

Run

docker run --name kafka0 --hostname kafka0 -d -P -p 9092:9092 -p 8088:8088 centos-ssh-root-jdk-kafka

Exec

docker exec -it kafka0 /bin/bash

启动

bin/zookeeper-server-start.sh config/zookeeper.properties
bin/kafka-server-start.sh config/server.properties
java -cp KafkaOffsetMonitor-assembly-0.4.6-SNAPSHOT.jar \
       com.quantifind.kafka.offsetapp.OffsetGetterWeb \
     --offsetStorage kafka \
     --kafkaBrokers localhost:9092 \
     --zk localhost:2181 \
     --port 8088 \
     --refresh 10.seconds \
     --retain 2.days \
     --dbName offsetapp_kafka

访问

容器开放了kafka的9092端口、监控服务的8088端口。