使用docker部署mysql和tomcat服务器发现的问题整理

1、本地访问tomcat时访问不到

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE       COMMAND                   CREATED        STATUS          PORTS                                                                NAMES
8bf430c86754   mysql:5.7   "docker-entrypoint.s..."   21 hours ago   Up 12 minutes   3306/tcp, 33060/tcp, 0.0.0.0:32768->33506/tcp, :::32768->33506/tcp   mysql001
0444152863f2   tomcat:9    "catalina.sh run"         21 hours ago   Up 12 minutes   0.0.0.0:80->8080/tcp, :::80->8080/tcp                                tomcat001
[root@localhost ~]# docker exec -it 0444152863f2 /bin/bash
root@0444152863f2:/usr/local/tomcat# cd webapps
root@0444152863f2:/usr/local/tomcat/webapps# ls -l
total 0
root@0444152863f2:/usr/local/tomcat/webapps# cd ..
root@0444152863f2:/usr/local/tomcat# cp -r webapps.dist/* ./webapps
root@0444152863f2:/usr/local/tomcat# rm -rf webapps.dist
root@0444152863f2:/usr/local/tomcat# 

2、docker部署mysql8.0病开启远程访问

[root@localhost ~]# docker pull mysql:8.0
8.0: Pulling from library/mysql
2c0a233485c3: Pull complete 
b746eccf8a0b: Pull complete 
570d30cf82c5: Pull complete 
c7d84c48f09d: Pull complete 
e9ecf1ccdd2a: Pull complete 
6331406986f7: Pull complete 
f93598758d10: Pull complete 
6c136cb242f2: Pull complete 
d255d476cd34: Pull complete 
dbfe60d9fe24: Pull complete 
9cb9659be67b: Pull complete 
Digest: sha256:d58ac93387f644e4e040c636b8f50494e78e5afc27ca0a87348b2f577da2b7ff
Status: Downloaded newer image for mysql:8.0
docker.io/library/mysql:8.0
[root@localhost ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
tomcat        9         f05fe3cd4f92   11 days ago     470MB
mysql         8.0       6c55ddbef969   3 months ago    591MB
mysql         5.7       5107333e08a8   13 months ago   501MB
hello-world   latest    d2c94e258dcb   20 months ago   13.3kB
[root@localhost ~]# docker run -di --name=mysql002 -p 33506:3306 -e MYSQL_ROOT_PASSWORD=123456 docker.io/mysql:8.0
cb20831541f02ad140340c7b89a622e73eeab6341e9009bc4a8450de8a360f3e
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE         COMMAND                   CREATED          STATUS                       PORTS                                                    NAMES
cb20831541f0   mysql:8.0     "docker-entrypoint.s..."   11 seconds ago   Up 10 seconds                33060/tcp, 0.0.0.0:33506->3306/tcp, :::33506->3306/tcp   mysql002
64257bbaf82d   mysql:5.7     "docker-entrypoint.s..."   22 hours ago     Exited (0) 3 minutes ago                                                              mysql001
0a4499668709   tomcat:9      "catalina.sh run"         23 hours ago     Exited (143) 3 minutes ago                                                            tomcat001
c469af5214b2   hello-world   "/hello"                  23 hours ago     Exited (0) 23 hours ago                                                               lucid_colden
[root@localhost ~]# docker exec -it cb20831541f0 bash
bash-5.1# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.40 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

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> cb20831541f0
    -> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'cb20831541f0' at line 1
mysql> create database zrlog;
Query OK, 1 row affected (0.00 sec)

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.01 sec)

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select user,host,plugin from user where user='root';
+------+-----------+-----------------------+
| user | host      | plugin                |
+------+-----------+-----------------------+
| root | %         | caching_sha2_password |
| root | localhost | mysql_native_password |
+------+-----------+-----------------------+
2 rows in set (0.00 sec)

mysql> alter user 'root'@'%' identified by 'password' password expire never;
Query OK, 0 rows affected (0.00 sec)

mysql> alter user 'root'@'%' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host,plugin from user where user='root';
+------+-----------+-----------------------+
| user | host      | plugin                |
+------+-----------+-----------------------+
| root | %         | mysql_native_password |
| root | localhost | mysql_native_password |
+------+-----------+-----------------------+
2 rows in set (0.00 sec)

mysql> select user,host,plugin from user where user='root';
+------+-----------+-----------------------+
| user | host      | plugin                |
+------+-----------+-----------------------+
| root | %         | mysql_native_password |
| root | localhost | mysql_native_password |
+------+-----------+-----------------------+
2 rows in set (0.00 sec)

mysql> exit
Bye
bash-5.1# exit
exit
[root@localhost ~]# 
相关推荐
寒山李白1 小时前
MySQL union和union all
java·数据库·sql·mysql
二哈喇子!1 小时前
MySQL中的GROUP_CONCAT函数将分组后的多个行值合并成一个字符串,并用指定分隔符连接
数据库·mysql
Run Out Of Brain2 小时前
MySQL程序之:使用DNS SRV记录连接到服务器
mysql
兵bing2 小时前
mysql的mvcc
数据库·mysql
丁乾坤的博客3 小时前
function isBulkReadStatement, file SQLiteDatabaseTracking.cpp
mysql·xcode16·ios18闪退
张3蜂4 小时前
Ubuntu安装docker
ubuntu·docker·eureka
计算机学姐5 小时前
基于微信小程序的手机银行系统
java·vue.js·spring boot·mysql·微信小程序·小程序·intellij-idea
小菜日记^_^5 小时前
苍穹外卖项目总结(二)
java·spring boot·spring·tomcat·maven·mybatis·postman
m0_674031435 小时前
docker离线安装及部署各类中间件(x86系统架构)
docker·中间件·系统架构