使用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 ~]# 
相关推荐
朝新_6 分钟前
【MySQL】第三弹——表的CRUD进阶(一)数据库约束
数据库·mysql
搬砖的工人25 分钟前
Docker环境下的Apache NiFi安装实践踩坑记录
docker·容器·apache
Eternity......2 小时前
spark MySQL数据库配置
数据库·mysql·spark
脑子慢且灵2 小时前
MySQL:关系模型的基本理论
数据库·sql·mysql
敲上瘾3 小时前
MySQL基本查询
数据库·mysql·数据库开发·数据库架构·数据库系统
猴子请来的逗比4893 小时前
tomcat与nginx之间实现多级代理
java·nginx·tomcat
QX_hao4 小时前
【docker】--镜像管理
运维·docker·容器
敲上瘾4 小时前
MySQL数据库表的约束
linux·数据库·sql·mysql·数据库开发·数据库架构·数据库系统
努力的搬砖人.4 小时前
SQLite 转换为 MySQL 数据库
数据库·mysql·sqlite
2301_803297754 小时前
Shell编程值正则表达式和文本处理器
数据库·mysql·正则表达式