I am using docker-compose.yml to build my enviroment.
docker-compose.yml
version: '3'
services:
mysql:
image: mysql:5.5
container_name: mysql
restart: always
environment:
MYSQL_DATABASE: my-test-app
MYSQL_ROOT_PASSWORD: root
volumes:
- ./docker/db:/docker-entrypoint-initdb.d
ports:
- "3306:3306"
tomcat:
image: tomcat:8.5.35
container_name: tomcat
volumes:
- ./docker/myapp.war:/usr/local/tomcat/webapps/myapp.war
ports:
- "8080:8080"
My folder structore
my-env
├── docker-compose.yml
├── docker
├── myapp.war
├── db
├── DB_INIT.SQL
DB_INIT.SQL
CREATE TABLE EMPLOYEE (
EMPLOYEE_ID BIGINT(20) NOT NULL AUTO_INCREMENT,
NAME VARCHAR(65) NOT NULL,
DOB DATETIME DEFAULT NULL,
GENDER VARCHAR(10) NOT NULL,
MOBILE VARCHAR(65) DEFAULT NULL,
EMAIL VARCHAR(60) DEFAULT NULL,
PRIMARY KEY (EMPLOYEE_ID)
) ENGINE=INNODB DEFAULT CHARSET=UTF8MB4;
INSERT INTO EMPLOYEE (NAME, DOB, GENDER, MOBILE, EMAIL) VALUES ("Aung Ko Tint", '1986-12-02', 'MALE', '09458682152', 'aungko@demo.com');
INSERT INTO EMPLOYEE (NAME, DOB, GENDER, MOBILE, EMAIL) VALUES ("Hein Thu", '1990-10-25', 'MALE', '0942562871', 'mthk@demo.com');
INSERT INTO EMPLOYEE (NAME, DOB, GENDER, MOBILE, EMAIL) VALUES ("Arr Yone", '1991-12-15', 'MALE', '0942255023', 'hwyk@demo.com');
After running this commend docker-compose up
,
My docker-machine ip is 192.168.99.100
. I can access http://192.168.99.100:8080
of tomcat, but I cannot acess my app http://192.168.99.100:8080/myapp
. It was 404
.
I can access docker's mysql
from my host by using MySQL Work Branch
. In MySQL Work Branch
, I see my-test-app
database. but There is no EMPLOYEE
table.
Tomcat & Mysql are successfuly install. But my war
and init sql script
are not OK. Is there any missing config in my docker-compose.yml
For the Database:
Maybe you run in the same problem as described here: https://stackoverflow.com/a/36348572/8221303
1. At first run this to delete the current containers:
docker-compose rm -vf
2. Remove database name from compose file.
3. Modify your database creation file like this:
CREATE DATABASE `my-test-app`;
USE my-test-app;
CREATE TABLE EMPLOYEE (
EMPLOYEE_ID BIGINT(20) NOT NULL AUTO_INCREMENT,
NAME VARCHAR(65) NOT NULL,
DOB DATETIME DEFAULT NULL,
GENDER VARCHAR(10) NOT NULL,
MOBILE VARCHAR(65) DEFAULT NULL,
EMAIL VARCHAR(60) DEFAULT NULL,
PRIMARY KEY (EMPLOYEE_ID)
) ENGINE=INNODB DEFAULT CHARSET=UTF8MB4;
INSERT INTO EMPLOYEE (NAME, DOB, GENDER, MOBILE, EMAIL) VALUES ("Zaw Than Oo", '1986-12-02', 'MALE', '09420000773', 'zawthanoo@cycdemo.com');
INSERT INTO EMPLOYEE (NAME, DOB, GENDER, MOBILE, EMAIL) VALUES ("Myo Thiha Kyaw", '1990-10-25', 'MALE', '0942568971', 'mthk@cycdemo.com');
INSERT INTO EMPLOYEE (NAME, DOB, GENDER, MOBILE, EMAIL) VALUES ("Htet Wai Yan Kyaw", '1991-12-15', 'MALE', '0942025023', 'hwyk@cycdemo.com');
4. Run Docker-Compose again. When the containers are starting you should see something like this in the stdout:
/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/DB_INIT.sql
For the Tomcat:
Maybe your application does not run because of the DB problem. But if not you can try the following:
At first check if the WAR file is deployed correctly. Connect to the container bash via:
docker exec -it tomcat bash
Check if there is the war file with the deployed one in the webapps directory:
/usr/local/tomcat/webapps/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.