Running Docker as a non-root user allows you to share a directory on the host and create files with non-root permissions. This is what I did to make the ~/docker directory available.
sudo usermod -aG docker lance
sudo service docker restart
newgrp docker
chown :docker docker
docker run -v /home/lance/docker:/code -u docker r-base