大网数据广告活动
服务器运维问答

Installing docker/compose-bin plugin on Google's Container Optimized OS

· 52CE 我爱测

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…

问题原文

原帖链接 · 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 version
    
  • using a function:

    ~/.profile:

    docker() {
        if [ "$1" = compose ]; then
            command docker run --rm docker "$@"
        else
            command docker "$@"
        fi
    }
    export -f docker
    
    $ docker compose version
    
  • using 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2023-05-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。