Gkatziouras | A Developer's Essential Guide to Docker Compose | E-Book | www.sack.de
E-Book

E-Book, Englisch, 264 Seiten

Gkatziouras A Developer's Essential Guide to Docker Compose

Simplify the development and orchestration of multi-container applications
1. Auflage 2024
ISBN: 978-1-80181-381-5
Verlag: De Gruyter
Format: EPUB
Kopierschutz: 0 - No protection

Simplify the development and orchestration of multi-container applications

E-Book, Englisch, 264 Seiten

ISBN: 978-1-80181-381-5
Verlag: De Gruyter
Format: EPUB
Kopierschutz: 0 - No protection



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.

Gkatziouras A Developer's Essential Guide to Docker Compose jetzt bestellen!

Autoren/Hrsg.


Weitere Infos & Material


Table of Contents - Introduction to Docker Compose
- Running the First Application Using Compose
- Network and Volumes Fundamentals
- Executing Docker Compose Commands
- Connecting Microservices
- Monitoring Services with Prometheus
- Combining Compose Files
- Simulating Production Locally
- Creating Advanced CI/CD Tasks
- Deploying Docker Compose Using Remote Hosts
- Deploying Docker Compose to AWS
- Deploying Docker Compose to Azure
- Migrating to Kubernetes Configuration Using Compose


1


Introduction to Docker Compose


As Docker has rapidly become part of our daily developments and deployments, Docker Compose is a tool that you will encounter frequently. You have probably read about it, used it, or you might even have stumbled upon it while browsing the official Docker documentation.

As day-to-day development becomes more complex, it’s common for an application to interact with more than one software component. Applications that grow in popularity will face the need to separate the workloads and facilitate scaling. The separation of logic, along with responsibilities to multiple software components, is imminent. Docker has been giving solutions for simplifying the containerization, management, and isolation of an application’s workloads. Docker Compose can assist in the development of modern multi-container applications and their deployment.

Docker Compose is a simple and effective tool. Utilizing its features, it can help to tackle the challenges faced on multi-container applications and increase productivity in day-to-day development. Apart from its usage in the development life cycle, it can also be a viable option for production deployments. This bridges the gap between your initial local developments and actual production deployment. This capability can be utilized to achieve a smooth transition to orchestration engines such as Kubernetes.

This chapter will be an overview of Compose, how it works, and its common use cases. We will install Docker Compose and create our first Compose file to run a software component of our choice. By diving more into the Compose file format, we will also apply some extra configurations and use one of our local images.

In this chapter, the following topics will be covered:

  • Introducing Docker Compose and its usage
  • Installing Docker Compose
  • Understanding how Docker Compose works
  • Your first Docker Compose file
  • Using your Docker image in Docker Compose

Technical requirements


The code for this book is hosted on GitHub at https://github.com/PacktPublishing/A-Developer-s-Essential-Guide-to-Docker-Compose. In case of an update to the code, it will be updated on GitHub.

Introducing Docker Compose and its usage


Docker Compose is a tool for defining and running multi-container Docker applications. The configuration is achieved using YAML files, and through the Docker Compose CLI utility, we can provision and perform operations on the containers managed by Docker Compose.

Here is a list of features that Compose offers:

  • Complex multi-container applications on a single host
  • The isolation of Docker workloads
  • Bootstrapping and the distribution of complex applications
  • Multiple environments
  • The ability to preserve data on application change
  • The ability to update application versions
  • Environment composition
  • Reusable configurations
  • The simulation of complex production environments
  • The deployment of production applications

In this book, we will dive into the preceding features extensively, evaluate how we can benefit from them, and incorporate them into our development process. In the next section, we will install Docker and Compose on our workstation using the operating system of our choice.

Installing Docker Compose


Both Docker Compose and the Compose CLI are built using Go. Compose can be run on the three major operating systems: Linux, Windows, and macOS. Since Compose is about managing multi-container Docker applications, the prerequisite is to have Docker installed.

Docker Desktop


On Mac and Windows, Docker Desktop is an installation option. Docker Desktop handles the complexity of setting up Docker on your local machine. It will create a Linux Virtual Machine (VM) on your host and facilitate container interactions with the OS such as access to the filesystem and networking. This one-click installation comes with the necessary tools such as the Docker CLI. One of the tools that is included is also Docker Compose. Therefore, installing Docker Desktop makes it sufficient to interact with Docker Engine using Compose on our workstation.

Installing Docker


To install the correct Docker distribution for the workstation of our choice, we will navigate to the corresponding section of the official Docker page:

On macOS


