Docker Compose is available on multiple platforms.In this lab we’ll demonstrate some of the ways to install it on Linux, Windows and Mac.
Installing Docker Compose on Linux
Installing Docker Compose on Linux is a two-step process. Firt you will be downloading binary from github, Second giving executable permission.
Download the current stable release of Docker Compose
$ curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
$ chmod +x /usr/local/bin/docker-compose
Test the installation
You can run this command from a terminal window
$ docker-compose --version
Installing Docker Compose on Windows 10
If you have already installed Docker Desktop for Windows or Docker Toolbox then no need of separate installation for docker compose, since its part of the package.
Check Docker Compose is installed
You can run this command from a PowerShell or CMD terminal.
Installing Docker Compose on Mac
Docker Compose is installed as part of Docker for Mac. So if you have Docker for MAC, you have Docker Compose.
Check Docker Compose is installed
You can run this command from a terminal window.
$ docker-compose --version
Contributor
Savio Mathew
Время на прочтение
3 мин
Количество просмотров 51K
Docker-compose — это утилита, позволяющая запускать одновременно несколько контейнеров, используя при этом единый файл конфигурации всего стека сервисов, нужных вашему приложению. Например, такая ситуация: запускаем node.js webapp, которому нужна для работы mongodb, compose выполнит build вашего контейнера с webapp (традиционный Dockerfile) и перед его запуском запустит контейнер с mongodb внутри; так же может выполнить линк их между собой. Что крайне удобно как в разработке, так и в CI самого приложения. Так сложилось, что Windows пользователи были обделены возможностью использовать столько удобное средство, ввиду того, что официальной поддержки данной ОС все еще нет. А python версия для *nix не работает в окружении windows cmd, ввиду ограничений консоли Windows.
Для того, чтобы запустить docker-compose, мы можем использовать консольную оболочку Babun. Это, так сказать, «прокаченный» форк cygwin.
Итак, рецепт запуска docker-compose в Windows из консоли babun такой:
1. Скачиваем(~280MB!) и устанавливаем сам babun, узнать больше об этой оболочке можно на ее домашней странице babun.github.io;
2. Распаковываем архив (после установки полученную папку можно удалять);
3. Запускаем файл install.bat и ждем, пока пройдет установка;
4. После в открывшемся окне babun введем команду:
babun update
И убедимся, что у нас самая последняя версия оболочки (далее все команды выполняются только внутри оболочки babun);
5. Если вам не нравится дефолтный shell babun (используется zsh), его можно изменить на bash. Для этого вводим:
babun shell /bin/bash
6. Теперь нам нужно установить те самые зависимости Python, которых так не хватает docker-compose. Для этого выполним следующие команды по очереди:
pact install python-setuptools
pact install libxml2-devel libxslt-devel libyaml-devel
curl -skS https://bootstrap.pypa.io/get-pip.py | python
pip install virtualenv
curl -skS https://raw.githubusercontent.com/mitsuhiko/pipsi/master/get-pipsi.py | python
7. Теперь мы готовы установить сам docker-compose:
pip install -U docker-compose
Если все прошло успешно, увидим:
{ ~ } » docker-compose --version
docker-compose 1.2.0
Если же вы получили ошибку, error python fcntl или сообщение о не найдом файле docker-compose, попробуйте найти файл docker-compose в папках /usr/local/bin, /usr/sbin и подобных, затем можно сделать симлинк на /bin/. либо добавить в системный PATH недостающий путь.
Для правильной работы docker-compose нужно иметь уже настроенное окружение консоли для работы с docker-machine или boot2docker, а так же сам клиент docker должен быть доступен в системном PATH. О том, что такое docker, docker-machine и как с ними работать отлично рассказывает официальная документация.
Для входа в окружение нашего хоста докера, запущенного в docker-machine, нужно выполнить:
eval "$(docker-machine env ИМЯ_МАШИНЫ)"
Либо тоже самое для boot2docker:
eval "$(boot2docker shellinit)"
Проверить правильность работы клиента docker можно так:
docker ps
Если получаем список контейнеров или просто заголовки таблицы, значит, все ок!
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Для запуска стека приложения переходим в каталог нашего приложения, где у нас уже должен быть заготовлен файл docker-compose.yml или fig.yml. Синтаксис yml файла описан тут.
Далее для запуска вводим команду:
docker-compose up
Если нужно запустить в фоне, добавляем -d. Compose построит нужный образ и запустит его согласно вашему файлу docker-compose.yml.
На этом все.
Спасибо за внимание, надеюсь было полезно.
p.s. Я умышлено не стал говорить о варианте запуска compose как контейнера, т.к. считаю его неудобным.
Update 2021: docker-compose has been rewritten in Go, and is now a docker command docker compose
As such, there is no longer the need to «install» it.
See docker compose
.
Update 7th of november 2018:
On desktop systems like Docker for Mac and Windows, Docker Compose is
included as part of those desktop installs.
Accordingly to the documentation, Docker for Windows and Docker Toolbox already include Compose along with other Docker apps, so most Windows users do not need to install Compose separately.
Update 2017: this is now officially managed (for Windows 10 supporting Hyper-V) with «Docker for Windows».
See «Install Docker for Windows».
It does have a chocolatey installation package for Docker, so:
choco install docker-for-windows
# or
choco upgrade docker-for-windows
Again, this requires a 64bit Windows 10 Pro, Enterprise and Education (1511 November update, Build 10586 or later) and Microsoft Hyper-V.
For other Windows, you still need VirtualBox + Boot2Docker.
Update: docker compose 1.5 (Nov 2015) should make it officially available for Windows (since RC2).
Pull requests like PR 2230 and PR 2143 helped.
Commit 13d5efc details the official Build process for the Windows binary.
Original answer (Q1-Q3 2015).
Warning: the original answer («docker-compose
in a container») below seems to have a bug, according to Ed Morley (edmorley
).
There appear to be caching issues with the «docker-compose in a container» method (See issue #6: «Changes to docker-compose.yml and Dockerfile not being detected»)
Ed recommends:
As such for now, running the Python
docker-compose
package insideboot2docker
seems to be the most reliable solution for Windows users (having spent many hours trying to battle with the alternatives).To install docker-compose from PyPI, run this from inside
boot2docker
:docker@boot2docker:~$ tce-load -wi python && curl https://bootstrap.pypa.io/get-pip.py | \ sudo python - && sudo pip install -U docker-compose
To save having to run the above every time the
boot2docker
VM is restarted (since changes don’t persist), you can usebootlocal.sh
like so:docker@boot2docker:~$ echo 'su docker -c "tce-load -wi python" && \ curl https://bootstrap.pypa.io/get-pip.py | \ python - && pip install -U docker-compose' | \ sudo tee /var/lib/boot2docker/bootlocal.sh > /dev/null && \ sudo chmod +x /var/lib/boot2docker/bootlocal.sh
(The
su docker -c
gymnastics are required sincetce-load
cannot be run asroot
, andbootlocal.sh
is run asroot
. Thechmod
ofbootlocal.sh
should be unnecessary once #915 is fixed.
Add-a
to thetee
command if you need to append, rather than overwritebootlocal.sh
.)If you wish to use a pre-release version of docker-compose, then replace
pip install -U docker-compose
withpip install -U docker-compose>=1.3.0rc1
or equivalent.
Original answer:
I also run docker-compose
(on Windows boot2docker) in a image by:
-
cloning https://github.com/docker/compose in
/c/Users/<username>/myproject/compose
(in order to have persistence, since/c/Users/<username>
is automatically mounted, when I use VirtualBox with its extension pack ) -
building the docker-compose image:
cd /c/Users/<username>/myproject/compose # that will put the repo in a detached HEAD, but it does not matter here git checkout 1.2.0 docker build -t docker-compose .
-
adding a ‘
dc
‘ alias (in aprofile
file that I copy to my/home/docker/.ashrc
before launching the boot2docker ssh session.)dc='docker run --rm -i -t -v /var/run/docker.sock:/var/run/docker.sock -v `pwd`:`pwd` -w `pwd` docker-compose'
From there, a ‘dc up
‘ or ‘dc ps
‘ just works. On Windows. With boot2docker 1.6.
This page contains information on how to install Docker Compose. You can run Compose on macOS, Windows, and 64-bit Linux.
Prerequisites
Docker Compose relies on Docker Engine for any meaningful work, so make sure you have Docker Engine installed either locally or remote, depending on your setup.
-
On desktop systems like Docker Desktop for Mac and Windows, Docker Compose is included as part of those desktop installs.
-
On Linux systems, you can install Docker Compose with the Docker Engine using the convenience script. Select the install Docker Engine page for your distribution and then look for instructions on installing using the convenience script.
Otherwise, you should first install the Docker Engine for your OS and then refer to this page for instructions on installing Compose on Linux systems. -
To run Compose as a non-root user, see Manage Docker as a non-root user.
Install Compose
Follow the instructions below to install Compose on Mac, Windows, Windows Server, or Linux systems.
Install a different version
The instructions below outline installation of the current stable release (v2.5.0) of Compose. To install a different version of Compose, replace the given release number with the one that you want.
Compose releases are also listed and available for direct download on the Compose repository release page on GitHub.
To install the Python version of Compose, follow instructions in the Compose v1 GitHub branch.
- Mac
- Windows
- Windows Server
- Linux
- Linux Standalone binary
Install Compose on macOS
Docker Desktop for Mac includes Compose along with other Docker apps, so Mac users do not need to install Compose separately. For installation instructions, see Install Docker Desktop on Mac.
Install Compose on Windows desktop systems
Docker Desktop for Windows includes Compose along with other Docker apps, so most Windows users do not need to install Compose separately. For install instructions, see Install Docker Desktop on Windows.
If you are running the Docker daemon and client directly on Microsoft Windows Server, follow the instructions in the Windows Server tab.
Install Compose on Windows Server
Follow these instructions if you are running the Docker daemon and client directly on Microsoft Windows Server and want to install Docker Compose.
-
Start an “elevated” PowerShell (run it as administrator). Search for PowerShell, right-click, and choose Run as administrator. When asked if you want to allow this app to make changes to your device, click Yes.
-
In PowerShell, since GitHub now requires TLS1.2, run the following:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Then run the following command to download the current stable release of Compose (v2.5.0):
Invoke-WebRequest "https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-Windows-x86_64.exe" -UseBasicParsing -OutFile $Env:ProgramFiles\Docker\docker-compose.exe
Note
On Windows Server 2019, you can add the Compose executable to
$Env:ProgramFiles\Docker
. Because this directory is registered in the systemPATH
, you can run thedocker-compose --version
command on the subsequent step with no additional configuration.To install a different version of Compose, substitute
v2.5.0
with the version of Compose you want to use. -
Test the installation.
$ docker compose version Docker Compose version v2.5.0
Install Compose on Linux systems
You can install Docker Compose in different ways, depending on your needs:
- In testing and development environments, some users choose to use automated convenience scripts to install Docker.
- Most users set up Docker’s repositories and install from them, for ease of installation and upgrade tasks. This is the recommended approach.
- Some users download and install the binary, and manage upgrades manually.
Install using the convenience script
As Docker Compose is now part of the Docker CLI it can be installed via a convenience script with Docker Engine and the CLI.
Choose your Linux distribution and follow the instructions.
Install using the repository
If you already follow the instructions to install Docker Engine, Docker Compose should already be installed.
Otherwise, you can set up the Docker repository as mentioned in the Docker Engine installation, choose your Linux distribution and go to the Set up the repository
section.
When finished
-
Update the
apt
package index, and install the latest version of Docker Compose, or go to the next step to install a specific version:$ sudo apt-get update $ sudo apt-get install docker-compose-plugin
-
To install a specific version of Docker Engine, list the available versions in the repo, then select and install:
a. List the versions available in your repo:
$ apt-cache madison docker-compose-plugin docker-compose-plugin | 2.3.3~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable arm64 Packages
b. Install a specific version using the version string from the second column, for example,
2.3.3~ubuntu-focal
.$ sudo apt-get install docker-compose-plugin=<VERSION_STRING>
-
Verify that Docker Compose is installed correctly by checking the version.
$ docker compose version Docker Compose version v2.3.3
Install the binary manually
On Linux, you can download the Docker Compose binary from the Compose repository release page on GitHub and copying it into $HOME/.docker/cli-plugins
as docker-compose
. Follow the instructions from the link, which involve running the curl
command in your terminal to download the binaries. These step-by-step instructions are also included below.
-
Run this command to download the current stable release of Docker Compose:
$ DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker} $ mkdir -p $DOCKER_CONFIG/cli-plugins $ curl -SL https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
This command installs Compose for the active user under
$HOME
directory. To install Docker Compose for all users on your system, replace~/.docker/cli-plugins
with/usr/local/lib/docker/cli-plugins
.To install a different version of Compose, substitute
v2.5.0
with the version of Compose you want to use. -
Apply executable permissions to the binary:
$ chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
or if you choose to install Compose for all users
$ sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
-
Test the installation.
$ docker compose version Docker Compose version v2.5.0
Install Compose as standalone binary on Linux systems
You can use Compose as a standalone binary without installing the Docker CLI.
- Run this command to download the current stable release of Docker Compose:
$ curl -SL https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
To install a different version of Compose, substitute
v2.5.0
with the version of Compose you want to use.
- Apply executable permissions to the binary:
$ sudo chmod +x /usr/local/bin/docker-compose
Note:
If the command
docker-compose
fails after installation, check your path. You can also create a symbolic link to/usr/bin
or any other directory in your path.For example:
$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
-
Test the installation.
$ docker-compose --version Docker Compose version v2.5.0
Uninstallation
To uninstall Docker Compose if you installed using curl
:
$ rm $DOCKER_CONFIG/cli-plugins/docker-compose
or if you choose to install Compose for all users
$ sudo rm /usr/local/lib/docker/cli-plugins/docker-compose
Got a “Permission denied” error?
If you get a “Permission denied” error using either of the above methods, you probably do not have the proper permissions to remove
docker-compose
. To force the removal, prependsudo
to either of the above commands and run again.
Where to go next
- User guide
- Getting Started
- Command line reference
- Compose file reference
- Sample apps with Compose
compose, orchestration, install, installation, docker, documentation
© 2019 Docker, Inc.
Licensed under the Apache License, Version 2.0.
Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc. in the United States and/or other countries.
Docker, Inc. and other parties may also have trademark rights in other terms used herein.
https://docs.docker.com/compose/install/
Pick Your Operating System
You came here to ask, «how do I install Docker?» The answer can be straightforward if you’re willing to accept my way, but the steps differ based on which operating system is utilized. To make things more complicated, there are a few ways to install Docker on your OS that are largely based on preference. Today I’m going to walk you through my preferred method. This isn’t the only way, but I’ve found it to be the best way to get up and running with ease. For Ubuntu, we’ll be setting up the Docker Engine. For Windows and macOS, we’ll be using Docker Desktop.
Click on any of the links below to get started with installing Docker.
- Installing Docker on Ubuntu
- Installing Docker Compose on Ubuntu
- Automated Installation Script for Linux (Ubuntu)
- Installing Docker Desktop on macOS
- Installing Docker Desktop on Windows and WSL2
Installing Docker on Ubuntu
For Ubuntu, we’re going to install Docker Engine and Docker Compose using the Docker and Compose repositories. This also happens to be the recommended approach by Docker.
Follow Along on YouTube
Set Up
- Delete any prior versions if you had installed them.
sudo apt-get remove docker docker-engine docker.io containerd runc
- Update your system and install the necessary dependencies.
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
- For security purposes, add Docker’s official GPG key. Read more about that here.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
- Set up the stable repository.
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
That’s quite a few steps, but if you followed along exactly, you should be ready to install Docker!
Installation
- Install the latest version of Docker, along with its dependencies.
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
If you are running a later version of Ubuntu than what Docker has official builds for, you may get the following
error during this step.
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package docker-ce is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'docker-ce' has no installation candidate
E: Unable to locate package docker-ce-cli
E: Unable to locate package containerd.io
E: Couldn't find any package by glob 'containerd.io'
E: Couldn't find any package by regex 'containerd.io'
But don’t worry! We’ll just need to go install the latest version that is available. This can be done with the
following command INSTEAD of the one above.
sudo apt-get install -y docker.io
- Verify your install by running your first image.
sudo docker run hello-world
- Add your user as an admin to the Docker user group.
sudo usermod -aG docker $USER
Doing this last step means you no longer have to append sudo
to run Docker commands!
Uninstall
Fed up with Docker on your Ubuntu box? Uninstall and remove the configuration files with the following commands.
sudo apt-get purge docker-ce docker-ce-cli containerd.io
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
Installing Docker Compose on Ubuntu
Install
You must have completed the installation of Docker Engine in the steps above before you can install Docker Compose. Assuming you’ve done so without any errors, let’s continue on!
- Download the stable release of Docker compose.
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Unlike the installation for Docker Engine where it automatically installs the latest version, Docker Compose has to have the version manually specified. At the time of writing, the latest version is 1.29.2
. The latest version can be viewed at the Compose repository release page on GitHub. Feel free to substitute the version in the command above as needed.
- Make the downloaded binary executable.
sudo chmod +x /usr/local/bin/docker-compose
Uninstall
To remove Docker Compose, utilize the following command (assuming you installed with curl
as we did above).
sudo rm /usr/local/bin/docker-compose
Automated Installation Script for Linux (Ubuntu)
An automated installation script can be found here. The contents are pasted below.
#!/bin/sh
echo "Starting docker community edition install..."
echo "Removing any old instances of docker and installing dependencies"
apt remove -y docker docker-engine docker.io containerd runc
apt update
apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
echo "Dowloading latest docker and adding official GPG key"
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
echo "Pulling the latest repository"
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt update
echo "Installing docker community edition"
apt install -y docker-ce docker-ce-cli containerd.io
echo "Docker install completed, installing docker-compose"
echo "Dowloading docker-compose 1.29.2 - be sure to update to the latest stable"
curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o
/usr/local/bin/docker-compose
echo "Setting binary permissions"
chmod +x /usr/local/bin/docker-compose
echo “Docker and docker-compose install complete”
# Run docker as non-root user on Ubuntu
sudo usermod -aG docker $USER
Installing Docker Desktop on macOS
Note that Docker Desktop comes pre-equipped with Docker Engine, Docker Compose, Kubernetes, and a few other goodies.
Installation
Intel or Apple Silicon
Depending on which chipset you have on your Mac, you’ll need to install one of two versions of the Docker Desktop application. As this is a GUI application, there’s not much needed other than navigating to the correct site and installing the .dmg file. Just drag and drop the Docker icon into your Applications
directory.
Docker for macOS with Intel
The official link for installing Docker Desktop for macOS with an Intel chipset can be found here.
Apple Silicon
We’ll also need to take a few prior steps to get Docker Desktop running with Apple Silicon. Namely, you’ll need to install Rosetta 2 with the following command.
softwareupdate --install-rosetta
Afterward, install Docker Desktop for macOS with an Apple Silicon chipset from here.
Uninstall
Within the Docker Desktop toolbar item, navigate to the menu > Troubleshoot
> Uninstall
. See the screenshot below.
Installing Docker Desktop on Windows and WSL2
Note that Docker Desktop comes pre-equipped with Docker Engine, Docker Compose, Kubernetes, and a few other goodies. Firstly, you will need Docker Desktop even if you want Docker to only run on WSL. This is due to the sandboxed nature of WSL.
Installation
Windows
- First, you’ll need to ensure that virtualization is enabled for your CPU in the BIOS. This differs amongst motherboard manufacturers and chipsets (namely Intel and AMD). A quick Google search will get you going though.
- The executable for Docker Desktop for Windows can be found here. It can also be found on Docker Hub. Click the installer, follow the prompts and wait for it to be downloaded.
- During the process, be sure to allow the prompts for
Enable Hyper-V Windows Features
and theInstall required Windows components for WSL 2
.
WSL2
You’ll need to complete the steps for installing Docker Desktop on Windows before you can utilize WSL2. However, once you’ve completed it, feel free to come back to this section.
- Enable
Use the WSL2 based engine
in the Docker Desktop for Windows settings andApply & Restart
.
- Be sure that WSL2 is set as your default and current distribution.
Check the current WSL mode.
If not set to v2, upgrade your existing Linux.
wsl.exe --set-version (distro name) 2
Set v2 as the default version.
wsl.exe --set-default-version 2
- Navigate to
WSL Integration
and make sureEnable Integration with my default WSL distro
is checked.
Uninstall
Docker Desktop can be uninstalled from the Apps & features system settings. Just search for Docker Desktop
and select Uninstall
. Follow the prompts.
More Questions or Need Help
Be sure to check out the official documentation for Docker Engine and Docker Desktop and if you have more questions, feel free to send a message with any of the media icons below!