区块链技术博客
www.b2bchain.cn

dockerfile部署镜像

这篇文章主要介绍了dockerfile部署镜像的讲解,通过具体代码实例进行18064 讲解,并且分析了dockerfile部署镜像的详细步骤与相关技巧,需要的朋友可以参考下https://www.b2bchain.cn/?p=18064

本文实例讲述了2、树莓派设置连接WiFi,开启VNC等等的讲解。分享给大家供大家参考文章查询地址https://www.b2bchain.cn/7039.html。具体如下:

dockerfile部署镜像

  • 构建ssh镜像
  • 构建nginx镜像
  • 部署tomcat镜像
  • 部署mysql镜像

构建ssh镜像

[[email protected] ~]# cd /opt/ ##创建dockerfile目录 [[email protected] opt]# mkdir sshd [[email protected] opt]# cd sshd/ [[email protected] sshd]# vim Dockerfile  FROM centos:7 MAINTAINER tanglei RUN yum -y update RUN yum -y install openssh* net-tools Isof telnet passwd RUN echo 'As123' | passwd --stdin root RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config RUN ssh-****** -t rsa -f /etc/ssh/ssh_host_rsa_key RUN sed -i '/^sessions+requireds+pam_loginuid.so/s/^/#/' /etc/pam.d/sshd RUN mkdir -p /root/.ssh && chown root.root /root && chmod 700 /root/.ssh EXPOSE 22 CMD ["/usr/sbin/sshd","-D"]  ##生成镜像,启动容器 [[email protected] sshd]# docker build -t sshd:new . [[email protected] sshd]# docker run -d -P sshd:new ##看一下端口分配的端口号 [[email protected] sshd]# docker ps -a CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS                      PORTS                                           NAMES 06ea223672e8        sshd:new               "/usr/sbin/sshd -D"      25 hours ago        Up 2 hours                  0.0.0.0:32769->22/tcp                           crazy_newton  ##测试连接。交互时第一次输入yes ##提示输入密码时输入root密码As123 [[email protected] sshd]# ssh localhost -p 32769 The authenticity of host '[localhost]:32769 ([::1]:32769)' can't be established. RSA key fingerprint is SHA256:zsabi2CDVsTQi0EoO4lFLTlUr45v6Mz6Ph4M7TzM5pE. RSA key fingerprint is MD5:b7:f8:5f:41:68:c2:74:47:60:ba:27:73:98:d9:9c:4d. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[localhost]:32769' (RSA) to the list of known hosts. [email protected]'s password:  Last login: Tue Nov 10 07:53:47 2020 from gateway [[email protected] ~]#  ##这样就进来了 

构建nginx镜像

[[email protected] opt]# mkdir nginx [[email protected] opt]# cd nginx/ [[email protected] nginx]# vim Dockerfile FROM centos:7 MAINTAINER tanglei RUN yum -y update RUN yum -y install pcre-devel zlib-devel gcc gcc-c++ make RUN useradd -M -s /sbin/nologin nginx ADD nginx-1.15.9.tar.gz /usr/local/src WORKDIR /usr/local/src WORKDIR nginx-1.15.9 RUN ./configure  --prefix=/usr/local/nginx  --user=nginx  --group=nginx  --with-http_stub_status_module && make && make install ENV PATH /usr/local/nginx/sbin:$PATH EXPOSE 80 EXPOSE 443 RUN echo "daemon off;" >> /usr/local/nginx/conf/nginx.conf ADD run.sh /run.sh RUN chmod 755 /run.sh CMD ["/run.sh"]  ##需要把要用的包(nginx-1.15.9.tar.gz)放到当前目录下(新建的nginx目录) ##还有需要用到的脚本 [[email protected] nginx]# vim run.sh #!/bin/bash /usr/local/nginx/sbin/nginx [[email protected] nginx]# docker build -t nginx:new . [[email protected] nginx]# docker run -d -P nginx:new [[email protected] nginx]# docker ps -a CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS c628f8c19144        nginx:new              "/run.sh"                24 hours ago        Up 1 second                 0.0.0.0:32771->80/tcp, 0.0.0.0:32770->443/tcp   focused_shamir ###宿主机可以访问了 

宿主机访问:
dockerfile部署镜像

部署tomcat镜像

