问题原文
原帖链接 · supercoco · CC BY-SA 4.0
I am trying install the docker/compose-bin plugin on a Google Cloud VM with Container Optimized OS (https://hub.docker.com/r/docker/compose-bin/tags).
Has anybody achieved this?
I understand docker is running as a container and I think I have to install the plugin binary in the respective plugins folder inside the container. Am I in the right direction?
I am able to use the old docker-compose (https://hub.docker.com/r/docker/compose/tags) in a container using this script and alias:
#!/bin/bash
VERSION=${1:-1.27.4}
echo "* Add an alias for docker-compose to the shell configuration file ..."
echo alias docker-compose="'"'docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "$PWD:$PWD" \
-w="$PWD" \
docker/compose:'"${VERSION}"''"'" >> ~/.bashrc
echo "* Pull container image for docker-compose ..."
docker pull docker/compose:${VERSION}
echo "* Done"
echo "* To use docker-compose, run 'source ~/.bashrc' or simply re-login"
taken from https://gist.github.com/kurokobo/25e41503eb060fee8d8bec1dd859eff3
But I would really like to use the new plugin.
已采纳解答
原帖链接 · x-yuri · CC BY-SA 4.0
The writable and executable mounts are:
/var/lib/{google,docker,toolbox}(stateful)/var/lib/cloud(stateless,tmpfs, 2 MB)/mnt/disks(stateless,tmpfs, 256 KB)
/var/lib/{google,docker,toolbox} seems like the best option, and /var/lib/google is better then /var/lib/docker because it has o+x (I suppose /var/lib/docker lacks o+x for a reason):
$ sudo curl -sSL \
https://github.com/docker/compose/releases/download/v2.23.3/docker-compose-linux-x86_64 \
-o /var/lib/google/docker-compose
$ sudo chmod o+x /var/lib/google/docker-compose
$ mkdir -p ~/.docker/cli-plugins
$ ln -sf /var/lib/google/docker-compose \
~/.docker/cli-plugins/docker-compose
$ docker compose version
the official installation instructions
where docker looks for plugins
Alternatively one can use the docker image:
using
alias:~/.profile:if [ -f ~/.bashrc ]; then . ~/.bashrc; fi~/.bashrc:alias docker-compose='docker run --rm docker compose'$ docker-compose versionusing a function:
~/.profile:docker() { if [ "$1" = compose ]; then command docker run --rm docker "$@" else command docker "$@" fi } export -f docker$ docker compose versionusing a script:
/var/lib/google/bin/docker:#!/bin/sh -eu if [ "$1" = compose ]; then /usr/bin/docker run --rm docker "$@" else /usr/bin/docker "$@" fi~/.profile:export PATH=/var/lib/google/bin:$PATH$ sudo chmod o+x /var/lib/google/bin/docker $ docker compose version
For the record, I also added the info to the mentioned issue.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
