Search code examples
dockerdocker-compose

services.app.build contains unsupported option: 'ssh'


I am trying to create a docker-compose file that uses a previously made docker file that I build with this command:

docker build --ssh default=~/.ssh/id_rsa .

However I am having trouble replicating this in a docker-compose yml file:

version: '3.8'

services:
    app:
        image: python:3.11
        build:
            context: .
            ssh:
                - default=~/.ssh/id_rsa
            dockerfile: Dockerfile
        ...

I keep getting the same error:

ERROR: The Compose file './compose.yml' is invalid because:
services.app.build contains unsupported option: 'ssh'

which is very confusing for me because according to the documentation this should be fine.

docker-compose version 1.29.2, build unknown

Please help I don't know what I'm doing wrong.


Solution

  • Compose file format version 3 doesn't support a build: { ssh: } option.

    This is relevant because you're using the old Python-based version of Docker Compose. This supports file formats versions 1, 2, and 3, but it does not support any extensions in the "specification" file format.

    For build: { ssh: } to work, you need to update to the newer plugin-based version of Compose. It would be good practice to update the version: line to indicate you're using "specification"-only features (I tend to write version: "4.x"), but the plugin version of Compose ignores the version: line (and gives an incorrect warning if it's present).

    It's also possible your system has both versions installed, in which case docker compose build (with a space between docker and compose, not a hyphen) might work.