View profile

DevOps and Docker Updates - Three Compose Tips

Three tips to help you get the most out of Compose, the best tool for local container development.
DevOps and Docker Updates - Three Compose Tips
By Bret Fisher • Issue #9 • View online
Three tips to help you get the most out of Compose, the best tool for local container development.

Modern Monitoring & Analytics
Going beyond the "up" command
Docker compose is proven as an incredibly useful tool to spin up multi container applications with a single up command. Beyond that, we are able to have a higher level of control of that command using subcommands, flags, templates, overrides, and environment variables.
Here are a few tips to take you “beyond the up command.”
docker-compose run
docker-compose run [service] [command]
This command allows you to run a one-off command against a specific service in the compose file. Run is for creating a new container, so you don’t have to do a up first. Remember exec is only for running commands in containers that are actively running. By using run, you can install a specific tool at the command line or maybe run something else in the container by changing the default CMD. It gives you the ability to override the CMD that is defined in the image. By default, It will not publish any ports specified in that service, (unless specified to do so) so you can comfortably run this as a test without worrying about any port conflicts. You can also use this to pass environment variables just like a docker run command using the -e flag.
Top 4 Tactics To Keep Node.js Rockin’ in Docker
Skip the build cache
If you want to force a new rebuild of an image without using any cached layers of the build, you can run the command docker-compose build –no-cache, and it will run through the building of each layer from scratch as if it was never done on your machine. This allows you to have another troubleshooting step of ruling out cached builds as an issue.
Help, Docker Compose Runs Old Containers! · vsupalov.com
CLI aliases to save your hands
This is not anything specific to docker, but more of a shell (Bash, Zsh) command that aids in docker commands getting simpler. We can add aliases, so that typing dcu tells the shell we mean docker-compose up. We can set an alias for docker-compose by entering any of the following below that might be helpful for shortening your compose commands. Anything not on this list can be easily added by simply modifying any of the below commands.
alias dcu=‘docker-compose up’
alias dcd='docker-compose down’
alias dcr='docker-compose run’
alias dce='docker-compose exec’
alias dcud='docker-compose up -d’
alias dcps='docker-compose ps’
alias dcl='docker-compose logs’

Thanks for reading, and I’ll be back next week,
Bret
Did you enjoy this issue?
Bret Fisher

Frequent updates on my projects, videos, and opinions focused on the container ecosystem, including Docker, Kubernetes, Docker Swarm, CI/CD, and container DevOps.

If you don't want these updates anymore, please unsubscribe here
If you were forwarded this newsletter and you like it, you can subscribe here
Powered by Revue
Bret Fisher, Virginia Beach, Virginia, USA