Use an .env file to store sensitive variables
You might not want to store sensitive content such as passwords and secrets in version control. Instead, you can use an .env file that contains a list of variable names and values and keep it in a secret management system such as HashiCorp Vault.
Be mindful of dependencies in production
When you change a particular container and want to redeploy it, docker-compose also redeploys any dependencies. Now, this might not be something that you wish to do, so you can override this behavior by using the following command:
$ docker-compose up –no-deps -d <container_service_name>
Treat docker-compose files as code
Always version control your docker-compose files and keep them alongside the code. This will allow you to track their versions and use gating and Git features such as pull requests.
Summary
This chapter was designed to cater to both beginners and experienced individuals. We started by covering the foundational concepts of Docker and gradually delved into more advanced topics and real-world use cases. This chapter began with installing Docker, running our first Docker container, understanding various modes of running a container, and understanding Docker volumes and storage drivers. We also learned how to select the right storage driver, volume options, and some best practices. All these skills will help you easily set up a production-ready Docker server. We also discussed the logging agent and how to quickly ship Docker logs to multiple destinations, such as journald, Splunk, and JSON files, to help you monitor your containers. We looked at managing Docker containers declaratively using Docker Compose and deployed a complete composite container application. Please try out all the commands mentioned in this chapter for a more hands-on experience – practice is vital to achieving something worthwhile and learning something new.
As a next step, in the following chapter, we will look at Docker images, creating and managing them, and some best practices.