2

I'd like to run a Docker container on a server by running the docker command on my computer. I install Ubuntu 18.04.3 (LTS) x64 on my server, create a new non-root user

root@server:~#  useradd --create-home --shell /bin/bash unpriv

configure SSH and connect to the server as non-root user

me@local:~#  ssh unpriv@SERVER_IP

to install rootless Docker by running

unpriv@server:~#  curl -sSL https://get.docker.com/rootless | sh

As the output of the script tells me, I add

export PATH=/home/unpriv/bin:$PATH
export DOCKER_HOST=unix:///run/user/1000/docker.sock

to /home/unpriv/.bashrc, which I then re-source

unpriv@server:~#  source .bashrc

Then I start the Docker service

unpriv@server:~#  systemctl --user start docker

Now I can run a Docker container from my SSH session

unpriv@server:~#  docker run --rm hello-world

However, if I set

me@local:~#  export DOCKER_HOST=ssh://unpriv@SERVER_IP

on my computer and try to run the container, I get an error

me@local:~#  docker run --rm hello-world
docker: error during connect: Post http://docker/v1.40/containers/create: command [ssh -l unpriv 161.35.202.145 -- docker system dial-stdio] has exited with exit status 127, please make sure the URL is valid, and Docker 18.09 or later is installed on the remote host: stderr=bash: docker: command not found
.
See 'docker run --help'.

I assume that the added environment variables PATH and DOCKER_HOST that I added to home/unpriv/.bashrc on the server are not considered. Hence, the docker command is not found (on the server). What am I missing in my configuration?

maiermic
  • 141
  • 4
  • 1
    Did you add those variables to the beginning or end of the `.bashrc`? There's typically a line to stop parsing the file for non-interactive shells. – BMitch Jun 11 '20 at 20:15
  • @BMitch You are right. Adding the environment variables at the beginning works. I added them at the end :facepalm: – maiermic Jun 11 '20 at 20:31

1 Answers1

2

Thanks to @BMitch. I added the environment variables at the end, but should have added them at the beginning of /home/unpriv/.bashrc, e.g. before

# If not running interactively, don't do anything
[ -z "$PS1" ] && return
maiermic
  • 141
  • 4
  • Just checking in, this is still the solution as of the posting of this comment. Just be aware your distro's check for non-interactive mode might look a little different. On Debian 11, it was a case statement. – darethas Aug 07 '22 at 19:23