Apple provides workstations with two different types of processors: an Intel processor and an Apple processor. Docker has an installation option for both. Once the download is complete, by clicking on the installer, you can drag and drop the Docker application, as shown in the following screenshot:

Figure 1.1 – Installing Docker on Mac

Once Docker has been installed, we can run a hello world command check:

$ docker run --rm hello-world

Unable to find image 'hello-world:latest' locally

latest: Pulling from library/hello-world

93288797bd35: Pull complete

Digest: sha256:97a379f4f88575512824f3b352bc03cd75e239179eea 0fecc38e597b2209f49a

Status: Downloaded newer image for hello-world:latest

Hello from Docker!

This message shows that your installation appears to be working correctly.

..

Additionally, we have to check whether Compose has been installed:

$ docker compose version

Docker Compose version v2.2.3

Now, let’s look at how to install Docker Desktop on Windows.

On Windows


Similar to Mac, Docker Desktop is installed seamlessly onto your OS ready to be used.

Once you download the EXE installation file and click on it, Docker will be installed along with its utilities. Once this is done, some extra configurations will need to be applied to enable virtualization for Windows.

Whether the backend that’s being used is or , you have to set up your machine BIOS to enable virtualization, as shown in the following screenshot:

Figure 1.2 – Enabling virtualization on Windows via BIOS

Once you have logged in to Windows, you will need to enable the corresponding virtualization features.

For WSL 2, you should enable the Virtual Machine Platform feature and the Windows Subsystem for Linux feature:

Figure 1.3 – Enabling virtualization for WSL 2

For Hyper-V you should enable Hyper-V:

Figure 1.4 – Enabling virtualization for Hyper-V

Before you get started, make sure that your user account is added to the docker-users group. Once done, log out from Windows and log in again. You can start Docker, and then you can execute your first Docker command on PowerShell, as follows:

PS C:\Users\my-user> docker run -d -p 80:80 docker/getting-started

Unable to find image 'docker/getting-started:latest' locally

latest: Pulling from docker/getting-started

59bf1c3509f3: Pull complete                                     8d6ba530f648: Pull complete                                      5288d7ad7a7f: Pull complete                                  39e51c61c033: Pull complete                                    ee6f71c6f4a8: Pull complete                                    f2303c6c8865: Pull complete                                    0645fddcff40: Pull complete                                               d05ee95f5d2f: Pull complete                                     Digest: sha256:aa945bdff163395d3293834697fa91fd4c725f47093ec499 f27bc032dc1bdd16

Status: Downloaded newer image for docker/getting-started:latest

852371fcb34fddfe900bddc669af3a7aaab8743f8555fbb9952904bd2516a e7a

PS C:\Users\my-user>

Let’s also check whether Docker Compose has been installed:

PS C:\Users\my-user> docker compose version

Docker Compose version v2.2.3

Next, we will look at how to install Docker Desktop on Linux.

On Linux


At the time of writing, a Docker Desktop installation for Linux is not available, but it’s on the roadmap, and it’s just a matter of time before it’ll be available for Linux. However, Docker Engine is sufficient in order to use Docker Compose.

The most common method of installation is to add the Docker repositories to your Linux...


Gkatziouras Emmanouil :

Emmanouil Gkatziouras started his career in software as a Java developer. Since 2015, he has worked daily with cloud providers such as GCP, AWS and Azure, and container orchestration tools such as Kubernetes. He has fulfilled many roles, either in lead positions or as an individual contributor. He enjoys being a versatile engineer and collaborating with development, platform, and architecture teams. He loves to give back to the developer community by contributing to open-source projects and by blogging on various software topics. He is committed to continuous learning and is a holder of certifications such as CKA, CCDAK, PSM, CKAD, and PSO. He is the author of ‘A Developer's Essential Guide to Docker Compose'.



Ihre Fragen, Wünsche oder Anmerkungen
Vorname*
Nachname*
Ihre E-Mail-Adresse*
Kundennr.
Ihre Nachricht*
Lediglich mit * gekennzeichnete Felder sind Pflichtfelder.
Wenn Sie die im Kontaktformular eingegebenen Daten durch Klick auf den nachfolgenden Button übersenden, erklären Sie sich damit einverstanden, dass wir Ihr Angaben für die Beantwortung Ihrer Anfrage verwenden. Selbstverständlich werden Ihre Daten vertraulich behandelt und nicht an Dritte weitergegeben. Sie können der Verwendung Ihrer Daten jederzeit widersprechen. Das Datenhandling bei Sack Fachmedien erklären wir Ihnen in unserer Datenschutzerklärung.