GNS3 / gns3-gui

GNS3 Graphical Network Simulator
http://www.gns3.com
GNU General Public License v3.0
2.17k stars 436 forks source link

Docker integration: Add auxiliary console with docker-exec #1039

Closed ghost closed 8 years ago

ghost commented 8 years ago

The console on docker VMs gives you the input/output of the docker container, which is fine.

But for debugging a shell in the running container (docker exec -ti <container-id> sh) would be very helpful. So I suggest to add an auxiliary console to such a docker-exec.

julien-duponchelle commented 8 years ago

I agree. This mean we need to allocate the aux port by default but it's really simplify the usage of most containers.

julien-duponchelle commented 8 years ago

I will need to check if we can attach a websocket to a exec. I'm not sure the documentation is not clear on this topic. https://docs.docker.com/engine/reference/api/docker_remote_api_v1.22/

ghost commented 8 years ago

Here a workaround for local docker usage:

Create a shell script gns3-docker-exec in /usr/local/bin (or anywhere else in $PATH)

#!/bin/sh
# starts a docker-exec shell for a given hostname

id=$(docker inspect --format '{{if eq .Config.Hostname "'$1'"}}{{.Id}}{{end}}' $(docker ps -q))

[ -n "$id" ] && exec docker exec -ti $id sh -c 'if [ -x /bin/bash ]; then exec bash; else exec sh; fi'

Then create a custom console docker-exec with xfce4-terminal --tab -T "%d_exec" -e "gns3-docker-exec %d". Adapt the terminal program, here xfce4-terminal, to your preference.

Now you can use the custom console docker-exec to connect via "docker exec" to your container.

julien-duponchelle commented 8 years ago

Hmm the websocket is not yet available: https://github.com/docker/docker/issues/9372

I test and we can not attach to the container using websocket

julien-duponchelle commented 8 years ago

I have take a look on the source code. They need to do refactoring before adding this call to the API. I doubt it will arrive fast.

I found a solution not something very clean, but it's the best I can do :( I wrap docker exec. But no tty could be allocated.

Doc about it: https://docs.google.com/document/d/1KGkv1Vm5EgeDusk1qS1svacpuQ1ZUQSVK3XqJ01WKGc/edit#

ghost commented 8 years ago

Thanks !!! Even when it's not perfect it's a good fallback, when you want to debug a container.

Just get those validation error, I assume aux is unknown

Failed validating 'oneOf' in schema['properties']['topology']['properties']['nodes']['items']['properties']['properties']:
    {'oneOf': [{'$ref': '#/definitions/properties_vpcs'},
               {'$ref': '#/definitions/properties_dynamips'},
               {'$ref': '#/definitions/properties_dynamips_frame_relay'},
               {'$ref': '#/definitions/properties_qemu'},
               {'$ref': '#/definitions/properties_virtualbox'},
               {'$ref': '#/definitions/properties_vmware'},
               {'$ref': '#/definitions/properties_iou'},
               {'$ref': '#/definitions/properties_docker'},
               {'$ref': '#/definitions/properties_cloud_host'}],
     'type': 'object'}

On instance['topology']['nodes'][1]['properties']:
    {'adapters': 1,
     'aux': 2003,
     'console': 2001,
     'console_type': 'telnet',
     'environment': 'FTP_UID=1000\nFTP_GID=1000',
     'image': 'ftpd:latest',
     'name': 'ftpd-1'}
Best error message: Additional properties are not allowed ('environment', 'console_type', 'image', 'adapters', 'aux' were unexpected)
julien-duponchelle commented 8 years ago

Validation is fixed