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 261e231.
linux
#containers #docker #linux
published on 17.04.2022
edited on 02.05.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 …

published on 19.02.2022

Önceki yazıda LaTeX kullanmanın avantajlarından ve zorluklarından bahsetmiştim, MS Word gibi WYSIWYG programlar ile karşılaştırıp tavsiyelerimi yazmıştım. Bu yazıda Pandoc yazılımı üzerine konuşacağız. Pandoc’un da yardımıyla LaTeX’in avantajlarını alıp zorluklarını biraz geri de …

published on 12.02.2022

LaTeX bir çeşit döküman hazırlama sistemidir, ancak çoğumuzun alıştığı arayüzlerin aksine bu döküman içerisinde kod yazar gibi bazı komutlar kullanırız. Daha sonra derleyici (compiler) bu dökümanı bizim tanımladığınız kurallara göre PDF’e dönüştürür. […] 1978 yılında, Donald Knuth TeX …

published on 02.01.2022

This post is for fellow students who is studying Operations Research with CPLEX. If you don’t know already, IBM offers free academic license for IBM ILOG CPLEX Optimization Studio. […] First, you have to register IBM Academic Initiative with your academic instituion issued email. (e.g. …