"Error in Authenticator.pre_spawn_start: DockerException Error while fetching server API version" while starting jupyterhub with DockerSpawner

HI, I started using jupyterhub, right now I am fighting with errors, and I hope you can help a little.
I have working jupyterhub configuration:

import environ 
import simplespawner
import tmpauthenticator

ROOT_DIR = environ.Path(__file__) - 2
env = environ.Env()
env.read_env(str(ROOT_DIR.path(".env")))

c.JupyterHub.port = 8008
c.JupyterHub.authenticator_class = tmpauthenticator.TmpAuthenticator
c.JupyterHub.spawner_class = simplespawner.SimpleLocalProcessSpawner
c.Spawner.notebook_dir = NOTEBOOK_DIR

and it’s ok, but right now I’d like to change SimpleLocalProcessSpawner to DockerSpawner. I ran

docker pull jupyterhub/singleuser

and changed above configuration into:

....
c.JupyterHub.spawner_class = dockerspawner.DockerSpawner
c.DockerSpawner.image = 'jupyterhub/singleuser:latest'
docker0 = netifaces.ifaddresses('docker0')
docker0_ipv4 = docker0[netifaces.AF_INET][0]
c.JupyterHub.hub_ip = docker0_ipv4['addr']

Right now I end up with error:

500 : Internal Server Error
Error in Authenticator.pre_spawn_start: DockerException Error while fetching server API version: (‘Connection aborted.’, PermissionError(13, ‘Permission denied’))
You can try restarting your server from the home page.

Can you tell me what am I doing wrong?

It sounds like you can’t access the docker API. Your jupyterhub container needs access to the docker socket. In your docker-compose you need to mount it in your jupyterhub container:

volumes:
“/var/run/docker.sock:/var/run/docker.sock”

There are some good examples here:

Thanks,
Mark

I found solution … sort of. Writing:

sudo chmod 666 /var/run/docker.sock

allows me to run jupyterhub in this configuration. Problem is I must run it after each restart of computer. How to make it permanent?

Is the user that runs jupyterhub in the docker group?