千家信息网

Dockerfile制作镜像

发表于:2024-11-14 作者:千家信息网编辑
千家信息网最后更新 2024年11月14日,Dockerfile制作镜像目录:tomcat的Dockerfile脚本nginx.1.12.0的Dockerfile脚本mysql的Dockerfile脚本删除错误镜像和容器脚本tomcat的Doc
千家信息网最后更新 2024年11月14日Dockerfile制作镜像

Dockerfile制作镜像

目录:

  • tomcat的Dockerfile脚本
  • nginx.1.12.0的Dockerfile脚本
  • mysql的Dockerfile脚本
  • 删除错误镜像和容器脚本

    tomcat的Dockerfile脚本

cd /optmkdir tomcatcd tomcatvim DockerfileFROM centos:7MAINTAINER this is tomcat ADD jdk-8u91-linux-x64.tar.gz /usr/local/WORKDIR /usr/local/RUN mv jdk1.8.0_91 /usr/local/javaENV JAVA_HOME /usr/local/javaENV JAVA_BIN /usr/local/java/binENV JRE_HOME /usr/local/java/jreENV PATH $PATH:/usr/local/java/bin:/usr/local/java/jre/binENV CLASSPATH /usr/local/java/jre/bin:/usr/local/java/lib:/usr/local/java/jre/lib/charsets.jarADD apache-tomcat-8.5.16.tar.gz /usr/localWORKDIR /usr/local/RUN mv apache-tomcat-8.5.16 /usr/local/tomcat8EXPOSE 8080ENTRYPOINT ["/usr/local/tomcat8/bin/catalina.sh","run"]docker build -t tomcat:centos .docker run -d --name tomcat01 -p 1216:8080 -it tomcat:centos

nginx.1.12.0的Dockerfile脚本

cd /optmkdir nginxcd nginxvim Dockerfile FROM centos:7MAINTAINER this is nginx RUN yum -y updateRUN yum -y install wget pcre-devel zlib-devel make zlib gcc gcc-c++ openssl-devel net-toolsRUN useradd -M -s /sbin/nologin nginxADD nginx-1.12.0.tar.gz /usr/local/srcWORKDIR /usr/local/srcWORKDIR nginx-1.12.0RUN ./configure \--prefix=/usr/local/nginx \--user=nginx \--group=nginx \--with-http_stub_status_module && make && make installENV PATH /usr/local/nginx/sbin:$PATHEXPOSE 80EXPOSE 443RUN echo "daemon off;">>/usr/local/nginx/conf/nginx.confWORKDIR /root/nginxADD run.sh /run.shRUN chmod 755 /run.shCMD ["/run.sh"]#nginx启动文档vim run.sh#!/bin/bash/usr/local/nginx/sbin/nginxdocker build -t nginx:new .docker run -d -P nginx:new

mysql的Dockerfile脚本

mkdir mysqlcd mysql/vim DockerfileFROM centos:7MAINTAINER this is mysql RUN yum -y update#安装mysql依懒环境包RUN yum -y install \ncurses \ncurses-devel \bison \cmake \make \gcc \gcc-c++ #创建运行用户RUN useradd -s /sbin/nologin mysql#上传jingxADD mysql-boost-5.7.20.tar.gz /usr/local/src#编译安装WORKDIR /usr/local/src/mysql-5.7.20/RUN cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \-DSYSCONFDIR=/etc \-DSYSTEMD_PID_DIR=/usr/local/mysql \-DDEFAULT_CHARSET=utf8  \-DDEFAULT_COLLATION=utf8_general_ci \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_ARCHIVE_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \-DMYSQL_DATADIR=/usr/local/mysql/data \-DWITH_BOOST=boost \-DWITH_SYSTEMD=1 && make && make install#数据库目录进行权限调整RUN chown -R mysql:mysql /usr/local/mysql/#调整配置文件RUN rm -rf /etc/my.cnfADD my.cnf /etcRUN chown mysql:mysql /etc/my.cnf#设置环境变量ENV PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH#初始化数据库WORKDIR /usr/local/mysql/RUN bin/mysqld \--initialize-insecure \--user=mysql \--basedir=/usr/local/mysql \--datadir=/usr/local/mysql/dataRUN cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ADD run.sh /run.shRUN chmod 755 /run.shEXPOSE 3306CMD ["/run.sh"]#CMD ["mysql_safe"]#my.cnf启动脚本vim my.cnf[root@localhost mysql-5.7.20]#vi /etc/my.cnf[client]port = 3306default-character-set=utf8socket = /usr/local/mysql/mysql.sock[mysql]port = 3306default-character-set=utf8socket = /usr/local/mysql/mysql.sock[mysqld]user = mysqlbasedir = /usr/local/mysqldatadir = /usr/local/mysql/dataport = 3306character_set_server=utf8pid-file = /usr/local/mysql/mysqld.pidsocket = /usr/local/mysql/mysql.sockserver-id = 1sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES#mysql权限脚本vim run.sh/usr/bin/systemctl start mysql.server && \mysql -e "grant all privileges on *.* to 'root'@'%' identified by 'abc123';" && \mysql -e "grant all privileges on *.* to 'root'@'%' localhost identified by 'abc123';"docker build -t centos:mysql .docker run --name=mysql_server -d -P --privileged centos:mysql /usr/bin/initialize-insecuredocker exec -it  镜像ID  /bin/bash

删除错误镜像和容器

cd /optvim none.sh#!/bin/bashdocker ps -a | grep "Exited" | awk '{print $1 }' |xargs docker stopdocker ps -a | grep "Exited" | awk '{print $1 }' |xargs docker rmdocker images | grep none | awk '{print $3 }' | xargs docker rmi
0