liveBook · Manning

Hostname

As explained in Road to Kubernetes

A hostname is a human-readable network name that identifies a host or service for network communication.

A hostname is the human-readable name used to identify a host or service during network communication. In Docker Compose, a service name becomes the hostname other containers use. section 6.4.1

Compose creates a shared network for services. A container can reach another service by name, even when that service has no port exposed to the host machine. section 6.4.1

Calling an NGINX service by hostname

Define services named web and my-nginx-service, then enter the web container and run curl http://my-nginx-service or curl http://my-nginx-service:80. The web container receives NGINX’s standard HTML response through the Compose network. section 6.4.1

Using service names as hostnames provides several practical deployment behaviors:

  • Avoids requiring every internal service to publish a port on the host. section 6.4.1
  • Lets application services connect to databases such as Redis through the database service name. section 6.4.2
  • Requires services to share the Compose network and use the declared service name. section 6.4.1
Listing 6.9 NGINX service in Docker Compose
services:
  my-nginx-service:
    image: nginx
  web:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8080:8080"
    environment:
      - PORT=8080
    volumes:
      - mywebdata:/app/data

volumes:
  mywebdata:

Inspect the Compose definition that declares my-nginx-service and web, then relate those names to the curl hostname. section 6.4.1

How Road to Kubernetes covers it

How deep it goes
Demonstrates hostname resolution with Compose services and curl, but defers broader database connection setup and drivers.
Examples
Uses NGINX and Redis services, curl commands, Compose files, and an interactive shell inside the web container.
What it assumes
Assumes basic Docker Compose commands while teaching shared networks, service names, port exposure, and internal access through runnable steps.
What you can do after
Operate Docker Compose services by testing internal connectivity with curl and addressing dependencies by their service names.
How it connects
Connects Docker Compose, containers, networks, ports, Redis, and databases through service-name addressing.

Also explained in

Compare how 2 books explain hostname →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Road to Kubernetes. The section links point to the parts of the book it draws on.