Build Mysql container +Tomcat container connection environment through Docker


1. Experimental purpose: web container can access MySQL deployed in another container

2. Step 1: pull mysql image, pull command as follows:

docker pull mysql// The latest on the official website mysql for

3. Step 2: Pull tomcat image, pull command as follows:

docker pull tomcat --name xuguokun/jdk-tomcat

4. Step 3: Create 1 container of mysql with the name of mymysql. Create the command as follows:

docker run --name mymysql -p 3306:3306  -v /c/Users/xu/Desktop/mysqldata/:/usr/lib/mysql  -e MYSQL_ROOT_PASSWORD=123456 -d mysql (step 1 Pull in mysql Mirror)  

Among them:

  1. mymysql is the name of the mirror

    • v c/Users/xu/Desktop mysqldata / : / usr/lib/mysql is hanging in the container of data to the host machine
  2. MYSQL_ROOT_PASSWORD=123456 is the password of root user

  3. mysql is the mirror name of mysql < /span >

5. Step 4: Create the image of web and establish a connection with mysql. The name of the image of web is myweb.

docker run -it -p 8888:8080  myweb --link mymysql:db -d xuguokun/tomcat-jdk  

Among them:

  1. myweb is the name of the web container that was created

  2. mysql mymysql is created in step 3 the name of the vessel, can be accessed through the database, for example: jdbc_url = jdbc: mysql: / / mymysql: 3306 / mydatabasename & # 63; useUnicode = true & characterEncoding=utf8

  3. db is an alias, web access mysq data can be accessed through the program, for example jdbc_url = jdbc: mysql: / / db: 3306 / mydatabasename & # 63; useUnicode = true & characterEncoding=utf8 < /span >

  4. xuguokun/ ES108en-ES109en is the mirror name of tomcat

6. The experimental environment has been set up.