Github provides a great service for technique bloggers: Github
Pages. Just by creating a repo in GitHub, we can
host a domain like
http://username.github.io. And with
Jekyll we can write blogs with Markdown and preview
blog pages locally and conveniently.
The problem for me is that my work environment is Windows, and it’s not easy to install Jekyll in Windows(especially in China). So an idea comes out with me is to use Docker.
So let’s do it!
- Docker installed (if not go to https://www.docker.com/)
- GitHub repo for blog created
Pull official Jekyll Docker image in your docker host machine.
docker pull jekyll/jekyll
Move to your blog repo directory, for me is
/c/Users/ewenfga/Code/github.io/Wenfeng-GAO.github.io because docker
automatically mount with my C disk.
docker run --rm -v $(pwd):/srv/jekyll -it jekyll/jekyll bash
This line of code will run the jekyll image interatively and mount
/srv/jekylldirectory with current directory. That’s why we move to this GitHub
jekyll new . --force
This jekyll command will create all what we need for blogs, including a
directory where we place our blogs.
Quit the docker container(
Ctrl d). By now we have setup our blog’s structure
by jekyll, all is done and we can push to GibHub and see our blogs on the
internet if we wish.
But Jekyll also provides us a wonderful local server, by which we can preview what we write locally.
docker run --rm --label=jekyll --volume=$(pwd):/srv/jekyll -it -p 4000:4000
This line of code will run a docker container as a server and export
I recommand you to make an alias for this piece of code as we’ll use it often.
Ok, now lets open our browser and type
the navigation bar, you will see something like: