Dockerで「image is being used by stopped container」が出たときの対処法
Dockerでイメージ削除時に以下のエラーが出た時の対処メモ
$ docker rmi <image_id>
Error response from daemon: conflict: unable to delete <image_id> (must be forced) - image is being used by stopped container <container_id>
原因
停止中のコンテナが、そのイメージを参照しているためです。
Dockerでは「停止中」でもコンテナが存在している限り、イメージは削除できません。
ただし今回のケース(ハマりポイント)
$ docker ps -a
を実行しても、コンテナが表示されない場合があります。
👉 この場合は以下の可能性があります:
- Docker内部の状態不整合(幽霊コンテナ)
- メタデータだけ残っている状態
解決方法(最短手順)
以下のコマンドで解決できます。
$ docker container prune
👉 表示されない停止コンテナも含めて削除されます
イメージ削除
その後、以下を実行します。
$ docker image prune -a
👉 未使用イメージがすべて削除されます
まとめ
問題の本質:
- 見えない停止コンテナが残っている
対処手順:
$ docker container prune
$ docker image prune -a
補足
それでも解決しない場合は以下も有効です:
$ docker system prune -a
👉 コンテナ・イメージ・キャッシュをまとめて削除します(要注意)
一言メモ
Dockerで「削除できない」「使われている」と出たら、
👉 まず prune を疑うと解決が早いです 👍
Slack:特定のリアクションでメンション通知されるようにするBotを作ってみた
更新
- 2022.10.21 : Slack Even API で同じイベントが複数回処理されてしまう問題に対応しました
背景
Slackで承認boxのようなチャネルを作成し、承認者がチェックマークをリアクションすると、投稿者に自動でメンションがいくような仕組みを作りたい!
とチームメンバに言われたので作成しました。
通常仕様だと、リアクションされても通知いかないんですよね・・・。
Reacji Channelerとかもありますが、別チャネルに転送するだけだしあまりやりたいことができなかったので、作るしかなかったという感じ。どなたか、いいプラグイン等あれば教えてほしいです。
完成イメージ

