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?