Goal

Docker is one of the most popular container technology nowadays, so the purpose of this document is to illustrate how to use Docker for the Spring Boot Course Labs

Pivotal Edu Images

You can get all the images from Docker Hub: https://hub.docker.com/u/pivotaledu/

Spring Boot

This image is based on pivotaledu/base:latest. This images contains the following programs/packages:

  • OpenJDK 8 - 1.8.0_131

  • Spring Boot 2.0.0.M6 (latest)

  • Groovy 2.4.12

  • Cloud Foundry CLI 6.32

  • Maven and Gradle wrappers

Exposes from port 7000-9999

Usage

docker run --name spring-boot -it --rm pivotaledu/spring-boot bash
Tip
You can use the -p 8080:8080 to expose the port 8080 to your localhost.

Tomcat 8.5.3

This image is base from pivotaledu/java8:latest. It provides Tomcat 8.5.3

Usage

docker run -it --rm -p 8080:8080 --name tomcat8 pivotaledu/tomcat:8.5.3 /opt/tomcat/bin/catalina.sh run

If you want to copy a war to the container:

docker cp ./sample.war tomcat8:/opt/tomcat/webapps/sample.war

RabbitMQ 3.6.2

This image is base from pivotaledu/base:latest. It provides RabbitMQ 3.6.2

Default credentials:

    username: admin
    password: admin

You can use environment variables with the -e option:

    RMQ_USER
    RMQ_PASS

Usage

$ docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 pivotaledu/rabbitmq

NOTES

In the labs we are overriding a Listener and a RabbitTemplate so in order to use a custom username and password, you can package your app and the execute:

java -jar target/code-snippet-manager-amqp-0.0.1-SNAPSHOT.jar --spring.rabbitmq.username=admin --spring.rabbitmq.password=admin

Or another alternative is that we can add also a ConnectionFactory:

@Bean
public ConnectionFactory connectionFactory(RabbitProperties props){
    CachingConnectionFactory cf = new CachingConnectionFactory();
    cf.setUsername(props.getUsername());
    cf.setPassword(props.getPassword());
    return cf;
}

then you can add this to your application.properties

spring.rabbitmq.username=admin
spring.rabbitmq.password=admin

MySQL (MariaDB)

This image is base from pivotaledu/base:latest. It provides MariaDB 10.1.26.

Defautl credentials:

    user: root
    password: pivotal

You can add this environment variables with the -e option:

    MYSQL_DATABASE
    MYSQL_USER
    MYSQL_PASSWORD
    MYSQL_ROOT_PASSWORD

Usage

docker run -d -p 3306:3306 --name mysql pivotaledu/mariadb

NOTES:

If using a local mysql client, is necessary to add the --protocol=TCP

Example:

mysql --protocol=TCP -uroot -p

Redis 4.0.2

This image base from pivotaledu/base:latest. It provides Redis 4.0.2 server.

Usage

docker run -d --name redis -p 6379:6379 pivotaledu/redis:4.0.2