写一个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博客