欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > IT业 > 使用docker部署mysql和tomcat服务器发现的问题整理

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

2025/2/5 17:35:56 来源:https://blog.csdn.net/myfavoritey/article/details/145228577  浏览:    关键词:使用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 - GPLCopyright (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 -ADatabase 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 ~]# 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com