カテゴリー: tech

  • What to do when /Var/Lib/Docker/Overlay2 gets bloated in Docker

    Introduction

    I ran out of storage on my docker build server. I need to delete unnecessary files, but there is a command to safely allocate space.

    What to do first

    grasp of the situation

    Identify what is putting pressure on the disk in docker.

    Use docker system df command, you can identify the disk usage related to docker.

    # docker system df
    TYPE                    TOTAL      ACTIVE     SIZE       RECLAIMABLE
    Images               9              1              2.014GB   1.962GB (97%)
    Containers           2              0              0B              0B
    Local Volumes        4              2              824.6MB   781.2MB (94%)
    Build Cache          0              0              0B              0B
    

    cope

    It will remove stopped containers, unused volumes, unused networks, and unused images.

    docker system prune

    However, the option to delete unused volumes and images is required.

    # docker system prune --help
    
    Usage:	docker system prune [OPTIONS]
    
    Remove unused data
    
    Options:
      -a, --all             Remove all unused images not just dangling ones
          --filter filter   Provide filter values (e.g. 'label=<key>=<value>')
      -f, --force           Do not prompt for confirmation
          --volumes         Prune volumes
    

    Delete Volumes

    I was able to reduce the size of the file by 355.4MB.

    553d15cd6b78ad0f21788a22e9ce16a7295c4bab97609973
    deleted: sha256:7ae9338aed73a0f33568db53740431038d3a1f779c4dae40d27433984e1cd97c
    deleted: sha256:b1be54c8cadff1e50b87b93559320a1ae57b8d0dd326507148f7ca81d707beed
    deleted: sha256:86d78f10b9718618eaae056f5dfa1edae518949aee4578e4147268e9db2e75f0
    
    Total reclaimed space: 355.4MB

    However, this does not remove the storage.

    use –volumes optiion. you can also delete storage.

    docker system prune --volumes
    WARNING! This will remove:
            - all stopped containers
            - all networks not used by at least one container
            - all volumes not used by at least one container
            - all dangling images
            - all build cache
    Are you sure you want to continue? [y/N] y

    Deleting Images

    If you choose –all option. you can also delete images.

    # docker system prune --all
    WARNING! This will remove:
            - all stopped containers
            - all networks not used by at least one container
            - all images without at least one container associated to them
            - all build cache
    Are you sure you want to continue? [y/N]

    After work

    When you finish deleting unnecessary files, it will be zero.

    # docker system df
    TYPE    TOTAL   ACTIVE  SIZE    RECLAIMABLE
    Images  0    0    0B   0B
    Containers    0    0    0B   0B
    Local Volumes 0    0    0B   0B
    Build Cache   0    0    0B   0B
  • vue.js の v-for を理解する

    vue.js の loop

    HTML

    <script src="https://unpkg.com/vue@3.1.5"></script>
    <div id="app">
      <p v-for="color in colors">{{ color }}</p>
    </div>
    

    JS

    const app = Vue.createApp({
      data: () => ({
        colors: ['black', 'white', 'orange']
      })
    })
    app.mount('#app')
    

    結果は以下の通り、loop して値を取得できる

  • vue.js の v-if を理解する

    表示非表示を切り替える

    HTML

    <script src="https://unpkg.com/vue@3.1.5"></script>
    <div id="app">
      <p v-if="toggle">hello</p>
    </div>
    

    JS

    const app = Vue.createApp({
      data: () => ({
        toggle: true
      })
    })
    app.mount('#app')
    
    v-if に紐づくパラメータが true の時のみ項目を出力する
    v-if に紐づくパラメータが true の時のみ項目を出力する
  • vue.js の v-bind を理解する

    HTML

    <script src="https://unpkg.com/vue@3.1.5"></script>
    <div id="app">
       <input type="text" v-bind:value="message">
    </div>
    

    JS

    const app = Vue.createApp({
      data: () => ({
        message: 'hello'
      })
    })
    app.mount('#app')
    
    出力結果
  • vue.js でデータバインディングをする

    vue.js のデータバインディングの仕組みを紹介。

    HTML

    <script src="https://unpkg.com/vue@3.1.5"></script>
    
    <div id="app">
      <p>
        <input type="text" v-model="message">
      </p>
      <p>
        {{ message }}
      </p>
    </div>
    

    js

    console.log(Vue.version)
    
    const app = Vue.createApp({
      data: () => ({
        message: "hello"
      })
      
    })
    app.mount('#app')
    
    初期値として js に書かれている hello が表示されるが、

    テキストボックスを変更すると、js の message が変更され、html に反映される

  • vue.js で指定の version を読み込む

    最新 version ではなく、指定の version を読み込む際の設定

    https://v3.ja.vuejs.org/guide/installation.html#vue-devtools

    では、

    <script src="https://unpkg.com/vue@next"></script>
    

    を使うように記載されているが、これだと常に最新になる。

    @next の部分を version に変更することで指定した version を読み込ませる事ができる

    <script src="https://unpkg.com/vue@3.1.5"></script>
    

    codepen で確認すると、3.1.5 が読み込まれたことを確認。

  • python で csv を結合する

    pandas を使う事で容易に結合できる。

    例えば以下のような csv ファイルがあったとする

    a.csv

    NO,CODE
    1,987
    2,111
    3,222
    

    b.csv

    ID1,ID2,CODE
    1,111111111111111111,111111111111111111
    2,222222222222222222,222222222222222222
    

    pandas を使うことで容易に結合する事ができる

    import pandas as pd
    
    # まず2つのCSVを読み込む
    a = pd.read_csv('./a.csv', encoding='utf-8')
    b = pd.read_csv('./b.csv', encoding='utf-8')
    
    # b の ID1 を NO に置換する
    b_ = b.rename(columns={'ID1': 'NO'})
    
    # a とb 2つのCSVを結合する。結合する際のキーは NO とする
    df_merged = pd.merge(a, b_, on='NO')
    
    # 確認
    print(df_merged)
    
    # CSV ファイルとして出力する
    df_merged.to_csv("merged.csv", index=False)
    

    結果

     % python3 main.py
       NO  CODE_x                 ID2              CODE_y
    0   1     987  111111111111111111  111111111111111111
    1   2     111  222222222222222222  222222222222222222
    

    今回、結合した csv ファイルそれぞれに CODE というカラムがそれぞれに存在している。

    pd.merge の第一引数になったファイルは _x という suffix がつき、

    第二引数になったファイルには _y という suffix が付く。

  • pip で install するパッケージの version を確認する

    python で開発をする場合、requirements.txt に install したいパッケージを書く事が多いが、その際 install するパッケージの version を知りたい場合がある。

    (さらに…)
  • ERROR 2026 (HY000): SSL connection error: error:14077102:SSL routines:SSL23_GET_SERVER_HELLO:unsupported protocol

    mysql コマンドで接続しようとした際このエラーに陥った。

    原因はおそらく TLS の問題。

    mysql command の場合 --ssl-mode=DISABLED オプションをつけることで回避可能

    mysql -h10.10.0.1 -uuser -p --ssl-mode=DISABLED
    

  • boto3 でファイルをアップロードする

    python 経由で s3 にファイルをアップロードしたくなる場合がある。

    本記事はその際のメモ。

    import boto3
    
    # 書き込み先バケット
    BUCKET = 'output-bucket'
    INPUT= 'hoge.csv'
    OUTPUT = 'hoge.csv'
    # OUTPUT = 'DIR/DIR/hoge.csv'
    
    
    s3 = boto3.resource('s3')
    s3.Bucket(BUCKET).upload_file(Filename=INPUT, Key=OUTPUT)
    
    

    ポイントとして、書き込み先の s3 のディレクトリに対し書き込むとき、存在しないディレクトリを対象にすると、存在しないディレクトリは一緒に作られる。これは、そもそも s3 にディレクトリという考えがないためである。

    それについては以下の記事を参照