published on 09.09.2020
edited on 23.01.2021

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.

1
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
1
vim /etc/systemd/system/grafana.service
  1. Add the required content
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
[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.

1
systemctl daemon-reload
  1. Start the service

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

1
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. Last update on 23.01.2021 with commit c2f1bc0.
linux
#containers #docker #linux
published on 01.05.2020
edited on 19.01.2021

Containerlar ephemeral stroge kullanırlar. Yani container öldüğünde içindeki datada onunla birlikte yok olur gider. Bu yüzden, persistent volume‘ler kullanılır. Kalıcı olmasını istediğimiz datayı, containerın dışında tutarız. Ben, belli aralıklar ile bu volume’ü yedeklemek istiyorum. …

published on 18.11.2019

Başlamadan önce belirtmem gerekir ki bu yazı genel olarak docker nedir, container nedir ve temel operasyonları ve volume yapılarını bildiğinizi varsayıyor. […] Bir sunucuda çalışan bir konteynerimiz olsun. Bu konteynere bağlı bir ya da birden fazla volume olsun. Konteynerı farklı bir sunucuya …

published on 20.11.2019

Fonksiyonlar, bölümünde argümanlardan kısaca bahsetmiştik. Peki, ya argümanı direkt scriptin dışından userdan ya da farklı bir programdan almamız gerekiyorsa ne yapacağız? Yine fonksiyona argüman gönderir gibi scripte argüman gönderebiliriz. […] 1 ./foobar.sh "foo" "bar" …

published on 19.11.2019

Her dilde kullandığımız, tekrara düşmemek adına kullanılan en temel yapı. Fonksiyonlar, bash scriptinde aşağıdaki örnekteki gibi tanımlanabilir. function anahtar sözcüğü ardından fonksiyon adı verilir ve küme parantezi içerisinde fonksiyon tanımlanır. […] 1 2 3 4 #!/bin/bash function …

published on 24.01.2021
edited on 11.06.2021

Some time ago, I wanted to display image galleries on my Hugo website and searched for Hugo themes for photography and gallery. I can’t say I find much. Then, I met with a javascript library called nanogallery2 which is using another javascript library as an image viewer lightbox2. In this …

published on 23.01.2021
edited on 11.06.2021

Image processing may seem complicated at first but it’s actually easy and definitely worth implementing since it’ll help you decrease page load times. As you probably know, we don’t want to load raw images with huge sizes for small thumbnails or blog-posts. We want to load a small …

published on 31.12.2020
edited on 26.06.2021

I’ve, recently, published a blog post called Perfect Workflow for Publishing Python Notebooks. I talked about some of the benefits of using Rmarkdown and reticulate. In this post, I’ll try HTML widgets and explain how we can embed those in our blog post using nothing but R. […] 1 …

published on 05.12.2020

Resume A4 is a side project of mine. It’s one page Hugo Theme that allows you to write your resume in YAML format and keep track of it using git. Also, you can publish it online as a static site using GitLab, GitHub Pages, Netlify, or some other service you are familiar with. A few months …

published on 30.11.2020

I’ve been searching for a good workflow for publishing Jupyter or RMarkdown Notebooks as static blog posts. I think I’ve found the optimal solution for my use case. In this post, I’ll explain my workflow and why chose this way with examples. […] In reality my main purpose to …

published on 29.11.2020
edited on 05.12.2020

Plotly is a visualization library that allows us to write code in Python, R, or Julia and generates interactive graphs using Javascript. So, we don’t have to deal with Javascript. You can checkout Plotly gallery, there are interesting works. Anyway, last week, I’ve started learning …