docker tomcat container and mounting the container mysql

1. docker pull mysql:5.6

2.docker run -p 3306:3306 --name mysql -v /data/mysql/conf:/etc/mysql/conf.d -v /data/mysql/logs:/logs -v /data/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=12345678 -d mysql:5.6

Explanation:

Note that the host / data / mysql / conf or data or logs can not be created in advance, after executing the above statement, it will automatically created

Command Description:
-p 12345: 3306: 12345 maps the host port 3306 to port docker container.
--name mysql: run the service name
-v /data/mysql/conf:/etc/mysql/conf.d: the conf / my.cnf under the host / data / mysql record container mounted to the / etc / mysql / the conf.d
-v / data / mysql / logs: / logs: the host logs directory / data / mysql directory is mounted to the container / logs.
-v / data / mysql / data: / var / lib / mysql: a data directory of the host / data / mysql directory is mounted to the container / var / lib / MySQL
-e MYSQL_ROOT_PASSWORD = 12345678: initializing the root password.
-d mysql: 5.6: daemon running mysql5.6

3. Create my.cnf vi / data / mysql / conf under the host / data / mysql / conf directory

Which reads:

links=0

 

lower_case_table_name=1

character-set-server=utf8

collation-server=utf8_general_ci

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

 

log-slow-queries=/var/log/mysqllog/myslow.log

long_query_time=1

Mysql this container is created, you can use a remote connection nvcat, Ali cloud cloud services need to open ports 0.0.0.0/0 your own specified above

Docker docker id need to find the address of mysql container by container inspect mysql command:

 

 

docker create tomcat container:

1.docker pull tomcat:7

Modify war package related to the address database, port, database name

2.docker run --name tomcaties -p 9080:8080 -v /usr/local/ies.war:/usr/local/tomcat/webapps/ies.war tomcat:7

The first one is exposed outside of tomcat port (for api access) is behind the war package, we need to spread to / usr / local / folder

 

Id container vessel can view the log by docker logs -f -t

 

 

 

Guess you like

Origin www.cnblogs.com/zhangshitong/p/11094494.html