Flutter環境構築 for M1 Mac
久々にFlutterを利用しようと思って、備忘のために残してあったメモがあったので公開します。自分用のメモなので色々間違っていたり、抜けていたりする可能性ありますが、ご容赦ください。
Flutter Setup for M1 Mac
Reference web sites
Install
Install for M1 Mac
$ sw_vers ProductName: macOS ProductVersion: 11.1 BuildVersion: 20C69
公式のインストール方法の手順通りにやってみる。
$ cd ~/Dev/lib
$ unzip ~/Downloads/flutter_macos_1.22.6-stable.zip
$ vim ~/.zshrc
+ export PATH="$PATH:<your path>/flutter/bin"
$ source ~/.zshrc
Run flutter doctor
flutter doctorを実行すると、開発環境の状態をチェックして表示してくれます。
Dart SDKはバンドルされているので、個別にインストール必要はないので便利。
ここで整っていないと言われた環境を整えていきます。
$ flutter doctor
Downloading Dart SDK from Flutter engine 2f0af3715217a0c2ada72c717d4ed9178d68f6ed...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 172M 100 172M 0 0 30.3M 0 0:00:05 0:00:05 --:--:-- 31.6M
Building flutter tool...
╔════════════════════════════════════════════════════════════════════════════╗
║ Welcome to Flutter! - https://flutter.dev ║
║ ║
║ The Flutter tool uses Google Analytics to anonymously report feature usage ║
║ statistics and basic crash reports. This data is used to help improve ║
║ Flutter tools over time. ║
║ ║
║ Flutter tool analytics are not sent on the very first run. To disable ║
║ reporting, type 'flutter config --no-analytics'. To display the current ║
║ setting, type 'flutter config'. If you opt out of analytics, an opt-out ║
║ event will be sent, and then no further information will be sent by the ║
║ Flutter tool. ║
║ ║
║ By downloading the Flutter SDK, you agree to the Google Terms of Service. ║
║ Note: The Google Privacy Policy describes how data is handled in this ║
║ service. ║
║ ║
║ Moreover, Flutter includes the Dart SDK, which may send usage metrics and ║
║ crash reports to Google. ║
║ ║
║ Read about data we send with crash reports: ║
║ https://flutter.dev/docs/reference/crash-reporting ║
║ ║
║ See Google's privacy policy: ║
║ https://policies.google.com/privacy ║
╚════════════════════════════════════════════════════════════════════════════╝
Downloading Material fonts... 0.5s
Downloading Gradle Wrapper... 0.2s
Downloading package sky_engine... 0.2s
Downloading flutter_patched_sdk tools... 0.7s
Downloading flutter_patched_sdk_product tools... 0.5s
Downloading darwin-x64 tools... 1.2s
Downloading libimobiledevice... 0.0s
Downloading usbmuxd... 0.0s
Downloading libplist... 0.0s
Downloading openssl... 0.1s
Downloading ios-deploy... 0.0s
Downloading darwin-x64/font-subset tools... 0.1s
Downloading android-arm-profile/darwin-x64 tools... 0.2s
Downloading android-arm-release/darwin-x64 tools... 0.3s
Downloading android-arm64-profile/darwin-x64 tools... 0.3s
Downloading android-arm64-release/darwin-x64 tools... 0.2s
Downloading android-x64-profile/darwin-x64 tools... 0.3s
Downloading android-x64-release/darwin-x64 tools... 0.3s
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.6, on macOS 11.1 20C69 darwin-arm, locale ja-JP)
[✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, set ANDROID_SDK_ROOT to that location.
You may also want to add it to your PATH environment variable.
[✗] Xcode - develop for iOS and macOS
✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
Download at: https://developer.apple.com/xcode/download/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage
on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To install:
sudo gem install cocoapods
[!] Android Studio (not installed)
[!] VS Code (version 1.52.1)
✗ Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[!] Connected device
! No devices available
! Doctor found issues in 5 categories.
Seting environment
flutter doctorで足りないと言われた環境を整えていきます。
[✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, set ANDROID_SDK_ROOT to that location.
You may also want to add it to your PATH environment variable.
公式のインストール方法については、Android Studio install for Macを参照
- Download Android Studio and SDK tools | Android Developersにアクセス
DOWNLOAD ANDROID STUDIOから.dmgファイルをダウンロード- ダウンロードした.dmgファイルを実行
- 以下の画面になったらDrug&Dropし、Andriod Studioを起動

- 初回なので以前の設定をインポートしないを選択


Intel CPUじゃないとHAXM11がインストールされないだと…。M1 Maxにまだ人権はない模様。 調べてみると"現時点ではAndroid EmulatorはM1では動作しない”とのことだが、まぁ、それ以外は問題ないようなのでよしとする。
Android SDK is up to date. Unable to install Intel® HAXM Your CPU does not support VT-x. Unfortunately, your computer does not support hardware accelerated virtualization. Here are some of your options: 1) Use a physical device for testing 2) Develop on a Windows/OSX computer with an Intel processor that supports VT-x and NX 3) Develop on a Linux computer that supports VT-x or SVM 4) Use an Android Virtual Device based on an ARM system image (This is 10x slower than hardware accelerated virtualization) Creating Android virtual device Android virtual device Pixel_3a_API_30_x86 was successfully created
[✗] Xcode - develop for iOS and macOS
✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
Download at: https://developer.apple.com/xcode/download/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage
on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To install:
sudo gem install cocoapods
- Apple StoreからXcodeのアプリをインストール
- 以下のコマンドを実行
$ sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer $ udo xcodebuild -runFirstLaunch
- CocoaPods
$ exec arch -x86_64 /bin/zsh $ sudo gem install ffi $ sudo gem install cocoapods
ffiをgemインストールしておくとcocoapods インストール時のffiのエラーが回避できるようです。
Run flutter doctor again
これで問題の箇所( [x] )は解消できました。必須ではないですが、[ ! ]箇所もできるだけ解消しておこうと思います。
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.6, on macOS 11.1 20C69 darwin-arm, locale ja-JP)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
✗ Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 12.4)
[!] Android Studio (version 4.1)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[!] VS Code (version 1.52.1)
✗ Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[!] Connected device
! No devices available
! Doctor found issues in 4 categories.
$ flutter doctor --android-licenses # 質問には全てy(yes)で回答して問題ないです。
これはM1 Mac以外でも出ている事象らしく下記Issueに対処方法が載っているので対応します。
Flutter Doctor: Android Studio 4.1 is not detected · Issue #67986 · flutter/flutter
$ ln -s ~/Library/Application\ Support/Google/AndroidStudio4.1/plugins ~/Library/Application\ Support/AndroidStudio4.1
私は普段からVScodeを利用しているのでFlutter extensnionはもちろんインストールします。
再度確認
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.6, on macOS 11.1 20C69 darwin-arm, locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 12.4)
[!] Android Studio (version 4.1)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.52.1)
[!] Connected device
! No devices available
! Doctor found issues in 2 categories.
Android Studioのエラーは消えてないけど、放置しておいても問題はなさそうなので一旦OKということにします。 以上でFlutterのインストール及び環境設定は完了です。
Set up the iOS simulator
$ open -a Simulator

