tar -xvf
tar -xzvf
先解压到本地查看。ADD
文件路径到 /opt
下,因为 opt 目录一般为空,不易搞混。# 准备一个目录用作存放文件
mkdir /root/public
# 准备构建镜像需要添加的yum源文件
# 这里用ftp做连接,需要目标主机提前安装vsftpd并将访问根目录设为/opt
vi /root/public/local.repo
[gpmall]
name=gpmall
baseurl=ftp://192.168.200.100/ChinaskillMall/gpmall-repo
enabled=1
gpgcheck=0
[centos]
name=centos
baseurl=ftp://192.168.200.100/centos
gpgcheck=0
enabled=1
[k8s]
name=k8s
baseurl=ftp://192.168.200.100/kubernetes-repo
gpgcheck=0
enabled=1
# 准备部署MariaDB需要添加的.sh脚本文件
vi /root/public/start.sh
#!/bin/bash
mysql_install_db --user=mysql
mysqld_safe &
sleep 3
mysqladmin -u root password '123456'
mysql -uroot -p123456 -e "grant all privileges on *.* to 'root'@'%' identified by '123456';"
mysql -uroot -p123456 -e "create database gpmall;use gpmall;source /opt/gpmall.sql;"
# 准备部署Nginx需要添加的.sh脚本文件
vi /root/public/setup.sh
#!/bin/bash
nohup java -jar /root/shopping-provider-0.0.1-SNAPSHOT.jar &
sleep 5
nohup java -jar /root/user-provider-0.0.1-SNAPSHOT.jar &
sleep 5
nohup java -jar /root/gpmall-shopping-0.0.1-SNAPSHOT.jar &
sleep 5
nohup java -jar /root/gpmall-user-0.0.1-SNAPSHOT.jar &
sleep 5
# 准备构建镜像需要添加的其余文件
cp /opt/ChinaskillMall/gpmall.sql /root/public
cp /opt/ChinaskillMall/zookeeper-3.4.14.tar.gz /root/public
cp /opt/ChinaskillMall/kafka_2.11-1.1.1.tgz /root/public
cp /opt/ChinaskillMall/*.jar /root/public
cp -rfv /opt/ChinaskillMall/dist/ /root/public
在 master 节点上编写/root/redis/Dockerfile 文件,基于提供的软件包gpmall-single.tar 构建 chinaskill-redis:v1.1 镜像,具体要求如下:
mkdir /root/redis/
cp /root/public/local.repo /root/redis/
vi /root/redis/Dockerfile
FROM centos:centos7.5.1804
MAINTAINER Chinaskill
RUN rm -rf /etc/yum.repos.d/*
ADD local.repo /etc/yum.repos.d/
RUN yum -y install redis*
RUN sed -i 's/bind 127.0.0.1/bind 0.0.0.0/g' /etc/redis.conf && sed -i 's/protected-mode yes/protected-mode no/g' /etc/redis.conf
EXPOSE 6379
CMD ["redis-server","/etc/redis.conf"]
# 此shell块为个人注释笔记,不需要执行
# 一个 Dockerfile 只有一个 CMD 指令,若有多个,只有最后一个 CMD 指令生效
# CMD 主要目的:为容器提供默认执行的命令,这个默认值可以包含可执行文件
CMD ["redis-server","/etc/redis.conf"]
CMD ["可执行命令", "参数1", "参数2"...]
# 完成后构建镜像
cd /root/redis/
# 通过 --network=host 参数来确保docker使用与宿主机同一网络
docker build --network=host -t chinaskill-redis:v1.1 .
在 master 节点上编写/root/mariadb/Dockerfile 文件,基于提供的软件包gpmall-single.tar 构建 chinaskill-mariadb:v1.1 镜像,具体要求如下:
mkdir /root/mariadb/
cp /root/public/local.repo /root/mariadb/
cp /root/public/gpmall.sql /root/mariadb/
cp /root/public/start.sh /root/mariadb/
vi /root/mariadb/Dockerfile
FROM centos:centos7.5.1804
MAINTAINER chinaskill
RUN rm -rf /etc/yum.repos.d/*
ADD local.repo /etc/yum.repos.d/
ADD gpmall.sql /opt/
ADD start.sh /opt/
RUN yum -y install mariadb-server
RUN chmod +x /opt/start.sh
RUN /opt/start.sh
EXPOSE 3306
ENV LC_ALL en_US.UTF-8
CMD mysqld_safe
# 完成后构建镜像
cd /root/mariadb/
# 通过 --network=host 参数来确保docker使用与宿主机同一网络
docker build --network=host -t chinaskill-mariadb:v1.1 .
在 master 节点上编写/root/zookeeper/Dockerfile 文件,基于提供的软件包gpmall-single.tar 构建 chinaskill-zookeeper:v1.1 镜像,具体要求如下:
mkdir /root/zookeeper/
cp /root/public/local.repo /root/zookeeper/
cp /root/public/zookeeper-3.4.14.tar.gz /root/zookeeper/
vi /root/zookeeper/Dockerfile
FROM centos:centos7.5.1804
MAINTAINER Chinaskill
EXPOSE 2181
RUN rm -rf /etc/yum.repos.d/*
ADD local.repo /etc/yum.repos.d/
ADD zookeeper-3.4.14.tar.gz /opt
RUN yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
RUN mv /opt/zookeeper-3.4.14/conf/zoo_sample.cfg /opt/zookeeper-3.4.14/conf/zoo.cfg
CMD ["sh","-c","/opt/zookeeper-3.4.14/bin/zkServer.sh start && tail -f /etc/shadow"]
# 完成后构建镜像
cd /root/zookeeper/
# 通过 --network=host 参数来确保docker使用与宿主机同一网络
docker build --network=host -t chinaskill-zookeeper:v1.1 .
使用构建的镜像运行容器 myzookeeper。
在 master 节点上编写/root/kafka/Dockerfile 文件,基于提供的软件包gpmall-single.tar 构建 chinaskill-kafka:v1.1 镜像,具体要求如下:
mkdir /root/kafka/
cp /root/public/local.repo /root/kafka/
cp /root/public/zookeeper-3.4.14.tar.gz /root/kafka/
cp /root/public/kafka_2.11-1.1.1.tgz /root/kafka/
vi /root/kafka/Dockerfile
FROM centos:centos7.5.1804
MAINTAINER chinaskill
RUN rm -rf /etc/yum.repos.d/*
ADD local.repo /etc/yum.repos.d/
ADD zookeeper-3.4.14.tar.gz /opt/
ADD kafka_2.11-1.1.1.tgz /opt/
RUN yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
RUN mv /opt/zookeeper-3.4.14/conf/zoo_sample.cfg /opt/zookeeper-3.4.14/conf/zoo.cfg
EXPOSE 9092
CMD ["sh","-c","/opt/zookeeper-3.4.14/bin/zkServer.sh start && /opt/kafka_2.11-1.1.1/bin/kafka-server-start.sh /opt/kafka_2.11-1.1.1/config/server.properties"]
# 完成后构建镜像
cd /root/kafka/
# 通过 --network=host 参数来确保docker使用与宿主机同一网络
docker build --network=host -t chinaskill-kafka:v1.1 .
在 master 节点上编写/root/nginx/Dockerfile 文件,基于提供的软件包gpmall-single.tar 构建 chinaskill-nginx:v1.1 镜像,具体要求如下:
mkdir /root/nginx/
cp /root/public/local.repo /root/nginx/
cp /root/public/*.jar /root/nginx/
cp /root/public/setup.sh /root/nginx/
cp -rfv /root/public/dist/ /root/nginx/
vi /root/nginx/Dockerfile
FROM centos:centos7.5.1804
MAINTAINER chinaskill
RUN rm -rf /etc/yum.repos.d/*
ADD local.repo /etc/yum.repos.d/
ADD *.jar /root/
ADD setup.sh /root/
RUN yum -y install nginx java-1.8.0-openjdk java-1.8.0-openjdk-devel
RUN sed -i '1a location /shopping { proxy_pass http://127.0.0.1:8081 ;}' /etc/nginx/conf.d/default.conf
RUN sed -i '2a location /user { proxy_pass http://127.0.0.1:8082 ;}' /etc/nginx/conf.d/default.conf
RUN sed -i '3a location /cashier { proxy_pass http://127.0.0.1:8083 ;}' /etc/nginx/conf.d/default.conf
RUN chmod +x /root/setup.sh
RUN rm -rf /usr/share/nginx/html/
EXPOSE 80 443 8081 8082 8083
ADD dist/ /usr/share/nginx/html/
CMD ["nginx","-g","daemon off;"]
# 完成后构建镜像
cd /root/nginx/
# 通过 --network=host 参数来确保docker使用与宿主机同一网络
docker build --network=host -t chinaskill-nginx:v1.1 .
在 master 节点上编写/root/chinaskillmall/docker-compose.yaml 文件,具体要求如下:
mkdir /root/chinaskillmall/
vi /root/chinaskillmall/docker-compose.yaml
version: '3'
services:
mall-mysql:
image: chinaskill-mariadb:v1.1
ports:
- 13306:3306
mall-redis:
image: chinaskill-redis:v1.1
ports:
- 16379:6379
mall-kafka:
image: chinaskill-kafka:v1.1
ports:
- 19092:9092
mall-zookeeper:
image: chinaskill-zookeeper:v1.1
ports:
- 12181:2181
mall-nginx:
image: chinaskill-nginx:v1.1
depends_on:
- mall-mysql
- mall-redis
- mall-zookeeper
- mall-kafka
links:
- mall-mysql:mysql.mall
- mall-redis:redis.mall
- mall-zookeeper:zookeeper.mall
- mall-kafka:kafka.mall
ports:
- 83:80
- 1443:443
command: ["sh","-c","/root/setup.sh && nginx && tail -f /etc/shadow"]
# 完成后编排部署 GPMall
cd /root/chinaskillmall/
docker-compose up -d
docker-compose ps -a