项目位置
项目代码地址如下 项目的GIT地址
项目中有初始化sql文件和源代码,我们软件编译好名字为jeewms-3.7.jar. 通过maven 自己编译获取项目的war包
准备好文件
[root@master1 wms]# cat sqlmod.cnf supervisord.conf
[mysqld]
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
[supervisord]
nodaemon=true
[program:mysql]
command=docker-entrypoint.sh mysqld
autostart=true
autorestart=true
[program:javaapp]
command=/usr/local/tomcat/bin/catalina.sh run
autostart=true
autorestart=true
[root@master1 wms]#
Dockerfile
因为要执行二个程序,因此仍然使用supervisor工具。
如果直接启动 mysqld和 tomcat,mysqld是起不来的,说mysql.plugin表没有,然后jeewms-3.7就不能连接到服务器。
如果dockerfile的最后的CMD这么写
CMD ["sh", "-c", "mysqld & sleep 10 & /usr/local/tomcat/bin/catalina.sh run"]
错误情况如下
2024-07-23T08:57:08.514833Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2024-07-23T08:57:08.515276Z 0 [Note] InnoDB: Doublewrite buffer not found: creating new
2024-07-23T08:57:08.594902Z 0 [Note] InnoDB: Doublewrite buffer created
2024-07-23T08:57:08.615419Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2024-07-23T08:57:08.615475Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2024-07-23T08:57:08.616164Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2024-07-23T08:57:08.650808Z 0 [Note] InnoDB: Foreign key constraint system tables created
2024-07-23T08:57:08.650979Z 0 [Note] InnoDB: Creating tablespace and datafile system tables.
2024-07-23T08:57:08.658751Z 0 [Note] InnoDB: Tablespace and datafile system tables created.
2024-07-23T08:57:08.658861Z 0 [Note] InnoDB: Creating sys_virtual system tables.
2024-07-23T08:57:08.673484Z 0 [Note] InnoDB: sys_virtual table created
2024-07-23T08:57:08.674189Z 0 [Note] InnoDB: Waiting for purge to start
2024-07-23T08:57:08.725553Z 0 [Note] InnoDB: 5.7.44 started; log sequence number 0
2024-07-23T08:57:08.728042Z 0 [Note] Plugin 'FEDERATED' is disabled.
mysqld: Table 'mysql.plugin' doesn't exist
2024-07-23T08:57:08.728972Z 0 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2024-07-23T08:57:08.731189Z 0 [Note] Salting uuid generator variables, current_pid: 8, server_start_time: 1721725027, bytes_sent: 0,
2024-07-23T08:57:08.737861Z 0 [Note] Generated uuid: '8ae4a061-48d1-11ef-ab43-0242ac110002', server_start_time: 2251801535410283, bytes_sent: 62664848
2024-07-23T08:57:08.737919Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this serve r has been started. Generating a new UUID: 8ae4a061-48d1-11ef-ab43-0242ac110002.
2024-07-23T08:57:08.755839Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2024-07-23T08:57:09.379905Z 0 [Note] Auto generated SSL certificates are placed in data directory.
2024-07-23T08:57:09.380042Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2024-07-23T08:57:09.380059Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2024-07-23T08:57:09.386774Z 0 [Warning] CA certificate ca.pem is self signed.
2024-07-23T08:57:09.945828Z 0 [Note] Auto generated RSA key files are placed in data directory.
2024-07-23T08:57:09.958097Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2024-07-23T08:57:09.958361Z 0 [Note] IPv6 is available.
2024-07-23T08:57:09.958438Z 0 [Note] - '::' resolves to '::';
2024-07-23T08:57:09.958816Z 0 [Note] Server socket created on IP: '::'.
2024-07-23T08:57:09.969186Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessib le to all OS users. Consider choosing a different directory.
2024-07-23T08:57:09.970296Z 0 [Warning] Failed to open optimizer cost constant tables
2024-07-23T08:57:09.971381Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2024-07-23T08:57:09.971437Z 0 [ERROR] Fatal error: Failed to initialize ACL/grant/time zones structures or failed to remove tempo rary table files.
2024-07-23T08:57:09.976025Z 0 [ERROR] Aborting
上述问题最主要的原因就是一个docker里面只能运行一个进程。
因此我们需要通过supervisor启动。
FROM mysql:5.7
# 安装必要的工具和Java 1.8
RUN yum install -y wget unzip java java-devel supervisor
# 下载并安装Tomcat 7.0
RUN wget https://archive.apache.org/dist/tomcat/tomcat-7/v7.0.109/bin/apache-tomcat-7.0.109.zip && \
unzip apache-tomcat-7.0.109.zip && \
mv apache-tomcat-7.0.109 /usr/local/tomcat && \
rm apache-tomcat-7.0.109.zip
COPY sqlmod.cnf /etc/my.cnf.d/sqlmod.cnf
# 将你的WAR包复制到容器内
COPY jeewms-3.7.war /usr/local/tomcat/webapps/
# 设置工作目录
WORKDIR /docker-entrypoint-initdb.d
# 这个目录下的SQL会自动执行。
COPY supervisord.conf .
# 设置语言环境
ENV LANG=C.UTF-8
ENV MYSQL_DATABASE=wms
# 添加 SQL 初始化脚本
ADD init.sql .
# 设置环境变量,确保MySQL和Tomcat在容器启动时运行
ENV MYSQL_ROOT_PASSWORD=Zzerp123
# 设置工作目录为Tomcat的根目录
WORKDIR /usr/local/tomcat
RUN chmod +x /usr/local/tomcat/bin/catalina.sh
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# 启动 supervisor
CMD [ "/usr/bin/supervisord", "-c" ,"/etc/supervisor/conf.d/supervisord.conf"]
# 设置容器启动命令
#CMD ["sh", "-c", "mysqld & sleep 10 & /usr/local/tomcat/bin/catalina.sh run"]
# 设置容器内部的监听
编译dockefile期望当前的镜像可以运行
[root@master1 wms]# docker build -t wms:1.0 .
[+] Building 143.4s (16/16) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 1.32kB 0.0s
=> [internal] load metadata for docker.io/library/mysql:5.7 1.9s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> CACHED [ 1/11] FROM docker.io/library/mysql:5.7@sha256:4bc6bc963e6d8443453676cae56536f4b8156d78bae03c0145cbe47c2aad73bb 0.0s
=> [internal] load build context 0.1s
=> => transferring context: 373B 0.0s
=> [ 2/11] RUN yum install -y wget unzip java java-devel supervisor 117.1s
=> [ 3/11] RUN wget https://archive.apache.org/dist/tomcat/tomcat-7/v7.0.109/bin/apache-tomcat-7.0.109.zip && unzip apache-tomcat 5.5s
=> [ 4/11] COPY sqlmod.cnf /etc/my.cnf.d/sqlmod.cnf 0.1s
=> [ 5/11] COPY jeewms-3.7.war /usr/local/tomcat/webapps/ 1.9s
=> [ 6/11] WORKDIR /docker-entrypoint-initdb.d 0.1s
=> [ 7/11] COPY supervisord.conf . 0.1s
=> [ 8/11] ADD init.sql . 0.1s
=> [ 9/11] WORKDIR /usr/local/tomcat 0.0s
=> [10/11] RUN chmod +x /usr/local/tomcat/bin/catalina.sh 0.5s
=> [11/11] COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf 0.1s
=> exporting to image 15.5s
=> => exporting layers 15.4s
=> => writing image sha256:62826d8e98f8ed420935adb9b3a7f644fde64b4ebd7b478c9f99ff98973a1988 0.0s
=> => naming to docker.io/library/wms:1.0
因为我要上传公司内部的服务器,需要重新打标签
build tag -t wms:1.0 nexus.ycjy.info/wms:1.0
然后执行运行就可以了、
[root@master1 wms]# docker run -d jeewms -p 8080:8080 nexus.ycjy.info/jeewms:1.0
Unable to find image 'jeewms:latest' locally
[root@master1 wms]# docker run --rm -p 8080:8080 nexus.ycjy.info/jeewms:1.0
2024-07-24 06:41:31,245 CRIT Supervisor is running as root. Privileges were not dropped because no user is specified in the config file. If you intend to run as root, you can set user=root in the config file to avoid this message.
2024-07-24 06:41:31,254 INFO supervisord started with pid 1
2024-07-24 06:41:32,261 INFO spawned: 'javaapp' with pid 9
作者:严锋 创建时间:2024-07-24 13:44
最后编辑:严锋 更新时间:2025-05-09 15:48
最后编辑:严锋 更新时间:2025-05-09 15:48