How I Built This

I’ve recently seen a decent amount of posts generally in the theme of “Why you shouldn’t use Medium to blog”. I also like learning new frameworks and tools, so I took a look around to find some good alternatives to Medium. The option I decided to go with was a Jekyll site hosted on a DigitalOcean droplet. I more or less followed Josh Habdas’ writeup here. There were a couple small issues with the newer version of Jekyll. I also wasted some time thinking that docker wasn’t working.

In my DigitalOcean droplet set up, Docker commands issued without sudo result in messages leading the user to believe Docker isn’t running:

[email protected]:~$ docker ps
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

It took me a little bit to realize I just needed sudo. D’oh.

[email protected]:~$ sudo docker ps
[sudo] password for deployer:
CONTAINER ID  IMAGE   COMMAND          CREATED      STATUS
66944bb2c7d6  webapp  "/sbin/my_init"  2 weeks ago  Up 2 weeks

This was a great place to use the new trick that I learned from Learn Enough Command Line to Be Dangerous:

[email protected]:~$ docker ps
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
[email protected]:~$ sudo !!
sudo docker ps
CONTAINER ID  IMAGE   COMMAND          CREATED      STATUS
66944bb2c7d6  webapp  "/sbin/my_init"  2 weeks ago  Up 2 weeks

One thing I wish that Josh had written more about is the day-to-day usage - the process to add posts, etc. I find myself doing a lot of steps to publish every post:

  1. Write post (obvs)
  2. zip my local repository
    git archive -o app.tar.gz –prefix=app/ master
    
  3. SCP the file to my droplet
    scp app.tar.gz [email protected]:
    
  4. SSH into the droplet and expand the repository
    ssh [email protected]
    tar zxvf app.tar.gz
    
  5. Build a docker image with the new files
    sudo docker build -t webapp app/
    
  6. Stop the currently running docker image and start it using the new docker image (results in momentary downtime - not optimal, but I think I’m the only one reading this site for now)
    sudo docker stop $(docker ps -lq)
    sudo docker run -d -p 80:80 webapp
    
  7. Cleanup unused docker images and containers
    sudo docker ps -q -a | xargs sudo docker rm
    sudo docker images –no-trunc -aqf “dangling=true” | xargs sudo docker rmi
    

I’m assuming that I might be doing something wrong, but I haven’t found a better solution to this yet.

I’ll look into some automated solutions for this and/or work on an automated script that will do all this for me. Ideally, it would do both a local and a remote option. This will make previewing posts and publishing them much easier.

If you’re looking to set up a DigitalOcean account, you can use my link and you’ll get a $10 credit.