使用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 ~]# 
相关推荐
逢君学术论文AI写作7 分钟前
Java第21课:JavaWeb入门——Tomcat+第一个Servlet
java·servlet·tomcat
就叫_这个吧9 分钟前
Java使用tomcat+servlet+filter实现简单的登录功能,需先登录再进行页面数据管理操作
java·开发语言·servlet·tomcat·jsp·filter
川石课堂软件测试18 分钟前
UI自动化测试|下拉选择框&弹出框&滚动条操作实践
开发语言·python·jmeter·ui·docker·单元测试·harmonyos
“码”力全开19 分钟前
统一解耦海量设备:基于 Docker 与边缘计算的 GB28181/RTSP 视频中台全协议兼容架构解析(附源码交付)
docker·音视频·边缘计算
峥无20 分钟前
MySQL 最全数据类型详解(数值/字符串/日期/枚举集合)
数据库·mysql
sbjdhjd21 分钟前
Tomcat(下) 集群高可用实战:反向代理・负载均衡・分布式 Session
运维·前端·云原生·开源·tomcat·负载均衡·memcached
liux352826 分钟前
Namespace 多租户隔离:K8s 资源管理的基石
docker·容器·kubernetes
Amnesia0_032 分钟前
MySQL的访问和数据流动
数据库·mysql
Arbori_2621536 分钟前
找回mysql root 密码
数据库·mysql
ejinxian3 小时前
PolarDB ,MongoDB ,MySQL ,PostgreSQL ,Redis, OceanBase, Sql Server等数据库
数据库·mysql·mongodb