Docker Compose FQDN

1. Introduction

Docker Compose is a tool that allows you to define and run multi-container applications. It provides a simple way to define the services, networks, and volumes required for your application and run them with a single command. One common use case for Docker Compose is to deploy and manage applications that require a Fully Qualified Domain Name (FQDN) for their services.

In this article, we will explore how to configure and use FQDNs with Docker Compose. We will discuss the importance of FQDNs, how to define them in your Compose file, and how to access your services using these FQDNs.

2. Why FQDNs are important?

FQDNs are used to uniquely identify a specific host or service on the internet. They consist of a hostname and a domain name separated by a dot, for example, example.com. FQDNs provide a way to access services over the network without relying on IP addresses, which can change frequently. They also allow for easy scalability and load balancing by distributing requests across multiple hosts.

When deploying applications using Docker Compose, FQDNs become crucial for accessing the different services within the application. By using FQDNs, you can ensure that your application remains accessible even when containers are scaled up or down or when containers are replaced due to failures.

3. Defining FQDNs in Docker Compose

To define FQDNs in Docker Compose, you need to specify the hostname and domainname options for each service in your Compose file. Let's consider an example where we have a web application that consists of two services: a frontend service and a backend service.

version: '3'

services:
  frontend:
    image: myapp/frontend
    hostname: frontend
    domainname: example.com

  backend:
    image: myapp/backend
    hostname: backend
    domainname: example.com

In the above example, we have defined two services, frontend and backend, with their respective hostnames and the shared domain name example.com. With this configuration, the FQDNs for the frontend and backend services will be frontend.example.com and backend.example.com, respectively.

4. Accessing services using FQDNs

Once you have defined the FQDNs for your services, you can access them from within your application or from external clients. To access the services from within the application, you can use the defined FQDNs as the hostnames when making requests between services.

# frontend application code
import requests

response = requests.get('

In the above example, the frontend application makes a request to the backend service using the FQDN backend.example.com. This ensures that the request is routed to the correct backend service, even if multiple instances of the backend service are running.

To access the services from external clients, you need to configure the DNS resolution for the FQDNs. One way to achieve this is by configuring the DNS server to resolve the domain name example.com to the IP address of the host running the Docker Compose application.

5. Conclusion

In this article, we have explored the importance of using FQDNs with Docker Compose. We have seen how to define FQDNs in the Compose file and how to access services using these FQDNs. By using FQDNs, you can ensure that your multi-container applications remain accessible and scalable, even when containers are scaled up or down.