当前位置: 首页 > web >正文

docker compose 编排容器 mysql Springboot应用

写一个docker-compose.yml文件

内容如下:

services:db:image: "docker.xuanyuan.me/library/mysql:8.3.0"restart: unless-stoppedhostname: dbports:- "3306:3306"container_name: mysqlenvironment:- "MYSQL_ROOT_PASSWORD=1234"myjava:build:context: .ports:- "8080:8080"depends_on:- db

如果拉起镜像困难可先用pull拉取成功后在执行docker compose

注意新版本命令是docker compose 而不是docker-compose

这样mysql先启动,自定义的容器后启动保证启动顺序

执行docker compose up

[root@localhost ~]# docker compose up
[+] Running 2/2✔ Container mysql          Created                                                                                         0.1s✔ Container root-myjava-1  Created                                                                                         0.1s
Attaching to mysql, myjava-1
mysql     | 2025-07-20 01:55:58+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.3.0-1.el8 started.
mysql     | 2025-07-20 01:55:59+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql     | 2025-07-20 01:55:59+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.3.0-1.el8 started.
mysql     | 2025-07-20 01:56:00+00:00 [Note] [Entrypoint]: Initializing database files
mysql     | 2025-07-20T01:56:00.501879Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
mysql     | 2025-07-20T01:56:00.511825Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.3.0) initializing of server in progress as process 78
mysql     | 2025-07-20T01:56:00.547310Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
mysql     | 2025-07-20T01:56:01.897536Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql     | 2025-07-20T01:56:07.956337Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
myjava-1  |
myjava-1  |   .   ____          _            __ _ _
myjava-1  |  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
myjava-1  | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
myjava-1  |  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
myjava-1  |   '  |____| .__|_| |_|_| |_\__, | / / / /
myjava-1  |  =========|_|==============|___/=/_/_/_/
myjava-1  |
myjava-1  |  :: Spring Boot ::                (v3.4.7)
myjava-1  |
myjava-1  | 2025-07-20T01:56:14.355Z  INFO 1 --- [demo1] [           main] org.example.demo1.Demo1Application       : Starting Demo1Application v0.0.1-SNAPSHOT using Java 21 with PID 1 (/app/app.jar started by root in /app)
myjava-1  | 2025-07-20T01:56:14.391Z  INFO 1 --- [demo1] [           main] org.example.demo1.Demo1Application       : The following 1 profile is active: "pro"
mysql     | 2025-07-20T01:56:19.730033Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
mysql     | 2025-07-20 01:56:19+00:00 [Note] [Entrypoint]: Database files initialized
mysql     | 2025-07-20 01:56:19+00:00 [Note] [Entrypoint]: Starting temporary server
mysql     | 2025-07-20T01:56:19.854669Z 0 [System] [MY-015015] [Server] MySQL Server - start.
mysql     | 2025-07-20T01:56:20.306879Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.3.0) starting as process 118
mysql     | 2025-07-20T01:56:20.368952Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
mysql     | 2025-07-20T01:56:20.985344Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql     | 2025-07-20T01:56:22.297269Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
mysql     | 2025-07-20T01:56:22.302279Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
mysql     | 2025-07-20T01:56:22.321292Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
mysql     | 2025-07-20T01:56:22.424971Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
mysql     | 2025-07-20T01:56:22.434865Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.3.0'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server - GPL.
mysql     | 2025-07-20 01:56:22+00:00 [Note] [Entrypoint]: Temporary server started.
mysql     | '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
mysql     | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
mysql     | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
mysql     | Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
myjava-1  | 2025-07-20T01:56:33.171Z  INFO 1 --- [demo1] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 8080 (http)
myjava-1  | 2025-07-20T01:56:33.342Z  INFO 1 --- [demo1] [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
myjava-1  | 2025-07-20T01:56:33.354Z  INFO 1 --- [demo1] [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.42]
myjava-1  | 2025-07-20T01:56:34.978Z  INFO 1 --- [demo1] [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
myjava-1  | 2025-07-20T01:56:35.010Z  INFO 1 --- [demo1] [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 19598 ms
myjava-1  | Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
mysql     | Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
mysql     | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
mysql     | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
mysql     |
mysql     | 2025-07-20 01:56:53+00:00 [Note] [Entrypoint]: Stopping temporary server
mysql     | 2025-07-20T01:56:53.447182Z 10 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.3.0).
myjava-1  | Get /172.18.0.3 network interface
myjava-1  | Get network interface info: name:eth0 (eth0)
myjava-1  | Initialization Sequence datacenterId:3 workerId:30
myjava-1  |  _ _   |_  _ _|_. ___ _ |    _
myjava-1  | | | |\/|_)(_| | |_\  |_)||_|_\
myjava-1  |      /               |
myjava-1  |                         3.5.12
mysql     | 2025-07-20T01:56:57.288017Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.3.0)  MySQL Community Server - GPL.
mysql     | 2025-07-20T01:56:57.293771Z 0 [System] [MY-015016] [Server] MySQL Server - end.
mysql     | 2025-07-20 01:56:57+00:00 [Note] [Entrypoint]: Temporary server stopped
mysql     |
mysql     | 2025-07-20 01:56:57+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
mysql     |
mysql     | 2025-07-20T01:56:57.544573Z 0 [System] [MY-015015] [Server] MySQL Server - start.
mysql     | 2025-07-20T01:56:58.042930Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.3.0) starting as process 1
mysql     | 2025-07-20T01:56:58.098132Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
mysql     | 2025-07-20T01:56:58.873478Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql     | 2025-07-20T01:57:00.560040Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
mysql     | 2025-07-20T01:57:00.560764Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
mysql     | 2025-07-20T01:57:00.587610Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
mysql     | 2025-07-20T01:57:00.854363Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
mysql     | 2025-07-20T01:57:00.859520Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.3.0'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
myjava-1  | 2025-07-20T01:57:02.748Z  INFO 1 --- [demo1] [           main] m.e.s.MybatisPlusApplicationContextAware : Register ApplicationContext instances org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@1722011b
myjava-1  | 2025-07-20T01:57:03.841Z  INFO 1 --- [demo1] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port 8080 (http) with context path '/'
myjava-1  | 2025-07-20T01:57:03.999Z  INFO 1 --- [demo1] [           main] org.example.demo1.Demo1Application       : Started Demo1Application in 57.681 seconds (process running for 64.939)
myjava-1  | 2025-07-20T01:57:04.313Z  INFO 1 --- [demo1] [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
myjava-1  | 2025-07-20T01:57:04.316Z  INFO 1 --- [demo1] [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
myjava-1  | 2025-07-20T01:57:04.336Z  INFO 1 --- [demo1] [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 9 ms

有关自定义镜像参考上一篇文章

docker构建springboot镜像-CSDN博客

http://www.xdnf.cn/news/15957.html

相关文章:

  • 使用pnpm安装项目的生产依赖dependencies和开发依赖devDependies及pnpm工作空间等简单使用方法说明
  • 全面解析MySQL(2)——CRUD基础
  • SQL 调优第一步:EXPLAIN 关键字全解析
  • HTTP1-HTTP2-HTTP3简要概述
  • day 12 看门狗外设
  • 运行时常量池 和 字符串常量池 区别
  • 【数据集】NOAA 全球监测实验室(GML)海洋边界层(MBL)参考简介
  • 虚拟机VMware安装国产桌面系统统信UOS
  • 传输层协议 TCP
  • 【Python数据采集】Python爬取小红书搜索关键词下面的所有笔记的内容、点赞数量、评论数量等数据,绘制词云图、词频分析、数据分析
  • docker-compose启动前后端分离项目(单机)
  • ARFoundation系列讲解 - 101 VisionPro 真机调试
  • MySQL EXPLAIN 解读
  • DAY 20 奇异值分解(SVD)
  • ant+Jmeter+jenkins接口自动化,如何实现把执行失败的接口信息单独发邮件?
  • leetcode丑数II计算第n个丑数
  • zabbix服务器告警处理
  • 【milvus检索】milvus检索召回率
  • pages.json页面路由中,globalStyle的各个属性
  • 社交圈子系统开源社交源码 / 小程序+H5+APP 多端互通的底层技术分析
  • Ubuntu 24.04 设置静态 IP 的方法
  • 对LLM某一层进行优化:通过眼动数据发现中间层注重语句内在含义,进而对中间层参数优化
  • pthread_detach与pthread_join区别及使用场景
  • 408考研逐题详解:2010年第35题——RIP协议
  • BST(二叉搜索树)的笔试大题(C语言)
  • AG32:解锁MCU+FPGA应用新姿势,功能与实战全解析
  • SQL中的EXPLAIN命令详解
  • 【Linux】权限详解 权限本质、权限属性、su、sudo提权、chmod\chown\chgrp、文件类别
  • Qt 应用程序入口代码分析
  • HarmonyOS 启动提速秘籍:懒加载全链路实战解析