04/20/2015: Running Spring Boot inside Docker
This is another in my series of very short entries about Docker. I've been working to not install maven on my development laptop. But I still want to use spring-boot:run to launch my applications. Here is the Docker command I am using. Notice the server.port is specified on the command line so that I can change it as needed.
-it \
--rm \
-p 8090:8090 \
-e server.port=8090 \
--link artifactory:artifactory \
--link mysql:mysql \
-v "$PWD/m2":/root/.m2 \
-v "$PWD":/usr/src/mymaven \
-w /usr/src/mymaven \
maven:3.3-jdk-8 \
mvn spring-boot:run
The MySQL container was started like this:
docker run \
--name mysql \
-p 3306:3306 \
-v /data/mysql:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=password \
-e MYSQL_DATABASE=docker \
-e MYSQL_USER=docker \
-e MYSQL_PASSWORD=password \
-d \
mysql/mysql-server:5.5
docker run \
-it \
--rm \
-p 8090:8090 \
-e server.port=8090 \
--link artifactory:artifactory \
--link mysql:mysql \
-v "$PWD/m2":/root/.m2 \
-v "$PWD":/usr/src/mymaven \
-w /usr/src/mymaven \
maven:3.3-jdk-8 \
mvn spring-boot:run
The MySQL container was started like this:
docker run \
--name mysql \
-p 3306:3306 \
-v /data/mysql:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=password \
-e MYSQL_DATABASE=docker \
-e MYSQL_USER=docker \
-e MYSQL_PASSWORD=password \
-d \
mysql/mysql-server:5.5
04/20/2015: Running Maven inside Docker.
I recently reinstalled Ubuntu on my zareason laptop. As I was thinking about installing my development tools, I thought about how to integrate Docker into the process. Below I show how simple using the Maven container can be:
* Create an alias to the Maven container.
alias mvn="docker run \
-it \
--rm \
--name my-maven-project \
-v "$PWD":/usr/src/mymaven \
-w /usr/src/mymaven \
maven:3.3-jdk-8 \
mvn"
* Clone my ragnvald Java project.
git clone git@github.com:medined/ragnvald.git
* cd ragnvald
* Package the project.
mvn package
That's it. You're using Maven without installing onto your laptop! The results of the compilation are placed into the target directory.
If you need to specify a Maven settings.xml file that's fairly easy as well. Simply create it alongside the pom.xml file. Then slightly modify your alias:
alias mvn="docker run \
-it \
--rm \
--name my-maven-project \
-v "$PWD":/root/.m2 \
-v "$PWD":/usr/src/mymaven \
-w /usr/src/mymaven \
maven:3.3-jdk-8 \
mvn"
The ragnvald project goes one step farther to use an Artifactory container so that I can use the Artifactory web interface if needed. That's quite convenient!
* Create an alias to the Maven container.
alias mvn="docker run \
-it \
--rm \
--name my-maven-project \
-v "$PWD":/usr/src/mymaven \
-w /usr/src/mymaven \
maven:3.3-jdk-8 \
mvn"
* Clone my ragnvald Java project.
git clone git@github.com:medined/ragnvald.git
* cd ragnvald
* Package the project.
mvn package
That's it. You're using Maven without installing onto your laptop! The results of the compilation are placed into the target directory.
If you need to specify a Maven settings.xml file that's fairly easy as well. Simply create it alongside the pom.xml file. Then slightly modify your alias:
alias mvn="docker run \
-it \
--rm \
--name my-maven-project \
-v "$PWD":/root/.m2 \
-v "$PWD":/usr/src/mymaven \
-w /usr/src/mymaven \
maven:3.3-jdk-8 \
mvn"
The ragnvald project goes one step farther to use an Artifactory container so that I can use the Artifactory web interface if needed. That's quite convenient!