问题
If I type the following commands in boot2docker as shown on the docker website:
curl -L https://github.com/docker/compose/releases/download/1.1.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
When I type the following commands to check if the installation was successful, I get:
/usr/local/bin/docker-compose: line 1: syntax error: unexpected newline
So, how can I install docker-compose on boot2docker ?
回答1:
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-composepackage insideboot2dockerseems 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
boot2dockerVM is restarted (since changes don't persist), you can usebootlocal.shlike 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 -cgymnastics are required sincetce-loadcannot be run asroot, andbootlocal.shis run asroot. Thechmodofbootlocal.shshould be unnecessary once #915 is fixed.
Add-ato theteecommand 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-composewithpip install -U docker-compose>=1.3.0rc1or 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 a profile 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.
回答2:
There is one more solution of running docker-compose under Windows using Babun (a famous port of Cygwin shell with all kinds of enhancements, including a package manager).
Here is how:
1.) Install Babun 2.) Open it and instal required dependencies for Python and Pip:
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
3.) Finally run
pip install -U docker-compose
The solution is not mine, taken from here: http://habrahabr.ru/post/260329/
I have a strong opinion, that docker-compose must be installed on a host, not a boot2docker VM, so you don't need to ssh all the time.
回答3:
You can install docker-compose on Windows with pip:
pip install -U docker-compose
回答4:
It seems they haven't added native support into the Windows version of Boot2Docker yet.
So for the moment, you can use docker-compose as how you've done with fig previously: run it as a docker container.
回答5:
boot2docker versions >= 1.7.0 have 64 bits userspace. This means that prebuilt binaries from their github repository are working out of the box.
I have used the information in VonC's answer above to write a script that downloads the latest version (or a specific version, see the commented part in the code) and persists it. It will only download the file once, but it will put it on the path on every startup of boot2docker.
Instructions:
boot2docker sshfrom any terminal.- paste the script and press enter.
exitand then runboot2docker restart && boot2docker ssh- When the box is restarted, run
docker-composeto see that it responds with its command list.
On Windows, the boot2docker restart command has a tendency to fail the first time. But it is just to run that command again.
echo 'if [ ! -f /var/lib/boot2docker/etc/docker-compose-`uname -s`-`uname -m` ]; then
echo "Download docker-compose..."
# Download latest version
curl -L https://github.com/docker/compose/releases/download/$(curl -s -L https://github.com/docker/compose/releases/latest | \
grep -Eo -m 1 docker/compose/releases/tag/\([0-9.]*\) | \
grep -o [0-9.]*)/docker-compose-`uname -s`-`uname -m` \
> /var/lib/boot2docker/etc/docker-compose-`uname -s`-`uname -m`
# Download fixed version
# curl -L https://github.com/docker/compose/releases/download/1.3.1/docker-compose-`uname -s`-`uname -m` \
# > /var/lib/boot2docker/etc/docker-compose-`uname -s`-`uname -m`
echo "Done!"
fi
echo "Install docker-compose on path..."
cp /var/lib/boot2docker/etc/docker-compose-`uname -s`-`uname -m` /usr/local/bin/docker-compose &&
chmod +x /usr/local/bin/docker-compose
echo "Done!"
' | sudo tee /var/lib/boot2docker/bootlocal.sh > /dev/null && \
sudo chmod +x /var/lib/boot2docker/bootlocal.sh
回答6:
Things have progressed and lately, I've had the most success with the following method, which allows you to run it natively on Windows, by using Docker.
First, you'll want to install the Docker CLI for Windows:
curl -L https://get.docker.com/builds/Windows/x86_64/docker-latest.exe > /usr/bin/docker
chmod +x /usr/bin/docker
Next, build the docker-compose image from the Github repository:
docker build -t docker-compose github.com/docker/compose
Then, simply set up an alias to run the container:
alias docker-compose='docker run --rm -ti -v /var/run/docker.sock:/var/run/docker.sock -v `pwd`:`pwd` -w `pwd` docker-compose'
I've been using this for a while now and haven't ran into any problems -- the functionality is exactly what you'd expect as if using the binary natively, you just need to make sure your shared folders are mapped correctly into the B2D/Docker-Machine VM. I find it easiest to mirror the paths in the VM as they are on the host so my docker-compose.yml file isn't quite so confusing.
回答7:
I got success following this issue on github
- install docker-machine;
- install python (3.4.3 worked fine)
- install pip;
after pip... run this command to install docker-compose:
`pip install git+git://github.com/docker/compose.git`
Not believing? watch this proof
回答8:
https://github.com/docker/compose/releases/tag/1.5.0rc3 "Compose is now available for Windows."
回答9:
The easiest way to install Docker Compose (and Docker) on Windows, is to use the chocolatey (a package manager for Windows) package docker-compose, which should be installed after the package docker. This will free you from the many obstacles, when installing it manually and gives you an easy way to update your installation.
If you´re not familiar with chocolatey, just install it - e.g. on a administrative commandline with:
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
Now that chocolatey is installed, the only thing that´s left is to fire up a administrative Powershell and do:
choco install docker
choco install docker-compose
As a sidenote: You don´t need Boot2Docker anymore to run Docker on Windows - Docker natively support´s Windows for some time now. So no need for that anymore.
回答10:
This has been my go-to answer for getting Compose installed inside of boot2docker. If anyone would like to entertain VonC's suggestion to run Compose against their host's Docker host from within a container, I've created a journeyman developer's container that follows Compose's guidelines and is easy to install and run.
If you have a Bourne shell-like environment on Windows, you can simply run:
curl -L https://git.io/vuEqk -o /usr/local/bin/room
chmod +x /usr/local/bin/room
You can start a container on any path and take it from there by simply running:
room
You can optionally pass command arguments, so if you find yourself in a working directory that has a Compose configuration file, this would suffice to get everything up and running:
room docker-compose up
If your missing a supportive shell environment, installing one of the Git distributions for Windows which include the Git Bash prompt would suffice or you can directly use the prompts from one of either MinGW or Cygwin. If not, you can always SSH into your Docker Machine and install there.
来源:https://stackoverflow.com/questions/29289785/how-to-install-docker-compose-on-windows