compose icon indicating copy to clipboard operation
compose copied to clipboard

Is it possible to add attach function to fig?

Open 0xcb49 opened this issue 12 years ago • 35 comments

For example, Using command "fig attach appname" to enter the container which was created by fig. I think this may be helpful in some cases. Now I know that nsenter can attach a new bash shell on a running container, but I don't know if it's possible to intergrate it with fig. Thanks.

0xcb49 avatar Aug 19 '14 07:08 0xcb49

Need it too!

shuron avatar Aug 31 '14 11:08 shuron

docker-enter (https://github.com/jpetazzo/nsenter/blob/master/docker-enter) is just a bash script. I supposed you can base on that to write a fig-enter script.

marksteve avatar Aug 31 '14 16:08 marksteve

Maybe it's more convenient to use alias below in your terminal. alias attach='bash -c "nsenter --mount --uts --ipc --net --pid --target docker inspect --format \"{{.State.Pid}}\" \$0"' Then you can use attach container_name to enter a container.

0xcb49 avatar Aug 31 '14 16:08 0xcb49

It shouldn't be too difficult to add this using dockerpty, which is what fig is using right now to handle fig run, I think.

dnephin avatar Aug 31 '14 16:08 dnephin

@bcheng049 the docker-enter script also handles some edge-cases (e.g. If you're not using bash as your shell), and makes sure to set up the environment variables of the container and not your host environment. The alias you're suggesting, won't handle those.

thaJeztah avatar Aug 31 '14 17:08 thaJeztah

This would be huge for my team also

erickbrower avatar Aug 31 '14 17:08 erickbrower

@thaJeztah Yes, it is just a snippet to avoid inputing many commands without installing a script.

0xcb49 avatar Aug 31 '14 17:08 0xcb49

Just wanted to clear that up to prevent people trying to solve problems that are already solved in the docker-enter script. Adding this functionality to fig would be a nice addition though (still hoping Docker itself will support this natively).

In the short run, I'd really advice people that want to have it now to install jpetazzo's script. Installing it is just a one-liner as explained in the readme; https://github.com/jpetazzo/nsenter

After installing, entering a running container is just simply docker-enter [container-name]

thaJeztah avatar Aug 31 '14 17:08 thaJeztah

There's two issues here: 1) being able to enter with nsenter and fiddle around with a running container, and 2) a way to get docker run web bash behavior but also bring up the entire stack not just direct links. The first is great for debugging and the second is great for development workflows with volumes mounted into containers. Just bringing up links is not enough for many stacks.

tristanz avatar Sep 11 '14 02:09 tristanz

I think fig up -d, fig run solves 2, but I'm not really clear on why you'd need to bring up services if they aren't linked. A container doesn't need to be running to share volumes.

dnephin avatar Sep 11 '14 03:09 dnephin

The set up I have in mind is proxy -> web -> db. I'd like to be able to bring this stack up, but develop in web using a bash prompt. I haven't found an easy to to do this, such that all the links work.

tristanz avatar Sep 11 '14 04:09 tristanz

attach and interactive is very useful to debug the running software using tools like python pdb.

robsonpeixoto avatar Oct 31 '14 00:10 robsonpeixoto

It's an essential feature to configure docker container. When this feature are release ?

baptistedonaux avatar Nov 13 '14 10:11 baptistedonaux

I agree that fig attach and fig exec, analogous to their docker counterparts, would be good to have. Is anyone here asking for anything other than those?

aanand avatar Nov 13 '14 12:11 aanand

It would be nice if attach was exposed in fig.yml, so that we could specify which one we want to attach to interactive tty on "fig up"

Stono avatar Dec 09 '14 16:12 Stono

@aanand Any update on when this may be available?

Stono avatar Dec 09 '14 16:12 Stono

this would be lovely!

MrMMorris avatar Dec 18 '14 18:12 MrMMorris

I'm strongly against the idea of doing an interactive attach on fig up - it's overloading its purpose.

The correct way to bring up an interactive container with its dependencies is fig run. We just need to get port mapping implemented (see #485, which I'll get to soon).

aanand avatar Dec 19 '14 22:12 aanand

Aanand, you said:

I agree that fig attach and fig exec, analogous to their docker counterparts, would be good to have. Is anyone here asking for anything other than those?

I believe just those two will make a lot of people happy.

I don't use fig scale and I'm not sure if you have considered how fig attach and fig exec would work with those. I suppose if I were to use fig scale I wouldn't care which container was used.

Will this issue address both fig attach and fig exec, or would it be better if a separate issue was logged?

itoed avatar Dec 22 '14 20:12 itoed

oops, wrong key, sorry

dnephin avatar Dec 22 '14 22:12 dnephin