[root@localhost my_war_project]# docker run -it -d -P mytomcat02:1.0 6f93d2a73e53651572c301143d46a70f1b1c46548766b9710123adb344256870
宿主机对外端口为32700
1 2 3
[root@localhost my_war_project]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6f93d2a73e53 mytomcat02:1.0 "/bin/sh -c 'bin/s..." 2 minutes ago Up 2 minutes 0.0.0.0:32770->8080/tcp hardcore_lichterman
[root@localhost my_war_project]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0adc13b5b8de ae0658fdbad5 "docker-entrypoint..." 10 seconds ago Up 10 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysql-5.7
[root@localhost my_war_project]# docker exec -it 0adc13b5b8de /bin/bash root@0adc13b5b8de:/# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)