Compose: Add `--service-ports` support to `docker-compose up`

Created on 29 Mar 2017  路  10Comments  路  Source: docker/compose

Related to this issue, it seems that docker-compose up doesn't support the same --service-ports flag.

Ideally, I would like to be able to specify this flag in some compose.yml file, so that I can run docker-compose -f foo.yml up -d and still be able to use ipdb.

Looking at the code a bit, I wonder - is this because the ports set by the service-ports flag need to be set when the container is built?

If that's the case, would it be as simple as setting ports correctly in some docker-compose.yml file passed into up?

Unfortunately, setting ports: [] in the yaml doesn't result in opening the service ports, even though that appears to be what happens when service-ports is set when calling run.

Any chance this will be supported in a future version?

arecli kinquestion

Most helpful comment

In order to run pdb with Docker, I needed to run docker-compose run --service-ports django to expose the necessary ports as per https://www.calazan.com/using-ipdb-docker-compose-interactive-debugging/. I could not get it to work with docker-compose up. Is it possible to configure the docker-compose.yml to support --service-ports? or Is it possible to add a flag --service-ports with docker-compose up?

All 10 comments

Sorry, can you be clearer as to what you expect to happen when using that option? docker-compose up will always expose the ports as specified by the service definition in the docker-compose.yml file.

In order to run pdb with Docker, I needed to run docker-compose run --service-ports django to expose the necessary ports as per https://www.calazan.com/using-ipdb-docker-compose-interactive-debugging/. I could not get it to work with docker-compose up. Is it possible to configure the docker-compose.yml to support --service-ports? or Is it possible to add a flag --service-ports with docker-compose up?

Again, service ports are always exposed when you run docker-compose up.

This might be the wrong place for this, but I think I have a very similar issue. In ruby programs there is something called binding.pry, which allows for "interactive debugging." I've been reading around in order for this interactive session to run, docker needs to create a tty session. docker-compose run with --service-ports creates that interactive session as well as mapping ports between service and host. So I think what we are actually after is the ability to run docker-compose up while enabling a tty session with a specific container, in my case "web" defined in docker-compose.yml.

Also, I am aware you can attach to a running container and do interactive debugging that way. But I was just trying to recreate the containerless experience of running rails s and the interactive debugger just working.

@shin- It seems like they are not exposed in the same way, since ipdb doesn't work with docker-compose up, but it does with docker-compose run --service-ports django.

@katylava Do you have a reproduction case you can share?

@shin- here you go: https://gist.github.com/katylava/3559c29160573488a7bbccb474b55356 (note there are 5 files in that gist, it's not just the README at the top).

@katylava Ok, I checked this, it's not a port related issue at all - the cause of the error is that ipdb expects an open TTY, which exists by default when doing docker-compose run, but not so when doing docker-compose up. Adding tty: true to the service definition will prevent the crash from happening (although note that docker-compose up is not interactive - it just outputs logs, so you won't be able to issue any ipdb commands that way)

So yeah - for anyone doing interactive debugging, run is indeed the way to go. Fundamentally, up is not designed to address this use case, but this has nothing to do with exposing ports, and everything to do with up not being an interactive command by design.

Was this page helpful?
0 / 5 - 0 ratings