Skip to content

Instantly share code, notes, and snippets.

View quangkeu95's full-sized avatar
🦀
rusty

Hashira quangkeu95

🦀
rusty
View GitHub Profile
@quangkeu95
quangkeu95 / shell set -e set -x.md
Last active December 6, 2017 03:42
Linux shell script: set -e and set -x

Set -e and set -x in shell script

set -e:

Enable checking of all commands. The execution of shell script will be aborted if one command returns non-zero status code. Examples:

# true; echo $?
0 

# false; echo $?
@quangkeu95
quangkeu95 / shell script trap.md
Last active November 7, 2017 02:23
Shell script knowledge about trap command

Khi shell script nhận được một Signal, script có thể thực hiện một trong ba actions:

  1. Ignore and do nothing.
  2. Catch signal by using trap and do something.
  3. Take the default action.

Các actions trên đúng ngoại trừ trường hợp 3 signals:

  • SIGKILL (9)
  • SIGSTOP (17)
  • SIGCONT (19)
@quangkeu95
quangkeu95 / docker-cleanup-resources.md
Created November 8, 2017 01:27 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

Find file path base on filename

locate -br '^settings.xml$'

From man locate:

   locate  reads  one or more databases prepared by updatedb(8) and writes
   file names matching at least one of the PATTERNs  to  standard  output,
 one per line.

Dockerfile VOLUME

Định nghĩa VOLUME trong Dockerfile sẽ:

  • Expose folder/directory được tạo bởi container ra đường dẫn trên host: /var/lib/docker/volumes/[container_id]/_data/ Note: _data được gọi là "mount point"

Run container với lệnh: docker run --rm image

Khi container được run, ta có thể check volume được tạo bởi container bằng câu lệnh: docker volume ls Khi container exited, volume sẽ mất do ta định nghĩa cờ --rm ở câu lệnh docker run, do đó container và volume của nó sẽ được remove hoàn toàn.

Install Docker Compose on Linux distribution

Get the latest version of Docker Compose on Docker Compose release page

To install

curl -L https://github.com/docker/compose/releases/download/1.17.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version

Docker Images

Each Docker Image was built by stacking different Image Layers, each Image Layer represents an instructions in Image's dockerfile.

When we create a new container, a writable layer is placed on top on underlying layers. We can call this layers is Container Layer. All changes made in container (such as writing to files, modifing files or delete files) are written to this Container Layer.

Multiple writable layers sharing the same read-only layers

@quangkeu95
quangkeu95 / bash-cheatsheet.sh
Created November 21, 2017 02:27 — forked from LeCoupa/bash-cheatsheet.sh
Bash CheatSheet for UNIX Systems --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
#!/bin/bash
#####################################################
# Name: Bash CheatSheet for Mac OSX
#
# A little overlook of the Bash basics
#
# Usage:
#
# Author: J. Le Coupanec
# Date: 2014/11/04

INTRODUCTION

Workspaces

Sẽ có 2 kiểu program trong Go:

  • Executables: là chương trình có thể chạy trực tiếp từ terminal.
  • Libraries: đóng gói thành package để các chương trình khác có thể gọi tới. Basically, Go workspace contains three directories:
  • src: Contains Go source files.
  • pkg: Contains package objects
@quangkeu95
quangkeu95 / gist:4d479610a4373b7fba8f416edc9a12bf
Created December 1, 2017 10:03 — forked from mbn18/gist:0d6ff5cb217c36419661
How to install nsenter on Ubuntu 14.04
# Ubuntu 14.04 don't have nsenter - the straight forward way required me to install build tools and etc.
# I preferred to keep the system clean and install nsenter in a container and then copy the command to the host
# Note - its also possible to run nsenter from a container (didn't tried) https://github.com/jpetazzo/nsenter
# start a container
docker run --name nsenter -it ubuntu:14.04 bash
## in the docker
apt-get update
apt-get install git build-essential libncurses5-dev libslang2-dev gettext zlib1g-dev libselinux1-dev debhelper lsb-release pkg-config po-debconf autoconf automake autopoint libtool