使用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 ~]# 
相关推荐
钊兵18 分钟前
数据库驱动免费下载(Oracle、Mysql、达梦、Postgresql)
数据库·mysql·postgresql·oracle·达梦·驱动
隔壁老王1562 小时前
mysql实时同步到es
数据库·mysql·elasticsearch
努力的小T2 小时前
使用 Docker 部署 Apache Spark 集群教程
linux·运维·服务器·docker·容器·spark·云计算
东风微鸣4 小时前
TTRSS 迁移实战
docker·云原生·kubernetes·可观察性
Hanson Huang5 小时前
【存储中间件API】MySQL、Redis、MongoDB、ES常见api操作及性能比较
redis·mysql·mongodb·es
LUCIAZZZ5 小时前
EasyExcel快速入门
java·数据库·后端·mysql·spring·spring cloud·easyexcel
yuanbenshidiaos5 小时前
【正则表达式】
数据库·mysql·正则表达式
转身後 默落6 小时前
04.Docker 镜像命令
docker·容器·eureka
IT_张三6 小时前
Docker+Kubernetes_第一章_Docker入门
java·docker·kubernetes