3

I want to use the rsub package for Sublime Text, in order to edit code inside a Docker container which runs on a remote server. However when I execute

rsub my_code.py

I get the error:

/usr/local/bin/rsub: connect: Cannot assign requested address
/usr/local/bin/rsub: line 392: /dev/tcp/localhost/52698: Cannot assign requested address

Line 392 basically corresponds to this instruction:

exec 3<> "/dev/tcp/localhost/52698"
bash: connect: Cannot assign requested address
bash: /dev/tcp/localhost/52698: Cannot assign requested address

If I exit the Docker container and run the same instruction on the remote server, it works nicely (or at least it doesn't give me any error messages). Can you help me fix this problem? I can modify the Dockerfile if needed. I can also post it here if you think it's needed, but I should doctor it a bit before to remove sensitive information.

EDIT: I include the part of the rsub script which raises the error. Note that at this point in the script, $host=localhost and $port=52698. I double checked that with echo statements.

# connect to textmate and send command
#
exec 3<> "/dev/tcp/$host/$port"

if [ $? -gt 0 ]; then
    echo "Unable to connect to TextMate on $host:$port"
    exit 1
fi

read -r server_info 0<&3

log $server_info

for i in "${!filepaths[@]}"; do
    open_file "$i"
done

echo "." 1>&3

if [[ $nowait = true ]]; then
    exec </dev/null >/dev/null 2>/dev/null
    ( (handle_connection &) &)
else
    handle_connection
fi

EDIT:I've been asked about the host OS. This is the result of uname -a when on the remote host, and outside the Docker container (server name removed):

Linux xxxxxxx 4.4.0-104-generic #127-Ubuntu SMP Mon Dec 11 12:16:42 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

and this is the result of the same command when run inside the Docker container:

Linux yyyyyyyyy 4.4.0-104-generic #127-Ubuntu SMP Mon Dec 11 12:16:42 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

xxxxxxx and yyyyyyy are different strings. Also, when inside the Docker container, I can't find any directory tcp inside the dev directory:

root@7f199087c883:~# ls /dev/tcp
ls: cannot access '/dev/tcp': No such file or directory
6
  • it's actually a Perl script. I'm very bad with Perl...I can post the whole script, but I won't probably be able to create a MVE without someone else's help. Unfortunately the Perl whiz left...
    – DeltaIV
    May 17, 2018 at 17:05
  • I added the part of the Perl script, from the command which raises the error to the end. I can include the rest, if you want. It's about 400 lines, though.
    – DeltaIV
    May 17, 2018 at 17:08
  • 1
    Just a consideration, Docker containers are typically not "full OS" containers (like LXD or OpenVZ based VPSes are), and binding to ports might not behave the same way with them. As such, you may get it to work fine on the 'remote' host, but you might not be able to get it working on remote docker containers (which sit 'within' the host and have a NAT component).
    – Thomas Ward
    May 18, 2018 at 16:07
  • @ThomasWard indeed, it works fine on the 'remote' host when I'm outside the Docker container, as you predicted.
    – DeltaIV
    May 18, 2018 at 16:14
  • Keep in mind that with Docker, to bind to a port it's supposed to be configured in Docker container at runtime what ports are to be bound with. This said, if you can go into the Docker container, see if there's anything at /dev/tcp/localhost. I'll bet the chances are there isn't one, and that this is a Docker-specific issue. Since I don't know the host OS in this equation (assuming Ubuntu), I can't give you any suggestions of where to look next, other than the standard "'It's a docker and how its containers work' problem." response :/
    – Thomas Ward
    May 18, 2018 at 16:16

1 Answer 1

3

In the end, since rsub was working on the remote host, the simplest solution was to:

  • log on to the remote host (without starting the container)
  • use rsub to edit any files on the remote host, in a session of Sublime on my local pc
  • then build the container again.

It's a bit slow, because each time I make changes I need to rebuild, but:

  • the remote host has a lot of computational power, so rebuilding is quick;
  • it's a better way to work anyway: each time I commit changes to the project, I should rebuild the container anyway. This prompts me to commit changes more often, which is always a good idea :-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .