Docker Tip #74: curl vs pip for Installing Docker Compose
On Linux, Docker Compose doesn't come bundled up with Docker like it does on Docker for Windows / Mac. So which one should you use?
When it comes to installing Docker Compose on Linux you have 2 options:
You can install Docker Compose on Linux by downloading the self-contained binary file from GitHub. This is typically done with curl. For example, check the install guide on the GitHub releases page.
Install it using PIP by running
pip3 install docker-compose
. Whether or not you choose to use--user
or put it into a virtual environment is up to you.
In both cases, you’re still running a Python application in the end.
I used to always download the self-contained file because it felt easier to me to download a single file, make it executable and run it but not anymore.
Lately I’ve been using the PIP version in development and production for 3 reasons:
The self-contained binary is using PyInstaller and every time you run a Docker Compose command it’s dumping a bunch of files to a temp directory to run the Python app inside. This consistently adds ~200ms* of delay to any command.
*I tested this on WSL running Ubuntu 18.04 and on a real Ubuntu 18.04 server. It was always about a 200ms difference. On my machine it was 170ms (PIP) vs 370ms (binary) to run
time docker-compose --version
.When it comes to automating the installation of Docker Compose , PIP is much easier to use because you can choose to download the latest version, or pin a specific version but with curl you always need to reference a version number in the download URL.
If you use any of Ansible’s
docker_*
modules, they depend on having thedocker
and / ordocker-compose
PIP packages installed, and using PIP for Docker Compose gets you half of the way there already.