'Failed to build node app on Dokku running as a Docker image on Macos

I've followed the steps from original documentation to deploy a Docker image of Dokku on Macos:

docker run \
    --env DOKKU_HOSTNAME=dokku.me \
    --name dokku \
    --publish 3022:22 \
    --publish 8080:80 \
    --publish 8443:443 \
    --volume /var/lib/dokku:/mnt/dokku \
    --volume /var/run/docker.sock:/var/run/docker.sock \
    dokku/dokku:latest

Source: https://hub.docker.com/r/dokku/dokku

Then I've initialized the ssh-keys within the container, and made an alias for the hostname dokku.me as advised. Now I can connect to the Dokku container and run commands on it, like creating a new application:

dokku apps:create node-test
dokku git:initialize node-test

I've added a new remote to my node project and tried to push:

git remote add dokku [email protected]:node-test

But pushing fails with an error that I don't understand completely:

➜  node-test git:(node-test) git push dokku master
Enumerating objects: 27, done.
Counting objects: 100% (27/27), done.
Delta compression using up to 16 threads
Compressing objects: 100% (19/19), done.
Writing objects: 100% (27/27), 2.95 KiB | 301.00 KiB/s, done.
Total 27 (delta 4), reused 3 (delta 0), pack-reused 0
-----> Cleaning up...
-----> Building node-test from herokuish
-----> Setting config vars
       CURL_CONNECT_TIMEOUT:  90
-----> Setting config vars
       CURL_TIMEOUT:  600
-----> Adding BUILD_ENV to build environment...
       BUILD_ENV added successfully
remote: Error response from daemon: Mounts denied:
remote: The path /home/dokku/node-test/cache is not shared from the host and is not known to Docker.
remote: You can configure shared paths from Docker -> Preferences... -> Resources -> File Sharing.
remote: See https://docs.docker.com/docker-for-mac for more info.
remote: Error: failed to start containers: c1ab941dcf71650f99c3199546277ec333463a09695d0dcf1cac755d3ec7bacf
remote: You cannot attach to a stopped container, start it first
remote: 2022/01/27 15:48:15 exit status 1
To dokku.me:node-test
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'dokku.me:node-test'

From Docker Desktop, I've updated the file sharing options and added /var/lib/dokku, after I've created this folder in my Mac's filesystem.

➜  node-test git:(node-test) ls -al /var/lib/dokku
total 0
drwxr-xr-x  2 root  wheel   64 Jan 27 14:22 .
drwxr-xr-x  4 root  wheel  128 Jan 27 14:22 ..

I suspect it has something to do with the mounted folders in the Docker host, but I cannot figure out exactly what it is.

Macos version 12.01

Dokku version

root@b6df7b8bc9b0:/tmp# dokku version
dokku version 0.26.7

Docker version:

➜  node-test git:(node-test) docker version
Client: Docker Engine - Community
 Cloud integration: 1.0.12
 Version:           20.10.5
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        55c4c88
 Built:             Tue Mar  2 20:13:00 2021
 OS/Arch:           darwin/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.5
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       363e9a8
  Built:            Tue Mar  2 20:15:47 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.4
  GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e
 runc:
  Version:          1.0.0-rc93
  GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0


Solution 1:[1]

I've checked again the Docker Installation Nodes for v0.26.7 and noticed the docker container run has an extra parameter when compared to the instructions from Dockerhub:

docker container create \
  --env DOKKU_HOSTNAME=dokku.me \
  --env DOKKU_HOST_ROOT=/var/lib/dokku/home/dokku \
  --name dokku \
  --publish 3022:22 \
  --publish 8080:80 \
  --publish 8443:443 \
  --volume /var/lib/dokku:/mnt/dokku \
  --volume /var/run/docker.sock:/var/run/docker.sock \
  dokku/dokku:0.26.7

The extra param --env DOKKU_HOST_ROOT=/var/lib/dokku/home/dokku seems to fix my issue.

Now pushing to Dokku doesn't throw the Mounts denied error anymore.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kenjiru