我是靠谱客的博主 善良犀牛,最近开发中收集的这篇文章主要介绍Docker系列---dockerfile方式 | 编写镜像 | 参考模板 | 说明详细mysql 模板nginx 模板Tomcat 模板ssh 模板,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
镜像模板
- mysql 模板
- nginx 模板
- Tomcat 模板
- ssh 模板
mysql 模板
在 root目录里面创建mysql目录 创建dockerfile my.cnf 文件
#Dockerfile文件
FROM centos:7
MAINTAINER dark
RUN yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake make
RUN useradd -M -s /sbin/nologin mysql
ADD mysql-5.7.17.tar.gz /usr/local/src
ADD boost_1_59_0.tar.gz /usr/local/boost
WORKDIR /usr/local/src/mysql-5.7.17
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_EXTRA_CHARSETS=all
-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=/usr/local/boost
-DWITH_SYSTEMD=1
RUN make && make install
RUN rm -rf /etc/my.cnf
ADD my.cnf /etc/my.cnf
RUN chown -R mysql.mysql /usr/local/mysql/
RUN chown mysql.mysql /etc/my.cnf
ENV PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
WORKDIR /usr/local/mysql/bin/
RUN ./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"]
#my.cnf文件
[client]
port = 3306
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock
auto-rehash
[mysqld]
user = mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character-set-server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1
sql_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
#构建过程
docker build -t mysql:new .
docker images
docker run -itd --privileged -P mysql:new
docker ps -a
docker exec -it 容器ID /bin/bash
进去容器
mysql -uroot -p 回车进去
grant all privileges on *.* to 'root'@'%' identified by '1';
grant all privileges on *.* to 'root'@'localhost' identified by '1';
flush privileges;
quit
mysql -uroot -p 密码
show databases;
yum -y install mysql
mysql -uroot -p1 -hIP地址 -P端口
nginx 模板
#Dockerfile文件内容
FROM centos:7
MAINTAINER dark
RUN yum -y install pcre-devel openssl-devel zlib-devel gcc gcc-c++ make cmake
RUN useradd -M -s /sbin/nologin nginx
ADD nginx-1.12.2.tar.gz /usr/local/src
WORKDIR /usr/local/src/nginx-1.12.2
RUN ./configure --prefix=/usr/local/nginx
--user=nginx
--group=nginx
--with-file-aio
--with-http_stub_status_module
--with-http_gzip_static_module
--with-http_flv_module
--with-http_ssl_module
RUN make && make install
RUN ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
RUN ln -s /usr/local/nginx/conf/nginx.conf /etc/
RUN rm -rf /lib/systemd/system/nginx.service
ADD nginx.service /lib/systemd/system/nginx.service
RUN chown nginx.nginx /lib/systemd/system/nginx.service
RUN chmod 754 /lib/systemd/system/nginx.service
EXPOSE 80
EXPOSE 443
RUN echo "daemon off;" >> /usr/local/nginx/conf/nginx.conf
CMD ["/usr/local/nginx/sbin/nginx"]
#nginx.service文件内容
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecrReload=/bin/kill -s HUP $MAINPID
ExecrStop=/bin/ki11 -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#构建过程
docker build -t nginx:new .
docker images
docker run -itd -P nginx:new
docker ps -a
docker exec -it 容器ID /bin/bash
Tomcat 模板
FROM centos:7
MAINTAINER dark
ADD jdk-8u201-linux-x64.rpm /usr/local/
WORKDIR /usr/local/
RUN rpm -ivh jdk-8u201-linux-x64.rpm
ENV JAVA_HOME=/usr/java/jdk1.8.0_201-amd64
ENV CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
ENV PATH=$JAVA_HOME/bin:$PATH
ADD apache-tomcat-9.0.16.tar.gz /usr/local/
WORKDIR /usr/local/
RUN mv apache-tomcat-9.0.16 /usr/local/tomcat
EXPOSE 8080
ENTRYPOINT ["/usr/local/tomcat/bin/catalina.sh","run"]
docker build -t tomcat:new
docker images
docker run -itd -P 镜像ID
docker ps -a
docker exec -it 容器ID /bin/bash
ssh 模板
#vim Dockerfile
FROM centos:7
MAINTAINER dark
RUN yum -y update && yum -y install openssh* net-tools lsof telnet passwd && echo "1" | passwd --stdin root && sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config && ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key && 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"]
#构建镜像
docker build -t sshd:new .
docker run -itd -P sshd:new
docker ps -a
docker exec -it sshd:new /bin/bash
ssh locathost -p 端口号
最后
以上就是善良犀牛为你收集整理的Docker系列---dockerfile方式 | 编写镜像 | 参考模板 | 说明详细mysql 模板nginx 模板Tomcat 模板ssh 模板的全部内容,希望文章能够帮你解决Docker系列---dockerfile方式 | 编写镜像 | 参考模板 | 说明详细mysql 模板nginx 模板Tomcat 模板ssh 模板所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复