Compose: docker-compose exec work on "run" containers

Created on 5 Mar 2019  路  15Comments  路  Source: docker/compose

Example use case

docker-compose.yml

version: "3.2"
services:
  foo:
    image: debian:9
    command: sleep 10000
  1. docker-compose run -d foo
  2. docker-compose exec foo bash

Current Result:

ERROR: No container found for foo_1

Desired result

It would be nice if not only did docker-compose exec check for containers created by up, but also run. This is already done for commands like down and ps

Example: docker-compose ps

          Name              Command     State   Ports
-----------------------------------------------------
foo_foo_run_382b47cedaf4   sleep 10000  Up 

Alternative solutions

If for some reason mixing the uped and runed containers together in exec is incompatible with use cases/maintaining backwards compatibility, then specifying a flag that either "Only execs using run containers" or combines the list of up and exec containers. Which ever you think is best if this is needed.

Current work around

I currently have to have to use a mix of bash, docker-compose ps, or docker ps commands to find the container I want to exec into

arerun kinenhancement stale

Most helpful comment

This would be a good one to have. Will be giving this a try perhaps this weekend.

All 15 comments

This would be a good one to have. Will be giving this a try perhaps this weekend.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

not stale.

This issue has been automatically marked as not stale anymore due to the recent activity.

@collin5 could you fix the failed test in your PR #6647 ?

Sure thing. Will do by this weekend.

thanks 馃檪

How would you identify the container to exec into if you had ran docker-compose run twice ?

TL; DR

"Just always use the last one" would be a good starting point


I personally do this in a script (We'll call this Idea 1):

  • If there is only one -> exec into that one
  • If there are more than one:

    • List them, number from 1 to X

    • Wait for you to select which one you want.

Of course, this might not be how we want to possibly strategies:

  • Idea 2: Just always use the last one

    • Maybe you add a argument, say --index or something. Of course that index would be blindly picking from the list from idea 1

  • Idea 3: Use Idea 1 if you have a TTY, else use Idea 2. I'm not talking about if the container has a tty or not, I mean if the docker-compose executable has an open tty or not, this is the same check that is often used to check if colors should be output or not, like by grep and other commands.

Hey @glours, sorry for the delay on this. Been caught up with some stuff at work lately. I've updated PR #6647 and all tests should now be passing.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically closed because it had not recent activity during the stale period.

BAD BOT!

following

we have the same issue, could we add some additional flag like --no-index in a future?

Was this page helpful?
0 / 5 - 0 ratings