Compose: Context not found when given on docker-compose CLI

Created on 8 May 2020  路  6Comments  路  Source: docker/compose

Description of the issue

When using the docker-compose command line --context parameter, the context reports not found, even though it's found when using docker commands.

Context information (for bug reports)

Output of docker-compose version

docker-compose version 1.26.0-rc4, build d279b7a8
docker-py version: 4.2.0
CPython version: 3.7.7
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019

Output of docker version

Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b7f0
 Built:             Wed Mar 11 01:25:46 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       afacb8b7f0
  Built:            Wed Mar 11 01:24:19 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

Output of docker-compose config
(Make sure to add the relevant -f and other flags)

services:
  test:
    container_name: test
    image: alpine
version: '3.6'

Steps to reproduce the issue

  1. Create a context (in this case with ssh):
docker context create testctx --default-stack-orchestrator swarm --docker "host=ssh://user@remote"
  1. Verify context is functional:
docker --context testctx ps
  1. Issue a compose command on the context (this is what fails):
docker-compose --context testctx up -d
  1. Issue the same compose command except with the host parameter to verify endpoint (this works for me):
docker-compose -H ssh://user@remote up -d

Observed result

ERROR: Context 'testctx' not found

Expected result

The docker-compose should remotely execute on the context's machine.

Stacktrace / full error message

(with --verbose)

docker.utils.config.find_config_file: Trying paths: ['/home/user/.docker/config.json', '/home/user/.dockercfg']
docker.utils.config.find_config_file: No config file found
ERROR: compose.cli.main.main: Context 'testctx' not found

Additional information

OS version / distribution, docker-compose install method, etc.

Ubuntu 18.04.

Docker installed via this ansible role, docker-compose installed via ansible task:

- name: Update docker-compose to bleeding edge # Required for docker context support
  get_url:
    url: https://github.com/docker/compose/releases/download/1.26.0-rc4/docker-compose-Linux-x86_64
    dest: /usr/local/bin/docker-compose
    checksum: sha256:3ad2031c7daae160b8987538a60261475b3e17dfccf6fb96c1ae67d23afecdb8
kinbug

Most helpful comment

Maybe I have solved it.

Before running docker-compose --context testctx, I executed docker context use testctx. Then docker-compose recognized my context, even if I set the context back to "default".

However, I'm not sure why it works. So I cannot guarantee that it will work in your environment.

$ docker context use testctx
$ docker context use default
$ docker-compose --context testctx up
# docker-compose finds testctx and works fine

All 6 comments

I saw same problem.

same issue here

docker-compose version 1.26.2, build eefe0d31
Docker version 19.03.12, build 48a66213fe

Maybe I have solved it.

Before running docker-compose --context testctx, I executed docker context use testctx. Then docker-compose recognized my context, even if I set the context back to "default".

However, I'm not sure why it works. So I cannot guarantee that it will work in your environment.

$ docker context use testctx
$ docker context use default
$ docker-compose --context testctx up
# docker-compose finds testctx and works fine

+1 docker-compose should respect the DOCKER_CONTEXT environment variable and the current user's docker context config files

@pandanoir sure, issuing a docker context use <> would work because then you're in the proper context, but the docker-compose --context argument would be pointless if that was required. The --context argument should either switch contexts only for that command, or only execute the given compose file on the context given.

@impala454

(I'm sorry if I misread your comment)

I tried docker context use to switch context, and then back to previous context(default). I ran docker-compose --context testctx up in default context and docker-compose worked fine.

While my solution seems to do nothing at first glance, my solution has some side effects that make docker-compose work properly. I don't know what the side effect is.

Was this page helpful?
0 / 5 - 0 ratings