Skip to main content

How to install Markdown Lint in a Docker container

· 3 min read

Hello, this post will explain how to install and use Markdown Lint in a Docker container. Please check my previous post to better understand Docker.

Before you start

Please, make sure that you checked my previous Docker post because I will be using some references to that post, and it would be easier to follow this post :)

In this case, will be using a ruby container to install our mdl tool. You show how to set up a ruby container in that previous Docker post that I mention.

Markdown Lint

This is a tool for markdown (md) files that includes a library of rules to encourage standards and consistency for Markdown files and that confirms if the files are following theses rules.

Ruby container

So, to start, lets run the ruby container! Copy paste the following line into your terminal:

docker run -tid -v /home/vagrant:/mdfiles --name ruby --entrypoint=/bin/bash ruby:latest

Okay, so you look at this command line and ask yourself what in the world is all of this!? Well, let me explain :)

The -tid is 3 different things:

  • -t or --tty: Allocate a pseudo-TTY
  • -i or --interactive: Keep STDIN open even if not attached
  • -d or --detach: Detached mode: run command in the background

Afterwards, we do a -v for volume, that in our case, is used to mirror the folder where we have our .md file. This will allow us to have "the same folder" in our container. Remember that the / is root and then we create a new folder in the container named "mdfiles"

Then we use the --name and as the name suggest it's to attibute a name to your container.

We run --entrypoint /bin/bash to let a bash opened. This allows the container to stay opened (up) instead of closing just after the run. When you do an exec, it doesn't goes on bash (exec is sh and not bash). That's why we have to make the container run bash, to be able to use all the bash command

The difference between docker run and docker exec is that docker exec executes a command on a running container. On the other hand, docker run creates a temporary container, executes the command in it and stops the container when it is $So we use --entrypoint to run a container, and let it open until we decide to stop it

You can also give a command to your container directly by doing so: Note: If you have a windows container you use powershell instead of bash

docker exec ruby bash -c "ip add"

We execute the bash terminal with the command (-c) "ip add" This will show you the IP adress of your ruby container

And now we can install the mdl tool:

docker exec ruby bash -c "gem install mdl"

Great, everything looks nice and clean! Now, pick a .md file of your choosing, and run mdl:

docker exec ruby bash -c "mdl /mdfiles/myfile.md"

This will run the mdl tool through your md file and will inform you of how many errors you have, the lines they are and what was the rule that wasn't respected.