[[email protected] opt]# mkdir tomcat [[email protected] opt]# cd tomcat/ [[email protected] tomcat]# vim Dockerfile  FROM centos:7 MAINTAINER tanglei ADD jdk-8u144-linux-x64.tar.gz /usr/local WORKDIR /usr/local RUN mv jdk1.8.0_144 /usr/local/java ENV JAVA_HOME /usr/local/java ENV JAVA_BIN /usr/local/java/bin ENV JRE_HOME /usr/local/java/jre ENV PATH $PATH:/usr/local/java/bin:/usr/local/java/jre/bin ENV CLASSPATH /usr/local/java/jre/bin:/usr/local/java/lib:/usr/local/java/jre/lib/charsets.jar ADD apache-tomcat-9.0.16.tar.gz /usr/local WORKDIR /usr/local/ RUN mv apache-tomcat-9.0.16 /usr/local/tomcat8 EXPOSE 8080 ENTRYPOINT ["/usr/local/tomcat8/bin/catalina.sh","run"]  ##把需要的两个包放到本目录下 jdk-8u144-linux-x64.tar.gz apache-tomcat-9.0.16.tar.gz ##然后就可以开始构建了 [[email protected] tomcat]# docker build -t tomcat:centos . [[email protected] tomcat]# docker run -d --name tomcat01 -p 1216:8080 tomcat:centons ##宿主机就可以访问了 

宿主机访问:
dockerfile部署镜像

部署mysql镜像

[[email protected] opt]# mkdir mysql [[email protected] opt]# cd mysql/ [[email protected] mysql]# vim Dockerfile FROM centos:7 RUN yum -y install  ncurses  ncurses-devel  bison  cmake  make  gcc  gcc-c++ RUN useradd -s /sbin/nologin mysql ADD 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 -j3 && make install RUN chown -R mysql:mysql /usr/local/mysql/ RUN rm -rf /etc/my.cnf ADD my.cnf /etc RUN 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/data RUN cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ EXPOSE 3306 RUN echo -e "#!/bin/sh nsystemctl enable mysqld" > /run.sh RUN chmod 755 /run.sh RUN sh /run.sh CMD ["init"]  ##开始构建 [[email protected] mysql]# docker build -t mysql:test . [[email protected] mysql]# docker run --name=mysql02 -d -P --privileged mysql:test [[email protected] mysql]# docker ps -a CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS                      PORTS                                           NAMES 87a448cde117        mysql:test             "init"                   3 hours ago         Up 4 minutes                0.0.0.0:32773->3306/tcp                         mysql02 [[email protected] mysql]# docker exec -it 87a448cde117 /bin/bash [[email protected] mysql]# mysql -uroot -p Enter password:  ##没有密码直接回车 ............. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. mysql>  ##授权测试访问 mysql> grant all privileges on *.* to 'root'@'%' identified by 'As123'; mysql> grant all privileges on *.* to 'root'@'localhost' identified by 'As123'; mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)  ##可以去其他虚拟机连接测试 [[email protected] ~]# yum -y install mariadb* [[email protected] ~]# mysql -uroot -pAs123 -h 20.0.0.10 -P 32773 Welcome to the MariaDB monitor.  Commands end with ; or g. Your MySQL connection id is 7 Server version: 5.7.20 Source distribution Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. MySQL [(none)]>   ###测试是不是同一个数据库 容器: mysql> show databases; +--------------------+ | Database           | +--------------------+ | information_schema | | mysql              | | performance_schema | | sys                | +--------------------+ 4 rows in set (0.01 sec)  虚拟机: mysql> show databases; +--------------------+ | Database           | +--------------------+ | information_schema | | mysql              | | performance_schema | | sys                | +--------------------+ 4 rows in set (0.01 sec)  容器: mysql> create database zhongyi; mysql> show databases; +--------------------+ | Database           | +--------------------+ | information_schema | | mysql              | | performance_schema | | sys                | | zhongyi            | +--------------------+ 5 rows in set (0.00 sec)  虚拟机: MySQL [(none)]> show databases; +--------------------+ | Database           | +--------------------+ | information_schema | | mysql              | | performance_schema | | sys                | | zhongyi            | +--------------------+ 5 rows in set (0.00 sec)  测试完毕。

本文转自互联网,侵权联系删除dockerfile部署镜像

赞(0) 打赏
部分文章转自网络,侵权联系删除b2bchain区块链学习技术社区 » dockerfile部署镜像
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

b2b链

联系我们联系我们