Skip to content

Instantly share code, notes, and snippets.

Container Design Patterns

1. The single-container design pattern

Employing the single-container pattern means just putting your application into a container. It's how you usually start your container journey. But it's important to keep in mind that this pattern is all about simplicity, meaning that the container must have only one responsibility. That means it's an anti-pattern to have a web server and a log processor in the same container.

Containers are commonly used for web apps, where you expose an HTTP endpoint. But they can be used for many different things.

In Docker, you have the ability to change the behavior of a container at runtime, thanks to the CMD and ENTRYPOINT instructions. So I'm not limited to using containers for HTTP services. I can also use them for any bash script that accepts some parameters at runtime.

By letting containers change behavior at runtime, you can create a base container that can be reused in different contexts. So you'd use the single-container pattern to expose

@shivai
shivai / bash_strict_mode.md
Created November 3, 2022 20:35 — forked from mohanpedala/bash_strict_mode.md
set -e, -u, -o, -x pipefail explanation

Restore from backup

Install the version that you want:

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | bash
apt-cache madison gitlab-ce
apt install gitlab-ce=12.10.2-ce.0

in this sample we are going to config Gitlab with external Postgresql:

apt install postgresql=9.6+181+deb9u3

Entering Copy Mode and Scrolling

By default, enter copy mode with CTRL+a then ESCAPE. You can use vi like commands to navigate through the scollback buffer. The arrows and PAGE UP/DOWN should work as well. A few useful commands some may be unfamiliar with:

    M - jumps to the middle visible line
    NN% - jumps to the specified percentage in the buffer (0 - start, 100 - end
    g - jumps to the beginning of the buffer
    G - jumps to the end of the buffer

How to install repmgr 4.2 and PSQL11

RELEASE=$(lsb_release -cs)
echo "deb http://apt.postgresql.org/pub/repos/apt/ ${RELEASE}"-pgdg main | sudo tee  /etc/apt/sources.list.d/pgdg.list
apt-get install dirmngr --install-recommends
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7FCC7D46ACCC4CF8
apt update 
apt -y install postgresql-11
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
proxy.py
~~~~~~~~
HTTP Proxy Server in Python.
:copyright: (c) 2013 by Abhinav Singh.
:license: BSD, see LICENSE for more details.

Python Proxy

run it on a server that have internet access:

python proxy.py --hostname 0.0.0.0

Then connect to another server that don't have internet access and run it:

export http_proxy=http://serverip:8899

Ho to mount a disk to a directory:

fdisk -l 

Disk /dev/sdc: 200 GiB, 214748364800 bytes, 419430400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

RSYSLOG

rsyslog is a tools for writing logs in log files, rsyslog by default listens on 514 port. The config file is in:

nano /etc/rsyslog.d/my_log.conf

You can write many rules in it like this:

$template mydirectory_1,"/var/log/prod1/%FROMHOST-IP%/%syslogfacility-text%.log"
$template mydirectory_2,"/var/log/prod2/%FROMHOST-IP%/%syslogfacility-text%.log"

Add a new disk and mount it

After adding a disk to linux you should do these steps to use it:

fdisk -l

You can see the your new disk and take its name then:

fdisk /dev/sdb

then press n and after that press enter for 3 steps later and finally press w to write the changes.