This docker image is intended to be used in Bitbucket Pipelines where we can do full integration tests on application (from backend to database).
This image contains:
- JDK 8u91
- Maven 3.3.3
- MariaDB 10.1
Bitbucket Pipelines doesn't support multiple (linking) containers on commit, so we need single container that can give us proper technology basics where we can do all our tests.
Currently we are mostly working with Java (JDK8) environment, using Maven to do builds (tests), and MariaDB for database.
Look below for sample bitbucket-pipelines.yml
file on how to use this image.
On the first look it might seem crazy to combine "full stack" in signle Docker image. Main idea behind Docker containers is to split responsabilities so application would have its own container and database would have separate containser. So, why would anybody have container to mix app and database?
Bitbucket is introducing new feature Pipelines, still in beta phase, that enables you to run docker containers on bitbucket with every commit and test your code in container.
Problem with current stage of Pipelines feature is that it doesn't support linking (multiple) containers. So for all our testing - we can only use one container - hence this image is created to contain all technologies that we use (JDK8, Maven, MariaDB).
This image is blatant rip-off and merge of several official Docker images
Big thanks to authors of these images for sharing their work!
- MariaDB Docker - Official MariaDB Docker page
- MariaDB GitHub - Official Docker MariaDB GitHub repository
- Maven Docker - Official Maven Docker page
- Maven GitHub - Official Docker Maven GitHub repository
- Java/JDK Docker - Official Java Docker page
- Java/JDK GitHub - Official Docker Java GitHub repository
MariaDB is exposing port 3306
so when running container if you want to use database you should make proper port mapping.
When running container you can use several environment variables (expected by docker-entrypoint.sh
script):
MYSQL_ROOT_PASSWORD
- this will set root password of databaseMYSQL_DATABASE
- this will create database schema with provided nameMYSQL_USER
,MYSQL_PASSWORD
- with these variables you can setup user that will have grants on database created usingMYSQL_DATABASE
. If you already provided root password, then you don't need to specify these variablesMYSQL_ALLOW_EMPTY_PASSWORD
- set this variable toyes
if you don't want to be bothered with root password (not recommended!)
In order to even start using Bitbucket Pipelines you must have bitbucket-pipelines.yml
file in root of your repository - official instructions on how to configure Bitbucket Pipelines.
Sample yml file:
image:
name: lukastosic/maven-mariadb:1.2
MYSQL_ROOT_PASSWORD: provide_root_password
MYSQL_DATABASE: provide_database_name
pipelines:
default:
- step:
script:
- mvn --version
- mvn clean test
In this sample we have used 2 database parameters described above. You can use other parameters, or you can use environment variables from Bitbucket - more info about environment variables
For complete instructions on how to use Docker container you can refer to MariaDB Docker page.
Running with specified root password
docker run --name my_container_name -e MYSQL_ROOT_PASSWORD=my_password -d lukastosic/maven-mariadb:1.2
Running with specified database and username/password
docker run --name my_cintainer_name -e MYSQL_DATABASE=init_database -e MYSQL_USER=my_user -e MYSQL_PASSWORD=my_password -d lukastosic/maven-mariadb:1.2
I'm not sure why would you want to do this, since image is available as public repo so you can just pull
the image, but if you really want to play:
- download this repository to some folder
- navigate to folder where you downloaded this repository
- execute
docker build -t image_name:tag .