Docker Image Library

A curated list of Docker images useful for Java developers; look for the image you want to setup on Docker and follow the steps. Before you follow the instructions, make sure your Docker is running on the computer.

Jenkins

1

Pull Jenkins image from Docker Hub

$ docker pull jenkins/jenkins:lts-jdk11

2

Run newly downloaded Jenkins image

$ docker run -d --name jenkins -p 8085:8080 -v E:/code/docker_volume/jenkins:/var/jenkins_home jenkins/jenkins:lts-jdk11

-d Runs container in background
--name This container will run under the name of ‘jenkins’
-p 8080 is default Jenkins port and we are mapping to 8085 on the local host
-v Configured Volume to store Jenkins job information, so next time we restart, we will see all previous ran jobs in history

3

Verify if Jenkins started properly. Execute Docker log command to view Jenkins logs and check if the log ends with something like this; Jenkins is fully up and running

$ docker container logs jenkins

4

Access Jenkins console using the browser;   http://localhost:8085
It is the first time we accessed the Jenkins console, so it prompts us to enter a password. Jenkin writes an initial password to a file. This password file path is /var/jenkins_home/secrets/initialAdminPassword

5

Retrieve the password by accessing the container’s bash.

$ docker container exec -it jenkins /bin/bash

Read password from file; /var/jenkins_home/secrets/initialAdminPassword

$ cat /var/jenkins_home/secrets/initialAdminPassword

Copy the output

6

Paste it in the password field on the Jenkins login page, then click on Continue. Jenkins will redirect us to the Plugin installation page. Click on Suggested Plugin Option to install default plugins. It will take a couple of minutes, and then it will take us to the user’s page, create an admin user so next time you can use these credentials to login Jenkins console.

7

Now we have our Jenkins running on the Docker.

Use this   Docker CLI cheat sheet to refer Docker CLI commands.

MySQL

1

Pull MySQL image from Docker Hub

$ docker pull mysql:8.0.22

2

Run newly downloaded MySQL image

$ docker run -d --name mysql -p 2306:3306 -e MYSQL_ROOT_PASSWORD=secret-pw -v E:/code/docker_volume/mysql:/var/lib/mysql mysql:8.0.22

-d Runs container in background
--name This container will run under the name of ‘mysql’
-p 3306 is MySQL’s default port, so we are mapping it to 2306 on the local host
-e Pass initial password for the admin user -v Configure volume so that MySQL can store data

3

Verify if MySQL started properly by checking the last line in the log, which says something like this; ready for connections

$ docker container logs mysql

4

Use any MySQL client to verify if connection is succesfull.
Here I used MySQL CLI client to verify the connection. From the terminal, execute the below command;

$ mysql -uroot -psecret-pw -h localhost -P 2306

If the connection is a success, then we get an SQL prompt.

5

Now we have our MySQL running on the Docker.

MongoDB

1

Pull Mongo image from Docker Hub

$ docker pull mongo:latest

2

Run newly downloaded Mongo image

$ docker run -d --name mongo -p 27017:27017 -v E:/code/docker_volume/mongo:/data/db mongo:latest

-d Runs container in background
--name This container will run under the name of ‘mongo’
-p Mongo uses 27017 as default port, so we are mapping to 27017 on the local host
-v We configured volume, so Mongo will use this space to store data

3

Verify if Mongo started properly by checking the logs, you should see a line saying Waiting for connections

$ docker container logs mongo

4

Access bash of Mongo container by executing command

$ docker container exec -it mongo /bin/bash

Now access Mongo shell by executing below command; this will connect to local mongo at port 27017

$ mongo -host localhost -port 27017

If you see Mongo prompt, then the connection is successfull and Mongo DB is up.

5

We have our Mongo DB running on the Docker.

Use this   Docker CLI cheat sheet to refer Docker CLI commands.

ActiveMQ

1

Pull ActiveMQ image from Docker Hub

$ docker pull rmohr/activemq:5.15.9-alpine

Note: This is not an official image. I didn’t found any official ActiveMQ image on Docker Hub, but I found instructions to create one on the ActiveMQ website. Click  here for the instructions.

2

Run newly downloaded ActiveMQ image

$ docker run -d --name activemq -p 61616:61616 -p 8161:8161 -v E:/code/docker_volume/activemq/conf:/opt/activemq/conf -v E:/code/docker_volume/activemq/data:/opt/activemq/data rmohr/activemq:5.15.9-alpine

-d Runs container in background
--name This container will run under the name of ‘activemq’
-p ActiveMQ uses 61616 and 8161 as default ports, so we are mapping same ports on the local host
-v Configured volume for ‘conf’ and ‘data’ folders, so data will be available on the next startup.
NOTE: Make sure to replace E:/code/docker_volume/activemq/* folder with the path according to your local.

3

Provide a default configuration. ActiveMQ expects default configuration files in the /opt/activemq/conf folder. It will be empty by default so we will see errors in the ActiveMQ startup logs. To fix this, click here to download the default configuration, then extract and copy it to your local conf folder (which is E:/code/docker_volume/activemq/conf in above case).

4

Start ActiveMQ by executing below command

$ docker container start activemq

Now access ActiveMQ logs to check if there are no errors.

$ docker container logs activemq

Make sure no errors in the log.

5

Access ActiveMQ console by going to   http://localhost:8161/admin

Provide default admin credentials; username: admin and password: admin

6

We have our ActiveMQ running on the Docker.

MariaDB

1

Pull MariaDB image from Docker Hub

$ docker pull mariadb:10.5

2

Run newly downloaded MariaDB image

$ docker run -d --name mariadb -p 3310:3306 -v E:/code/docker_volume/mariadb:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=secret-pw mariadb:10.5

-d Runs container in background
--name This container will run under the name of ‘mariadb’
-p MariaDB listens on 3306 port and I mapped it to 3310 on the local host
-v Configured volume to store data on local host, so data will be available on the next startup.
NOTE: Make sure to replace E:/code/docker_volume/mariadb folder with the path according to your local.

3

Verify MariaDB logs to check if there are no errors.

$ docker container logs mariadb

Make sure no errors in the log.

4

Use any MySQL client to verify if connection is succesfull.
Here I used MySQL CLI client to verify the connection. From the terminal, execute the below command;

$ mysql -uroot -psecret-pw -h localhost -P 3310

If the connection is a success, then we get an SQL prompt.

5

We have our MariaDB running on the Docker.



Each step starts with an action icon; this icon will give you an idea of what kind of work we will do in this step.

  • Terminal
  • Browser
  • Code editor
  • Info

comments powered by Disqus