Create and run sample app
$ flutter create my_app $ cd my_app $ flutter run
Run on the web
webアプリとして実行できるようにコンパイルできるようにするには、以下のコマンドでconfigを変更します。一度実行すれば、以降のアプリについてもWbサポートされるようになるようです。 ※現時点ではbeta版のようです。
$ flutter channel beta $ flutter upgrade $ flutter config --enable-web
有効化の確認
flutter configコマンドでebnable-webの項目がtrueとなっていれば有効化されています。
$ flutter config <--略--> Settings: enable-web: true
Format Code with dart-format
# Terminal $ flutter format <filename>
たまに調べるpythonコマンド 〜ファイル操作〜
たまに使い方を調べるpythonのファイル操作についていっそまとまておこうと思い載せておく
カレントディレクトリのパスを取得
import os
path = os.getcwd()
ファイルの存在を確認する
import os path = "./your/search/file/path" os.path.exists(path)
ファイルの拡張子判別
import os file = "test.txt" if file.endswith('.txt'): print("text file") else: print("not text file")
拡張子を除いたファイル名を取得
import os filename = "test.txt" name_only = os.path.splitext(os.path.basename(filename))[0] # name_only : test
Mac Book M1 でDocker環境を試してみる

目次
- 目次
- はじめに
- Docker Desktop for M1 のダウンロード
- Docker Desktopのインストール
- Docker versionの確認
- Dockerコンテナを動かしてみる
- VS code環境の設定
はじめに
Docker DesktopのApple silicon M1用のパブリックプレビューが開始されたということで、試してみることにしてみました。
「Docker Desktop」のパブリックプレビューが開始 ~1,000人以上の開発者が参加 - 窓の杜
Docker Desktop for M1 のダウンロード
Docker Desktop for M1 は以下からダウンロードすることができます。
Download and Try the Tech Preview of Docker Desktop for M1 - Docker Blog
Docker Desktopのインストール
上記リンクからダウンロードした.dmgファイルをダブルクリックして開きます。

Dockerでpython3+OpenCVの環境を整えてみる
Macbook air を購入したので、お試しがてらDockerでOpenCVの開発環境を整えてみようとしたらハマったので、その対処などをメモしておきます。
目次
- 目次
- やりたいこと
- 環境
- 環境構築開始
- Dockerfileをつくるとこんな感じ
やりたいこと
Dockerコンテナ上で、以下の環境を整える。
- Docker image : Ubuntu18.04:latest
- Python3
- OpenCV
環境
M1のMacbook向けのDocker desktop for M1がインストール済みであることを前提にしています。
$ system_profiler SPHardwareDataType
Hardware:
Hardware Overview:
Model Name: MacBook Air
Model Identifier: MacBookAir10,1
Chip: Apple M1
Total Number of Cores: 8 (4 performance and 4 efficiency)
Memory: 16 GB
System Firmware Version: 6723.50.2
$ docker --version
Docker version 20.10.1, build 831ebeae96
$ docker-compose --version
docker-compose version 1.27.4, build 40524192
続きを読む