This is a project for testing without affecting the source code of other projects. Both the application and the mysql can be accessed in the local machine and the container, and all changes will be synchronized at the same time.
For example, the following can be both accessed in the container and the local machine.
- Source code of this project (local:
.
, container:/app
) - Dependencies used in this project (managed by maven, local:
/User/${USERNAME}/.m2
, container:/root/.m2
) - Mysql Database (local:
localhost:13306
, container:localhost:3306
, see Mysql)
Warning! Stay alert to your path while executing docker commands.
You must execute all docker commands under this project directory.
Clone this project to your local machine, do NOT clone this project in the work
folder!
git clone https://github.com/tszyaul6/playground-java.git
cd into the project root directory, and build the containers
docker compose up --build -d
Get inside the container, use maven to install and run the project
docker exec -it playground bash
mvn clean install
Finally, start the application
java -jar target/*.jar
... and your application should be up and running at http://localhost:18080/
If you would like to connect to the mysql, run
docker exec -it playground_mysql mysql -uroot -psecret
... or you may connect to the mysql with any GUI (e.g. HeidiSQL, DBeaver) using localhost with port 13306
After finish testing code in the project, you can remove the containers
docker compose down
or
docker compose down -v
(Note that using -v flag will remove the volumes, which all data in the database will be removed.)