Cannot assign address inside a Docker container

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

1 Answer

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 :-)

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like