others-how to deploy a website using jekyll in docker?

1. The process

When you want to deploy jekyll to docker, you will get this error:

root@bw:/opt/bwBlog# docker run --rm \
>   --volume="$PWD:/srv/jekyll:Z" \
>   -it jekyll/jekyll:$JEKYLL_VERSION \
>   jekyll new .
docker: Error response from daemon: error while creating mount source path '/opt/bwBlog': mkdir /opt/bwBlog: read-only file system.
ERRO[0000] error waiting for container: context canceled

How to solve the problem?

docker: Error response from daemon: error while creating mount source path '/opt/bwBlog': mkdir /opt/bwBlog: read-only file system.
ERRO[0000] error waiting for container: context canceled

Here is the solution:

snap remove docker


rm -R /var/lib/docker

sudo apt-get remove docker docker-engine docker.io

reason of the problem:

Since posting this answer, I've learnt that tools installed using snap are installed in a sandbox with limited permissions outside of that sandbox. This is likely the cause as docker won't have access to the external filesystem from its isolated sandbox environment.

by HyperionX

Now try again to install docker:

sudo apt-get update

sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

 sudo mkdir -p /etc/apt/keyrings
 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

 echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null


#Install Docker Engine
 sudo apt-get update
 sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

Then we can verify if docker is installed correctly:

sudo service docker start
sudo docker run hello-world

Now ,let’s create jekyll website again:

bw@bw:/opt/jekyll/bw$ cat create_site.sh
export JEKYLL_VERSION=3.8
docker run --rm \
  --volume="$PWD:/srv/jekyll:Z" \
  -it jekyll/jekyll:$JEKYLL_VERSION \
  jekyll new .
bw@bw:/opt/jekyll/bw$ ./create_site.sh
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create": dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.

we change to use sudo:

bw@bw:/opt/jekyll/bw$ cat create_site.sh
export JEKYLL_VERSION=3.8
sudo docker run --rm \
  --volume="$PWD:/srv/jekyll:Z" \
  -it jekyll/jekyll:$JEKYLL_VERSION \
  jekyll new .

But we got this error:

bw@bw:/opt/jekyll/bw$ ./create_site.sh
Unable to find image 'jekyll/jekyll:3.8' locally
3.8: Pulling from jekyll/jekyll
9d48c3bd43c5: Pull complete
9ce9598067e7: Pull complete
278f4c997324: Pull complete
bfca09e5fd9a: Pull complete
2612f15b9d22: Pull complete
322c093d5418: Pull complete
Digest: sha256:9521c8aae4739fcbc7137ead19f91841b833d671542f13e91ca40280e88d6e34
Status: Downloaded newer image for jekyll/jekyll:3.8
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux-musl]
          Conflict: /srv/jekyll exists and is not empty.
                    Ensure /srv/jekyll is empty or else try again with `--force` to proceed and overwrite any files.

The above error seems caused by the /opt/jekyll/bw directory is not empty, so move the create_site.sh to /opt/jekyll and make sure the /opt/jekyll/bw directory is empty, then change the script to this:

export JEKYLL_VERSION=3.8
sudo docker run --rm \
  --volume="$PWD/bw:/srv/jekyll:Z" \
  -it jekyll/jekyll:$JEKYLL_VERSION \
  jekyll new .

then got this error:

bw@bw:/opt/jekyll$ ./create_site.sh
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux-musl]
jekyll 3.8.6 | Error:  Permission denied @ rb_sysopen - /srv/jekyll/./about.md

From this:https://stackoverflow.com/questions/57503011/unable-to-build-cloned-jekyll-site-jekyll-3-8-5-error-permission-denied-d, it might caused by the permission problem, the jekyll trying to use uid=1000/gid=1000 , but the user does not exist on my server, so change it :

create user jekylll and add it to sudoers

adduser jekyll

usermod -aG sudo jekyll

again:

export JEKYLL_VERSION=3.8
sudo docker run --rm --volume="$PWD:/srv/jekyll:Z" -it jekyll/jekyll:$JEKYLL_VERSION jekyll new .



2. Summary

In this post, I demonstrated how to install jekyll website using docker, this post is to be continued. That’s it, thanks for your reading.