Backend Environment in docker-compose

MinimalistDev
Nov 15, 2018 · 1 min read

The objective is to use on front-end development, to avoid to install databases, many languages and manage versions on your local machine of the front-enders.

For example, I created a spring boot application, with a mongo database.

On the root of the project, create the following Dockerfile

FROM gradle:jdk8 COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
ENTRYPOINT ["gradle", "bootRun"]

Also in the root, create the docker-compose.yml

version: "3"services:
db:
image: mongo
ports:
- "27017:27017"
restart: always
networks:
- backend
springbackend:
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:8080"
depends_on:
- db
restart: always
networks:
- backend
environment:
DB_HOST: db
networks:
backend:

To running the environment use the following command

docker-compose up

If you update the code or something, to recreate the images use

docker-compose up --build

The files are self-explained, but to summarise the docker-compose.yml use the Dockerfile to create the container with your code, and also create a container separated with a mongo.

To test go on http://localhost:8080/actuator/health

The code is on https://github.com/minimalistdev/backend-development-environment-in-docker

I'm a minimalist developer. let's simplify and do better and better…

More From Medium

Top on Medium

Ed Yong
Mar 25 · 22 min read

26K

Top on Medium

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade