Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to restart development container #2906

Closed
ramblingenzyme opened this issue May 1, 2020 · 11 comments
Closed

Option to restart development container #2906

ramblingenzyme opened this issue May 1, 2020 · 11 comments
Assignees
Labels
containers Issue in vscode-remote containers info-needed Issue requires more information from poster

Comments

@ramblingenzyme
Copy link

We've been using a Docker Compose stack as a standardised development environment internally at Easy Agile and it's been great for the most part.

I've pretty regularly run into an issue where my ssh-agent connection fails and the only reasonable solution is to rebuild the container. This not only takes time and does way too much, VSCode doesn't wait for the running container to quit before trying to build and fails.

If we could get an option to restart a development container without rebuilding the container, this would smooth over a real pain point.

@PavelSosin-320
Copy link

If you know the container id you can always restart the container. I tried it but VSCode lost connection anyway. I suppose you want to reuse your container. I already asked to keep PID file of the development container at the client side as a feature. Please vote for it.

@PavelSosin-320
Copy link

@ramblingenzyme you can restart service using docker-compose restart-service but I don't expect a different result. because of a lack of wait-for-reconnect at the client side. When container will be restarted forcibly it will be the same too.

@PavelSosin-320
Copy link

@ramblingenzyme
P.P.S. Nothing is new under the sun and this problem exists from the early days of Cloud backends where services can up and down. The solution was always to communicate with backend asynchronously and observe status, for example, using docker-compose ps waiting until backend will be running for reconnecting.

@ramblingenzyme
Copy link
Author

Hi @PavelSosin-320,
I'm not sure you've understood my issue, but thanks for the input.

I had issues with restarting the container outside of VSCode, but it could just be me. I don't want to reuse a running container, I want to restart the container without rebuilding and have all the remote VSCode stuff spin up, which doesn't seem to happen but I can try again.

The other issue is when I tell VSCode to rebuild while the container is running, it doesn't wait for the container to stop before rebuilding and fails, so it has nothing to do with waiting for the container to start running.

@andyljones
Copy link

This was a pain point for me too, though on top of container restarts I also sometimes want the container to persist beyond the vscode session. I've come to the conclusion that if sometimes I want stop the container but not vscode, and sometimes I want to stop vscode but not the container... then I probably shouldn't be managing it with vscode.

I've since swapped to managing the container with a command-line script and vscode'ing in with 'attach to running container'. My management script looks like this:

#!/bin/bash

export DOCKER_HOST="ssh://[email protected]"

case $1 in
    code )
        uri=$(python -c "import json; desc = json.dumps({'containerName': '/drones', 'settings': {'host':'ssh://aj-server.local'}}); print(f'vscode-remote://attached-container+{desc.encode().hex()}/code')")
        code --folder-uri "$uri" ;;
    build ) 
        docker build docker -t drones ;;
    run )
        docker run -td --name drones -v /home/ajones/code/drones:/code drones:latest ;;
    logs )
        docker logs drones ;;
    stop )
        docker stop drones ;;
    start )
        docker start drones ;;
    restart )
        docker restart drones ;;
    rm )
        docker rm drones ;;
    * ) 
        echo "No command matching '$1'"
esac

It's saved as dev, and ./dev code brings up vscode. The magic folder-uri string comes from this issue.

While my situation is a bit different from yours @ramblingenzyme , I haven't had trouble with vscode reinstalling itself after a restart. After ./dev restart I do need to hit 'reload window' but then vscode comes back up in ~five seconds, as opposed to the ~thirty second attaching to a fresh container takes.

(It'd be even better if vscode auto-reconnected, but this behaviour suffices)

@ramblingenzyme
Copy link
Author

Haven't had any issues with the Compose stack pulling itself down after closing VSCode, not sure what's special about our config.

I need to mess with it again, but I had set "restart: always" and stopped the container from VSCode, which might be the issue. I'll see if pressing restart in the Docker for Mac GUI will work but even if that works, it would be nice to do it from inside VSCode to make the process consistent no matter what OS you're running on.

@chrmarti
Copy link
Contributor

chrmarti commented May 5, 2020

@ramblingenzyme The ssh-agent connection should be reestablished when you reload the window. Could you try F1 > Developer: Reload Window next time?

@chrmarti chrmarti self-assigned this May 5, 2020
@chrmarti chrmarti added containers Issue in vscode-remote containers info-needed Issue requires more information from poster labels May 5, 2020
@ramblingenzyme
Copy link
Author

@chrmarti Will do, but I remember it not working. Today I found things work okay if I don't set a restart policy for the container and restart the dev container using the normal Docker extension.

@github-actions
Copy link

Hey @chrmarti, this issue might need further attention.

@ramblingenzyme, you can help us out by closing this issue if the problem no longer exists, or adding more information.

@chrmarti
Copy link
Contributor

@ramblingenzyme Have you had a chance to try reloading the window to reestablish the ssh-agent connection? Is that the ssh-agent on the host or the container?

@github-actions
Copy link

github-actions bot commented Oct 7, 2020

This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.

Happy Coding!

@github-actions github-actions bot closed this as completed Oct 7, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Nov 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
containers Issue in vscode-remote containers info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

4 participants