The Path Of Docker
The Path of Docker#
I have been wondering how I should start moving my applications from traditional vm’s to kubernetes - to attempt to save costs and compare. I need to actually get data and experience to know whether moving certain workloads to containers is the right thing to do and whether deep diving into kubernetes is the way to go.
I wanted to do this with a pragmatic approach. Getting hello world up and running is okay but putting it into a real world scenario is important.
To not get into the demo mode trap
I have drafted a path towards containerisation:
- Hello world - local machine
- Hello world - kubernetes cluster
- Static site - local machine
- Static site - kubenernetes cluster
- Deploying static site to kubernetes on deploy
- Django site with containerised db - local machine
- Django site with a managed db - kubernetes cluster
The reason we do the static site is because - html files static assets will be generated and that can be backed into an image and deployed. There are no other dependencies other than a webserver to serve it.
Setting up Jekyll#
Check you current ruby version (or install it using rvm or brew)
ruby -v ruby 2.1.10p492 (2016-04-01 revision 54464) [x86_64-darwin17.0]
Install recent ruby
rvm install ruby-2.6.3 # this takes about 4/5 minutes
Remember we don’t need ruby on our docker image - as ruby will only be used locally (or on ci) to generate the static files and then build that into an image.
rvm use 2.6.3 gem install bundler jekyll # takes about 3 minutes jekyll new <my_blog_name> cd <my_blog_name> bundle exec jekyll serve
_config.yml with your details
Build the site
FROM nginx:stable ADD ./_site /usr/share/nginx/html
Build the image
docker build -t surfer190/fixes:0.1 .
Login to docker hub
docker login docker push surfer190/fixes:0.1
Dockerfile assumes that
We want the build to happen automatically - during the docker build - ie. include it in the push process.
Let us use build phase hooks
#!/bin/bash echo "=> Build the site using jekyll" mkdir -p _site docker run --volume=`pwd`:/srv/jekyll jekyll/jekyll jekyll build
What this does:
- Uses the
jekyll/jekyllimage for a jekyll environment - the jekyll/jekyll image
- We map our current directory to
jekyll/jekyllexpects the site
- We build the site with