compose: Context not found when given on docker-compose CLI
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
- Create a context (in this case with ssh):
docker context create testctx --default-stack-orchestrator swarm --docker "host=ssh://user@remote"
- Verify context is functional:
docker --context testctx ps
- Issue a compose command on the context (this is what fails):
docker-compose --context testctx up -d
- 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
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 13
- Comments: 16
Commits related to this issue
- docker: workaround docker-compose not finding the custom context need to invoke docker context for some reason... https://github.com/docker/compose/issues/7434 — committed to avsm/ocurrent-deployer by avsm 4 years ago
- docker: workaround docker-compose not finding the custom context need to invoke docker context for some reason... https://github.com/docker/compose/issues/7434 — committed to avsm/ocurrent-deployer by avsm 4 years ago
Maybe I have solved it.
Before running
docker-compose --context testctx, I executeddocker 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.
Looks like this is due to docker/docker-py#2622 So just an initial use of
docker context use defaultshould be enough to at least work around this issue.Does not fix the problem for me sadly. This is on a fresh install of Docker using getdocker.sh and also after having installed
docker-composeanddocker-pyvia pip3.Getting this:
+1 docker-compose should respect the DOCKER_CONTEXT environment variable and the current user’s docker context config files
Its never a good sign when you find a 2 year old thread about an issue.
Versions
I created the context like so:
I can then run the following and get an output of running containers
However running with docker-compose the command fails
I tired the work around of setting the context and moving it back to default but that did not work either.
@pandanoir sure, issuing a
docker context use <>would work because then you’re in the proper context, but thedocker-compose --contextargument would be pointless if that was required. The--contextargument should either switch contexts only for that command, or only execute the given compose file on the context given.