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

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.dtcms.com/a/289140.html

相关文章:

  • 使用pytorch创建模型时,nn.BatchNorm1d(128)的作用是什么?
  • gradle关于dependency-management的使用
  • SpringBoot 整合 Langchain4j 实现会话记忆存储深度解析
  • OpenCV 入门知识:图片展示、摄像头捕获、控制鼠标及其 Trackbar(滑动条)生成!
  • 【LeetCode刷题指南】--反转链表,链表的中间结点,合并两个有序链表
  • Day25| 491.递增子序列、46.全排列
  • SQL Server(2022)安装教程及使用_sqlserver下载安装图文
  • redis-plus-plus安装与使用
  • [BUG]关于UE5.6编译时出现“Microsoft.MakeFile.Targets(44,5): Error MSB3073”问题的解决
  • 30天打牢数模基础-SVM讲解
  • Facebook 开源多季节性时间序列数据预测工具:Prophet 快速入门 Quick Start
  • UE5多人MOBA+GAS 26、为角色添加每秒回血回蓝(番外:添加到UI上)
  • Go并发聊天室:从零构建实战
  • Mysql(事务)
  • 30个常用的Linux命令汇总和实战场景示例
  • 30天打牢数模基础-粒子群算法讲解
  • 详解Mysql索引合并
  • Jetpack - ViewModel、LiveData、DataBinding(数据绑定、双向数据绑定)
  • langchain调用本地ollama语言模型和嵌入模型
  • 梯度提升之原理
  • COGNEX康耐视IS5403-01智能相机加Navitar 18R00 LR1010WM52镜头
  • React 英语打地鼠游戏——一个寓教于乐的英语学习游戏
  • [Windows] Bili视频转图文笔记 v1.7.5
  • 网鼎杯2020青龙组notes复现
  • 7. 命令模式
  • Modbus Slave 使用教程:快速搭建模拟从站进行测试与开发
  • Ribbon轮询实现原理
  • Unity笔记——Unity 封装方法指南
  • day24——Java高级技术深度解析:单元测试、反射、注解与动态代理
  • [Python] -项目实战类3- 用Python制作一个记事本应用