我试图使用Docker将使用Hibernate,XAMPP for Apache tomcat和mysql服务器的Windows应用程序移植到Linux上。
在我完成以下步骤后,我的web.app的第一个功能是登录/注册表单:在Windows上一切正常,但是容器有几十分钟的延迟..有时候有还有500个http错误!!
docker run -d --name mysql-phpmyadmin -p 127.0.0.1:8686:80 -p 127.0.0.1:3306:3306 grzesiekb/mysql-phpmyadmin
docker run -d -p 8484:8080 -p 8007:8009 --name tomcat8-linked --link mysql-phpmyadmin:mysqlphp tomcat:8.0-jre8
然后在webapps /文件夹下部署我的warfile
在我的hibernate.cfg.xml中,您可以看到它here(我有问题以可查看的方式粘贴它):)
在我的mysql容器my.cnf中有:
[客户] port = 3306 socket = /var/run/mysqld/mysqld.sock
# Here is entries for some specific programs # The following values assume you have at least 32M ram # This was formally known as [safe_mysqld]. Both versions are currently parsed. [mysqld_safe] socket = /var/run/mysqld/mysqld.sock nice = 0 [mysqld] # # * Basic Settings # user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp lc-messages-dir = /usr/share/mysql skip-external-locking # # Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. bind-address = 0.0.0.0 # # * Fine Tuning # key_buffer = 16M max_allowed_packet = 16M thread_stack = 192K thread_cache_size = 8 # This replaces the startup script and checks MyISAM tables if needed # the first time they are touched myisam-recover = BACKUP #max_connections = 100 #table_cache = 64 #thread_concurrency = 10 # # * Query Cache Configuration # query_cache_limit = 1M query_cache_size = 16M # # * Logging and Replication # # Both location gets rotated by the cronjob. # Be aware that this log type is a performance killer. # As of 5.1 you can enable the log at runtime! general_log_file = /var/log/mysql/mysql.log general_log = 1 # # Error log - should be very few entries. # log_error = /var/log/mysql/error.log # # Here you can see queries with especially long duration #slow_query_log_file = /var/log/mysql/mysql-slow.log #slow_query_log = 1 #long_query_time = 2 #log_queries_not_using_indexes # # The following can be used as easy to replay backup logs or for replication. # note: if you are setting up a replication slave, see README.Debian about # other settings you may need to change. #server-id = 1 #log_bin = /var/log/mysql/mysql-bin.log expire_logs_days = 10 max_binlog_size = 100M #binlog_do_db = include_database_name #binlog_ignore_db = include_database_name # * InnoDB # # InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. # Read the manual for more InnoDB related options. There are many! # # * Security Features # # Read the manual, too, if you want chroot! # chroot = /var/lib/mysql/ # # For generating SSL certificates I recommend the OpenSSL GUI "tinyca". # # ssl-ca=/etc/mysql/cacert.pem # ssl-cert=/etc/mysql/server-cert.pem # ssl-key=/etc/mysql/server-key.pem [mysqldump] quick quote-names max_allowed_packet = 16M [mysql] #no-auto-rehash # faster start of mysql but no tab completition [isamchk] key_buffer = 16M # # * IMPORTANT: Additional settings that can override those from this file! # The files must end with '.cnf', otherwise they'll be ignored. # !includedir /etc/mysql/conf.d/
默认情况下,这个mysql容器只允许来自localhost的连接:为了允许来自任何地方的连接,我已经完成了:
在上授予所有权限。以及' root' @'%'通过'密码识别' WITH GRANT OPTION; FLUSH PRIVILEGES;
然后我通过phpmyadmin
导入了我的dql转储描述您收到的结果:
巨大的延迟,与我不知道哪个问题有关,并且以随机的方式无法连接到mysql。没有日志。我的老师说这可能是与Docker网络相关的DNS问题。
描述您期望的结果:
立即连接到数据库,就像使用XAMPP的Windows
一样答案 0 :(得分:1)
您应该尽量使您的设置成为标准,以避免因非标准做法而导致的错误。
使用官方或至少受欢迎的图片(有数百万次拉动)代替你的mysql-phpmyadmin,数百次拉动:
我不确定你为什么用主机端口和容器端口声明ip,如果没有必要就不要这样做,只发布主机端口和容器端口,而不是IP
不要使用--link,因为它是deprecated,创建一个桥接网络并使用--network my-bridge-network运行每个容器。
< / LI>使用最新的&#34; HWE&#34;将您的Ubuntu升级到最新的LTS版本(16.04.2)。此LTS版本的内核(您必须使用单独的命令升级内核,如here所述:sudo apt-get install --install-recommends xserver-xorg-hwe-16.04