1

I am using docker compose to create a network of containers, where one of the containers requests another to run a process. The client also has to monitor these process in case of errors or when it completes. My approach is to use python's subprocess Popen like this:

process = subprocess.Popen(cmd,stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

where cmd is ['docker-compose', 'exec', 'service2', 'sh', '-c', 'cp sourcefile /destination && python run.py']

But I get this error

[Errno 2] No such file or directory: 'docker-compose': 'docker-compose'

I tried executing the same command in bash mode on the client container and got

bash: docker-compose: command not found. I thought of doing a dind, but is that really necessary? This command works on my host machine docker-compose run --rm service2 python apples.py shell. What's the right approach bearing in mind I need to query the returncode of the process running in container service2 from service1 at anytime. I declared a bridge-network. Thanks

4
  • Do you have Docker Compose installed in your image? Commented Jan 10, 2019 at 14:29
  • No.Generally I thought to docker in docker was bad practice. Containers should share the host daemon right? Would need to install the docker daemon as well to use docker compose in the container. 'am new so just asking really. Is that the way to go? Commented Jan 10, 2019 at 14:56
  • You can’t run a binary that’s not in your container. That doesn’t mean both the client and server halves have to be running in the container, just that the container must have its own /usr/bin/docker-compose. Commented Jan 10, 2019 at 16:48
  • @DavidMaze is this the best approach? I declared a network and expose ports and just wonder if I could avoid DIND. Might as well have a VM and lump them all together which isn't ideal? Commented Jan 10, 2019 at 23:21

2 Answers 2

1

I tried suggestion from here added

COPY --from=library/docker:latest /usr/local/bin/docker /usr/bin/docker COPY --from=docker/compose:1.23.2 /usr/local/bin/docker-compose /usr/bin/docker-compose to my dockerfile and was able to use the original docker-compose command. Still not sure if best practice but it worked.

EDIT: added to the above I set also set an environment variable in my docker file for docker host like RUN export DOCKER_HOST="tcp://0.0.0.0:2375" now docker-compose service2 exec -c 'cmd'works with subprocess.Popen created inside the service1 container.

Sign up to request clarification or add additional context in comments.

Comments

0

In your command, use the absolute path to the docker-compose executable on your machine.

5 Comments

Hi Matias, I have a docker-compose.yml. Is that the same as .exe. I am on ubuntu 16.04 BTW. Could you give an example of how you will do this? Thanks
@mikey1 once you're logged into your host that you're running this on, try running which docker-compose to find the full path to that executable. That's what should be in your Python command instead of just 'docker-compose'. hope this helps
I did which docker-compose but still got this in bash mode bash: /usr/local/bin/docker-compose: No such file or directory in the container.
An example of the path (maybe from your platform), or hints as to how to find the absolute path would have been useful.
sure -- on my amazon linux host, the docker-compose executable lives here: /usr/local/bin/docker-compose -- i found out where it lives exactly by running the command which docker-compose

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.