基于docker端口映射
[root@1 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos7.2_audit latest b56e5ebef779 5 minutes ago 2.252 GB ngjywbyg latest cc95b9673325 49 minutes ago 2.018 GB gjywbyg latest 63274623c5f1 51 minutes ago 2.018 GB centos7.4 latest 196e0ce0c9fb 4 days ago 196.6 MB centos7.2 latest 3c9d8944d9b2 5 days ago 194.6 MB [root@1 ~]# docker run -itd -p 80:8080 centos7.2_audit bash efbb1518b2db207e729c949c436f5f46a52a9283414c9831a4d9ce7e20d48119 [root@1 ~]# ss -tnlp State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* users:(("sshd",pid=982,fd=3)) LISTEN 0 100 127.0.0.1:25 *:* users:(("master",pid=1416,fd=13)) LISTEN 0 128 :::80 :::* users:(("docker-proxy-cu",pid=22258,fd=4)) LISTEN 0 100 ::1:25 :::* users:(("master",pid=1416,fd=14)) [root@1 ~]#
简述
-p 可以指定端口映射,本例中将容器的8080端口映射为本地的80端口
进入容器
[root@1 ~]# docker run -itd -p 80:8080 centos7.2_audit bash efbb1518b2db207e729c949c436f5f46a52a9283414c9831a4d9ce7e20d48119 [root@1 ~]# docker exec -it efbb1518b bash [root@efbb1518b2db /]#
开启服务
启动mysql
[root@efbb1518b2db /]# /etc/init.d/mysqld start Starting MySQL.Logging to '/data/mysql/efbb1518b2db.err'. . SUCCESS!
启动应用服务
[root@efbb1518b2db /]# cd /home/cafintech/App/audit/ [root@efbb1518b2db audit]# ll total 8 drwxr-xr-x 2 root root 65 Sep 19 04:55 bin drwxr-xr-x 2 root root 35 Sep 19 04:55 conf drwxr-xr-x 2 root root 4096 Sep 19 04:55 lib [root@efbb1518b2db audit]# ./bin/start.sh
查看端口
root@2d36536af243 cafintech]# netstat -lnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp6 0 0 :::3306 :::* LISTEN - tcp6 0 0 :::8080 :::* LISTEN 194/java Active UNIX domain sockets (only servers) Proto RefCnt Flags Type State I-Node PID/Program name Path unix 2 [ ACC ] STREAM LISTENING 27753 - /tmp/mysql.sock
给mysql设置帐号权限
设置密码
[root@2d36536af243 cafintech]# mysqladmin -uroot password '123456' Warning: Using a password on the command line interface can be insecure.
根据docker镜像主机设置登录权限
[root@2d36536af243 cafintech]# mysql -uroot -p123456 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 4 Server version: 5.6.35 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. 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> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "123456"; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye
修改审计连接数据库地址
[root@2d36536af243 conf]# pwd /home/cafintech/App/audit/conf [root@2d36536af243 conf]# vi application.properties spring.application.name=audit server.port=8080 #\u6570\u636E\u5E93\u914D\u7F6E spring.datasource.type=com.alibaba.druid.pool.DruidDataSource spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://172.18.0.2:3306/internal_tmp?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true spring.datasource.username=root spring.datasource.password=123456
重启服务
[root@2d36536af243 conf]# cd .. [root@2d36536af243 audit]# ll total 8 drwxr-xr-x 2 root root 65 Sep 19 07:37 bin drwxr-xr-x 2 root root 35 Sep 19 07:47 conf drwxr-xr-x 2 root root 4096 Sep 19 04:55 lib [root@2d36536af243 audit]# ./bin/reStart.sh stop process 194 succeed. process 314 is start ok. [root@2d36536af243 audit]# netstat -lnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp6 0 0 :::3306 :::* LISTEN - tcp6 0 0 :::8080 :::* LISTEN 314/java Active UNIX domain sockets (only servers) Proto RefCnt Flags Type State I-Node PID/Program name Path unix 2 [ ACC ] STREAM LISTENING 27753 - /tmp/mysql.sock
web页面访问测试
用你自己的宿主机进行浏览即可
http://172.17.6.253/login
继续阅读
- 我的QQ
- QQ扫一扫
-
- 我的头条
- 头条扫一扫
-
评论