Dcoker Multicontainer Docker Compose
Dcoker Multicontainer Docker Compose
example
Docker provides lightweight containers to run services in isolation from our
infrastructure so we can deliver software quickly.
Overview
Assume that we have a Spring Boot Application working with MySQL database.
The problem is to containerize a system that requires more than one Docker
container:
Docker Compose helps us setup the system more easily and efficiently than with
only Docker. We’re gonna following these steps:
Directory Structure:
FROM: install the image of the Maven – JDK version.
WORKDIR: path of the working directory.
COPY: copy all the files inside the project directory to the container.
RUN: execute a command-line inside the container: mvn clean install to install
the dependencies in pom.xml.
CMD: run script mvn spring-boot:run after the image is built.
– app:
You should note that the host port (LOCAL_PORT) and the container port
(DOCKER_PORT) is different. Networked service-to-service communication uses the
container port, and the outside uses the host port.
Docker Compose Environment variables
In the service configuration, we used environmental variables defined inside
the .env file. Now we start writing it.
.env
MYSQLDB_USER=root
MYSQLDB_ROOT_PASSWORD=123456
MYSQLDB_DATABASE=bezkoder_db
MYSQLDB_LOCAL_PORT=3307
MYSQLDB_DOCKER_PORT=3306
SPRING_LOCAL_PORT=6868
SPRING_DOCKER_PORT=8080