-
Notifications
You must be signed in to change notification settings - Fork 1
Dockerized backend
How to run the docker app?
Go to terminal or command prompt and run:
docker pull ghcr.io/java-dzgs/ingreedio-api:developThen restart Docker image so it can load new version.
Delete container.
Generate a Personal Access Token with the read:packages scope from your GitHub account. Go to Settings > Developer settings > Personal access tokens > Generate new token. Set expiration time to never, so you don't have to recreate the token! Make sure to save the token as it will be displayed only once!
Open your terminal or command prompt and run the following command:
docker login ghcr.io -u USERNAME -p YOUR_TOKENReplace USERNAME with your GitHub username and YOUR_TOKEN with the Personal Access Token you generated in Step 1.
Copy the following docker-compose.yml configuration somewhere into your project directory:
version: '2'
services:
app:
image: 'ghcr.io/java-dzgs/ingreedio-api:develop'
ports:
- '8080:8080'
container_name: app
depends_on:
- postgres
- mongo
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/ingreedio
- SPRING_DATASOURCE_USERNAME=compose-postgres
- SPRING_DATASOURCE_PASSWORD=compose-postgres
- SPRING_JPA_HIBERNATE_DDL_AUTO=update
- SPRING_DATA_MONGODB_HOST=mongo
- SPRING_DATA_MONGODB_USERNAME=compose-mongo
- SPRING_DATA_MONGODB_PASSWORD=compose-mongo
postgres:
image: 'postgres:13.1-alpine'
container_name: postgres
ports:
- '5431:5432'
environment:
- POSTGRES_USER=compose-postgres
- POSTGRES_PASSWORD=compose-postgres
- POSTGRES_DB=ingreedio
mongo:
image: 'mongo'
container_name: mongo
restart: always
ports:
- '27016:27017'
environment:
MONGO_INITDB_ROOT_USERNAME: compose-mongo
MONGO_INITDB_ROOT_PASSWORD: compose-mongo
mongo-express:
image: 'mongo-express'
container_name: mongo-express
restart: always
ports:
- '8081:8081'
depends_on:
- mongo
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: compose-mongo
ME_CONFIG_MONGODB_ADMINPASSWORD: compose-mongo
ME_CONFIG_MONGODB_URL: mongodb://compose-mongo:compose-mongo@mongo:27017/
ME_CONFIG_BASICAUTH: falseNavigate to the directory containing your docker-compose.yml file in your terminal or command prompt.
Run the following command to start the backend: 😻🐈
docker compose upCongratulations! Your Docker app should now be running. You can access it at http://localhost:8080.
For ease of use it is recommended to use IntelliJ IDEA Ultimate, which is free for students.
If you haven't already, you may need to clone the repository to your local machine. This step is optional if you already have the project setup. 🐈
This step involves a specific configuration within IntelliJ that automates the Docker image build and initiates Docker Compose within a Docker container. This process builds the Docker image and starts Docker Compose.

After initiating, the process will complete after some time:

If you encounter any issues, please contact your DevOps specialist for assistance. 😸
Once complete, you can test the app by navigating to localhost:8080. You should see a Hello, world! greeting :3 Remember to stop all Docker containers!!! after verifying that it works:

This configuration allows you to build the app outside Docker, then inject it into Docker for debugging purposes.
Here’s how you can set it up:

Change the Run on option to Docker compose...:

In the new window, select Service: app

Confirm the selection and complete the setup. You don't need to change anything else, so just click through the rest 😸

Test the 'Application' configuration by running it. Unlike the previous setup, the app will not start on port 8080. Instead, IntelliJ provides a new, dynamic port each time:

You may run into error like this:

This error indicates that your configured Java version is too old. 🙀 To resolve this, ensure that your Gradle configuration uses the appropriate Project SDK. Follow these steps:
Navigate to Settings > Build, Execution, Deployment > Build Tools > Gradle and check following setting:

After that, please change the SDK in Project Structure to at least 21:
These steps should resolve the Java version error, allowing you to proceed with running the Docker application seamlessly. 😻