generator-jhipster-docker

Docker JHipster module, Docker support in your JHipster application
Prerequisites
As this is a JHipster module, we expect you have JHipster and its related tools already installed:
You have to install Docker and Docker Compose:
All these images come from the official Docker Hub:
Installation
To install this module:
npm install -g generator-jhipster-docker
To update this module:
npm update -g generator-jhipster-docker
Usage
This is a JHipster module, that is meant to be use in a JHipster application.
To run the module on a JHipster generated application:
yo jhipster-docker
1 - Generate docker-compose services
1.1 - Description
When using the option Generating docker-compose services
, if your project uses MySQL, PostgreSQL, MongoDB or Cassandra, these files will be generated in your folder project:
- docker-compose.yml : to start the service(s) in DEV profile
- docker-compose-prod.yml : to start the service(s) in PROD profile
- docker/sonar.yml : to start a sonar instance
If your project uses Elasticsearch as search engine, the configuration will be included in the docker-compose-prod.yml
file.
So you can use docker-compose to start your database in development or production profile.
1.2 - Working with databases
Starting MySQL, PostgreSQL or MongoDB
In development profile:
docker-compose up -d
In production profile (it will start Elasticsearch too if you selected it as search engine):
docker-compose -f docker-compose-prod.yml up -d
Starting Cassandra the first time
In development profile:
- Build the image, which will contain the CQL scripts generated by your project for initializing the database:
docker-compose build
- Start the container (it will show the container id):
docker-compose up -d
- Initialize the database by creating the Keyspace and the Tables:
docker exec -it "container id" init
In production profile:
docker-compose -f docker-compose-prod.yml build
- Start the container (it will show the container id):
docker-compose -f docker-compose-prod.yml up -d
- Initialize the database by creating the Keyspace and the Tables:
docker exec -it "container id" init
Starting Cassandra the next times
In development profile:
docker-compose up -d
In production profile:
docker-compose -f docker-compose-prod.yml up -d
1.3 - Common commands
List the containers
You can use docker ps -a
to list all the containers
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fc35e1090021 mysql "/entrypoint.sh mysql" 4 seconds ago Up 4 seconds 0.0.0.0:3306->3306/tcp sampleapplication-mysql
Stop the containers
In development profile:
docker-compose stop
In production profile:
docker-compose -f docker-compose-prod.yml stop
You can use directly docker:
docker stop "container id"
When you stop a container, the data are not deleted, unless you delete the container.
Delete a container
Be carefull! All data will be deleted:
docker rm "container id"
2 - Automated build at the Docker Hub
2.1 - generate the files
- Launch :
yo jhipster-docker
- Select the second option :
Generate files for Automated build
- Answer all questions
2.2 - param your Docker Hub project
- go to Build Settings
- choose your branch or let master by default
- put this Dockerfile location: /docker/hub/
- click on Save Changes
- return to this project: git commit and push these changes!
- go to Build details: it should be a new line with Building
- go to Repo info and copy/paste in Full description the docker/app-hub.yml
3 - Local build and push image to Docker Hub
This option is used to build a Docker image for running the JHipster application.
You can read this documentation for more details:
spring-boot-docker
If you want, you can push your Docker image to Docker Hub.
License
Apache-2.0 © Pascal Grimaud