published on 09.09.2020

In this post, I’ll explain a very simple yet useful concept. I’m using Docker to manage a couple of containers in a few servers without using any management software since the environment isn’t big and complicated. Creating the containers for once is easy, it requires only a single line command. Yet, I’ve to save that command for later use; because it also contains my configurations.

In this example, we use the port, name, volume, and path parameters. This command will be needed in the future when we need to regenerate (eg. update) the container.

docker run -d -p 3000:3000 --restart=unless-stopped -v grafana:/var/lib/grafana -v /monitoring/grafana/grafana.ini:/etc/grafana/grafana.ini:ro -v /monitoring/grafana/ldap.toml:/etc/grafana/ldap.toml:ro --name grafana grafana/grafana:latest

Saving these commands in your notepad is a bad way to handle this process. Like every normal person, we want to keep these configurations in a well-structured file. We can utilize Systemd Unit Files to solve this problem. I’ll continue with the Grafana example.

  1. Create a systemd file
vim /etc/systemd/system/grafana.service
  1. Add the required content
[Unit]
Description=Grafana
Requires=docker.service
After=docker.service

[Service]
ExecStart=/usr/bin/docker run --rm --name=%n -p 3000:3000 --network=grafana -v grafana:/var/lib/grafana -v /monitoring/grafana/grafana.ini:/etc/grafana/grafana.ini:ro -v /monitoring/grafana/ldap.toml:/etc/grafana/ldap.toml:ro grafana/grafana:latestExecStop=/usr/bin/docker rm -f %n
Restart=always

[Install]
WantedBy=multi-user.target
  1. Daemon-Reload

Whenever we change unit files, we need to run daemon-reload so that systemd reloads the new configurations.

systemctl daemon-reload
  1. Start the service

It’s done. Now we can use systemctl commands to manage the service. Start the container (service).

systemctl start grafana.service

Make it start automatically on boot. systemctl enable grafana.service

We don’t need to remove the container and create a new one with a long command. We can simply use systemctl restart grafana.service.

Published on 09.09.2020 by Mert Bakır with commit 4866d43.
dev-ops
#dev-ops #docker #linux
published on 10.07.2022

Previously, I’ve published a blog post about deploying static content on heroku with basic authentication. The main purpose was to get basic auth for a freely hosted static website. In that post, we hosted the source code on GitLab and configured a CI/CD pipeline to render the static content …

published on 28.05.2022

Each git commit has a field called Author which consists ‘user.name’ and ‘user.email’. We usually set these variables once, after installing git, with git config --global so that each repo gets the variables from the global definition. We can also set them locally for a …

published on 25.05.2022

In this post, I’ll first walk through hosting static content with basic authentication. Then, we’ll look into deploying to Heroku using GitLab Pipelines, more specifically deploying a certain sub-directory within the project instead of pushing the whole project. Also, I’ll share …

published on 17.04.2022
edited on 15.07.2022

Önceki bölümde, markdown formatını LaTeX formatına dönüştürmek için kullanılan Pandoc yazılımından bahsetmiştik. Şimdi konuyu bir adım daha ileri taşıyıp ve bookdown’a geçiyoruz. Bookdown; Rmarkdown kullanarak teknik dökümanlar, kitaplar yazabilmemizi sağlayan, Yihui Xie tarafından yazılmış …

published on 10.04.2022

I’ve been using WSL-2 on Windows for over a year. It’s very useful because some Python packages are just a headache to install on Windows. Also, docker. It’s just better on Linux. Yet, WSL-2 can also be problematic. I remember trying a dual-boot setup when things just went way too …

published on 03.03.2022

In this post, I’ll share how to install geopandas and some other gis related packages on Windows. If you are on Mac or Linux you can probably just pip install those without any issue. I usually had to do a google search every time I wanted to install these packages on Windows environment. Of …