[ttr2v]
#!/usr/bin/env bash #后端服务创建脚本 #set -x #======================================================# #================== 变量信息 ========================# #======================================================# #目录名称 export dockerCatalogName=docker #dockerfiel 名称 export dockerFileName=deployDockerFile #dockerFile 内容 export dockerContent=' # CentOS with JDK 8 # Author JoanRoot # build a new image with basic centos FROM centos:centos7 # who is the author MAINTAINER JoanRoot # make a new directory to store the jdk files RUN mkdir /usr/local/java # copy the jdk archive to the image,and it will automaticlly unzip the tar file ADD jdk-8u212-linux-x64.tar.gz /usr/local/java/ # make a symbol link RUN ln -s /usr/local/java/jdk1.8.0_212 /usr/local/java/jdk # set environment variables ENV JAVA_HOME /usr/local/java/jdk ENV JRE_HOME ${JAVA_HOME}/jre ENV CLASSPATH .:${JAVA_HOME}/lib:${JRE_HOME}/lib ENV PATH ${JAVA_HOME}/bin:$PATH # 容器暴露的端口 EXPOSE 9000 9001 # 容器启动时执行的命令 # CMD ["java -jar deploy.jar"] ' #镜像名称和标签 export imagesName='centos/jdk1.8:v1.0' #容器名称和标签 export containerName='deploy' #======================================================# #================== 脚本部分 ========================# #======================================================# #进入根目录 echo "进入/(根目录)" cd / #输出当前目录 export dir=`pwd` echo "当前在" $dir "目录。" #1.创建目录 存在则跳过,不存在则创建 if [ ! -d $dockerCatalogName ];then mkdir /$dockerCatalogName echo "Create " $dockerCatalogName "success ." else echo "Sorry File " $dockerCatalogName "Already exist !" fi #2.进入docker 目录并下载jdk #进入目录 echo "进入" $dockerCatalogName "目录" cd $dockerCatalogName echo "当前为" $dockerCatalogName "目录" #3.下载jdk 判断文件是否已下载,下载则跳过 if [ ! -f "jdk-8u212-linux-x64.tar.gz" ];then wget -P /$dockerCatalogName https://改成jdk路径/jdk-8u212-linux-x64.tar.gz echo "download jdk-8u212-linux-x64.tar.gz" else echo "Sorry jdk-8u212-linux-x64.tar.gz Already exist !" fi #4.创建 dockerFileName if [ ! -f $dockerFileName ];then #dockerfile 不存在,直接创建创建 echo "no dockerfile go create ." cat >> $dockerFileName <> $dockerFileName < Docker安装 ========================# #======================================================# #卸载旧版本 echo "开始安装Docker" sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine #安装所需的软件包。yum-utils 提供了 yum-config-manager , #并且 device mapper 存储驱动程序需要 device-mapper-persistent-data 和 lvm2。 sudo yum install -y yum-utils device-mapper-persistent-data lvm2 #使用以下命令来设置稳定的仓库。 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo #安装 Docker Engine-Community sudo yum install docker-ce docker-ce-cli containerd.io #启动docker sudo systemctl start docker echo "Docker 安装 完成" #5.运行dockerfile docker build -f /$dockerCatalogName/$dockerFileName -t $imagesName . #6.创建 docker run -id -p 9000:9000 -p 9001:9001 --name=$containerName $imagesName /bin/bash
[/ttr2v]
© 版权声明
文章版权归作者所有,未经允许请勿转载。
tt
tt
tt_2020