Running applications

I have the first Compose file for NerdDinner in the ch06-docker-compose directory, which also contains the environment variable files. From that directory, I can start the whole application with a single docker-compose command:

> docker-compose up -d
Creating ch06-docker-compose_message-queue_1 ... done
Creating ch06-docker-compose_nerd-dinner-api_1 ... done
Creating ch06-docker-compose_nerd-dinner-db_1 ... done
Creating ch06-docker-compose_nerd-dinner-homepage_1 ... done
Creating ch06-docker-compose_elasticsearch_1 ... done
Creating ch06-docker-compose_reverse-proxy_1 ... done
Creating ch06-docker-compose_kibana_1 ... done
Creating ch06-docker-compose_nerd-dinner-index-handler_1 ... done
Creating ch06-docker-compose_nerd-dinner-web_1 ... done
Creating ch06-docker-compose_nerd-dinner-save-handler_1 ... done

Let's see the description of the preceding command: 

  • The up command is used to start the application, creating networks, volumes, and running containers.
  • The -d option runs all the containers in the background, and is the same as the --detach option in docker container run.

You can see that Docker Compose honors the depends_on settings for services. Any services that are dependencies for others are created first. Services that don't have any dependencies will be created in a random order. In this case, the message-queue service was created first, as many other services depend on it, and the nerd-dinner-web and nerd-dinner-save-handler services are the last of all, as they have the most dependencies.

The names in the output are the individual container names, with the naming format {project}_{service}_{index}. Each service has only one container running, which is the default, so the indexes are all 1. The project name is a sanitized version of the directory name where I ran the compose command.

When you run a docker-compose up command and it completes, you can manage the containers with Docker Compose or with the standard Docker CLI. The containers are just normal Docker containers, with some extra metadata used by compose to manage them as a whole unit. Listing containers shows me all the service containers created by compose:

> docker container ls
CONTAINER ID IMAGE COMMAND
c992051ba468 dockeronwindows/ch05-nerd-dinner-web:2e "powershell powershe…"
78f5ec045948 dockeronwindows/ch05-nerd-dinner-save-handler:2e "NerdDinner.MessageH…"
df6de70f61df dockeronwindows/ch05-nerd-dinner-index-handler:2e "dotnet NerdDinner.M…"
ca169dd1d2f7 sixeyed/kibana:5.6.11-windowsservercore-ltsc2019 "powershell ./init.p…"
b490263a6590 dockeronwindows/ch03-nerd-dinner-db:2e "powershell -Command…"
82055c7bfb05 sixeyed/elasticsearch:5.6.11-windowsservercore-ltsc2019 "cmd /S /C ".\bin\el…"
22e2d5b8e1fa dockeronwindows/ch03-nerd-dinner-homepage:2e "dotnet NerdDinner.H…"
058248e7998c dockeronwindows/ch05-nerd-dinner-api:2e "dotnet NerdDinner.D…"
47a9e4d91682 sixeyed/traefik:v1.7.8-windowsservercore-ltsc2019 "/traefik --docker -…"
cfd1ef3f5414 dockeronwindows/ch05-nats:2e "gnatsd -c gnatsd.co…"
...

The container running Traefik publishes port 80 to the local machine, and I have entries in my hosts file for the local NerdDinner domains. The NerdDinner application with its new home page, the REST API, and the Kibana analytics will behave as expected, because the full configuration is captured in the Compose file, and all the components are started by Docker Compose.

This is one of the most powerful features of the Compose file format. The file contains the complete specification to run your application, and anyone can use it to run your app. In this case, all the components use public Docker images on Docker Hub, so anyone can start the app from this Compose file. You don't need any prerequisites other than Docker and Docker Compose to run NerdDinner, which is now a distributed application containing .NET Framework, .NET Core, Java, Go, and Node.js components.

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

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