LoginSignup
1
1

More than 5 years have passed since last update.

dockerコンテナからcapybaraのスクリーンショットをローカル環境にコピーする

Posted at

諸事情あってfeature specはdockerコンテナ上で実行する必要があり、docker cpにいちいちコンテナIDを渡すのが面倒だったのでショートカットをつくた。テストプロセス内でファイル名取得しなきゃいけないのがまだ面倒だけど、pryからシェルを実行するときに引数を渡す方法がわからなかったのでとりあえずこれで凌ぐ。

#!/bin/bash

function docker-cp() {
    usage_exit() {
        echo "Usage:\tdocker-cp /path/to/your/file" 1>&2
        return 0
    }

    if [ $# -eq 0 ]
      then
        usage_exit
        return 0
    fi

    FILE_PATH=$1
    CONTAINER_ID=`docker ps | grep your_app | head -1 | awk '{print $1;}'`

    docker cp $CONTAINER_ID:$FILE_PATH ~/Desktop/capybara/
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1