Running the application in the background

We started the application by attaching the terminal to the output of the containers, but that's inconvenient if you want to deploy an application to a remote server. To detach the terminal, use the -d parameter when you start:

docker-compose -f docker-compose.prod.yml up -d

This will start the application with a persistent state, and print something like the following:

Starting deploy_db_1   ... done
Starting deploy_smtp_1 ... done
Starting deploy_dbsync_1 ... done
Starting deploy_mails_1 ... done
Starting deploy_content_1 ... done
Starting deploy_users_1 ... done
Starting deploy_router_1 ... done

It also detaches from the Terminal. You might ask: How can I read the logs that microservices print using env_logger and the log crate? Use the following command with the name of the service at the end:

docker-compose -f docker-compose.prod.yml logs users

This command will print the logs of the users_1 container, which represents the users service of the application. You can use the grep command to filter unnecessary records in logs.

Since the application detached from the terminal, you should use the down command to stop the application:

docker-compose -f docker-compose.test.yml stop

This will stop all containers and finish with the output: 

Stopping deploy_router_1  ... done
Stopping deploy_users_1 ... done
Stopping deploy_content_1 ... done
Stopping deploy_mails_1 ... done
Stopping deploy_db_1 ... done
Stopping deploy_smtp_1 ... done

The application has stopped and now you know how to use the Docker Compose tool to run a multi-container application. If you want to learn more about using Docker Compose on local and remote machines, read this book.

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

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