Specifying application resources

Docker Compose separates network and volume definitions from service definitions, which allows flexibility between environments. I'll cover this flexibility later in the chapter, but to finish the NerdDinner Compose file, I'll start with the simplest approach, using default values.

The services in my Compose file all use a network called nd-net, which needs to be specified in the Compose file. Docker networks are a good way to segregate applications. You could have several solutions that all use Elasticsearch but that have different SLAs and storage requirements. If you have a separate network for each application, you can run separate Elasticsearch services in different Docker networks, individually configured for each application, but all named elasticsearch. This keeps to the expected conventions but segregates by the network, so services only see the Elasticsearch instance in their own network.

Docker Compose can create networks at runtime, or you can define the resource to use an external network that already exists on the host. This specification for the NerdDinner network uses the default nat network that Docker creates when it is installed, so this setup will work for all standard Docker hosts:

networks:
  nd-net:
   external:
     name: nat

Volumes also need to be specified. Both of my stateful services, Elasticsearch and SQL Server, use named volumes for data storage:  es-data and nd-data, respectively. As with other networks, volumes can be specified as external, so Docker Compose will use existing volumes. Docker doesn't create any default volumes, so if I use an external volume, I would need to create it on each host before running the application. Instead, I'll specify the volumes without any options, so Docker Compose will create them for me:

volumes:
  es-data:
  db-data:

These volumes will store the data on the host, rather than in the container's writeable layer. They're not host-mounted volumes, so although the data is stored on the local disk, I'm not specifying the location. Each volume will write its data in the Docker data directory at C:ProgramDataDocker. I'll look at managing these volumes later in the chapter.

My Compose file has services, networks and volumes all specified, so it's ready to run. The full file is in the source code for this chapter at ch06ch06-docker-compose.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.179.35