编写dockerfile,构建tomcat镜像

编写dockerfile,构建tomcat镜像

[root@docker ~]# cd test
[root@docker test]# ls
damo  nginx_images
[root@docker test]# mkdir tomcat_image
[root@docker test]# cd tomcat_image/
[root@docker tomcat_image]# ls
[root@docker tomcat_image]# vim Dockerfile

在这里插入图片描述

vim Dockerfile

FROM centos:7
MAINTAINER this is tomcat image
ADD jdk-8u91-linux-x64.tar.gz /usr/local
WORKDIR /usr/local/
RUN mv jdk1.8.0_91 /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-8.5.16.tar.gz /usr/local
WORKDIR /usr/local/
RUN mv apache-tomcat-8.5.16 /usr/local/tomcat8
EXPOSE 8080
#CMD [“/usr/local/tomcat8/bin/catalina.sh”,“run”]
ENTRYPOINT [“/usr/local/tomcat8/bin/catalina.sh”,“run”]

docker build -t tomcat:centos .

docker run -d --name tomcat01 -p 1216:8080 tomcat:centos

[root@docker tomcat_image]# vim Dockerfile
[root@docker tomcat_image]# docker build -t tomcat:centos .
Sending build context to Docker daemon  192.2MB
Step 1/14 : FROM centos:7
 ---> eeb6ee3f44bd
Step 2/14 : ADD jdk-8u91-linux-x64.tar.gz /usr/local

在这里插入图片描述

Successfully built ce0a10c64d5a
Successfully tagged tomcat:centos
[root@docker tomcat_image]# docker run -d --name tomcat01 -p 1216:8080 tomcat:centos 
bd56f99c4f049d101fb23c5fd4a223f9f62be22ad0d85d4c8beec7fba1d1ae6f

在这里插入图片描述

dockerfile-mysql
cd /opt
mkdir test_1
cd test_1
mkdir mysql
cd mysql

[root@docker ~]# cd /opt
[root@docker opt]# mkdir test_1
[root@docker opt]# cd test_1/
[root@docker test_1]# mkdir mysql
[root@docker test_1]# cd mysql/
[root@docker mysql]# vim my.cnf

vim 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

[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
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

:wq

#上传安装包mysql-boost-5.7.20.tar.gz

vim Dockerfile

FROM centos:7

ADD mysql-boost-5.7.20.tar.gz /usr/local

RUN yum -y install
ncurses
ncurses-devel
bison
cmake
gcc
gcc-c++
make

RUN useradd -M -s /sbin/nologin mysql

WORKDIR /usr/local/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_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=boost
-DWITH_SYSTEMD=1 && make && make install

WORKDIR /opt/kiki/mysql
ADD my.cnf /etc

RUN chown -R mysql:mysql /usr/local/mysql/
RUN chown mysql:mysql /etc/my.cnf

ENV PATH $PATH:/usr/local/mysql/bin:/usr/local/mysql/lib

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”]

docker run --privileged -d -P mysql
在这里插入图片描述

#进入容器
mysql -uroot -p

grant all privileges on . to ‘root’@‘%’ identified by ‘123123’;
grant all privileges on . to ‘root’@‘localhost’ identified by ‘123123’;

创建库、表示

#测试
宿主机安装mariadb
yum install -y mariadb
mysql -uroot -P 容器端口 -p123123

注:勿借鉴部分截图无,想不到其中思路步骤的,勿看

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值