Book Image

A Developer's Essential Guide to Docker Compose

By : Emmanouil Gkatziouras
Book Image

A Developer's Essential Guide to Docker Compose

By: Emmanouil Gkatziouras

Overview of this book

Software development is becoming increasingly complex due to the various software components used. Applications need to be packaged with software components to facilitate their operations, making it complicated to run them. With Docker Compose, a single command can set up your application and the needed dependencies. This book starts with an overview of Docker Compose and its usage and then shows how to create an application. You will also get to grips with the fundamentals of Docker volumes and network, along with Compose commands, their purpose, and use cases. Next, you will set up databases for daily usage using Compose and, leveraging Docker networking, you will establish communication between microservices. You will also run entire stacks locally on Compose, simulate production environments, and enhance CI/CD jobs using Docker Compose. Later chapters will show you how to benefit from Docker Compose for production deployments, provision infrastructure on public clouds such as AWS and Azure, and wrap up with Compose deployments on said infrastructure. By the end of this book, you will have learned how to effectively utilize Docker Compose for day-to-day development.
Table of Contents (19 chapters)
1
Part 1: Docker Compose 101
6
Part 2: Daily Development with Docker Compose
12
Part 3: Deployment with Docker Compose

Adding a location service to Compose

We have implemented the service and have been able to add locations and execute spatial queries. The next step is to package the application using Docker and run it through Compose.

The first step is to create the Dockerfile. The same steps we followed in the previous chapter also apply here:

  1. Adding a Dockerfile
  2. Building the image using Compose

This is the Dockerfile for the location service:

# syntax=docker/dockerfile:1
FROM golang:1.17-alpine
 
RUN apk add curl
 
WORKDIR /app
 
COPY go.mod ./
COPY go.sum ./
 
RUN go mod download
 
COPY *.go ./
 
RUN go build -o /location_service
 
EXPOSE 8080
 
CMD [ "/location_service" ]

The Dockerfile is in place, and we can now proceed to run it through Compose. Now, to test the application, we need Redis and the image of the application to be built.

Our docker-compose.yaml, at this stage, should look like this:

services: 
  location-service: 
  ...