0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

新米エンジニアの黙示録

Last updated at Posted at 2023-05-02

概要

TIPSのまとめ記事。

拙者概要

  • 業務: Web Appの設計・構築
  • 資格: 応用情報技術者, AWS SAA, AWS DVA, DX Questケーススタディ教育プログラムGold修了証
Docker
基本構文
powershell
docker run --rm -it --name testcontainer python:3.9 /bin/bash
  • --rm: コンテナを自動で消去するオプション
  • -it: コンテナとの入出力を行うオプション
  • --name: コンテナ名を指定するオプション
  • /bin/bash: bashに入るオプション
bashで指定のコマンドを実行
powershell
docker run --rm -v ${pwd}:/tmp python:3.9 /bin/bash -c "pip install virtualenv && cd /tmp && virtualenv virtualenv && source virtualenv/bin/activate && pip install -r requirements.txt"
  • -v: ファイルをコンテナにマウントするオプション
  • -c: コマンドを指定するオプション

カレントディレクトリに、パッケージ情報をまとめたrequirements.txtを置き、
上記コマンドを実行することで、仮想環境の作成 & pip installしてくれる。

bashファイルをマウントし実行
exec.bash
#!/bin/bash
pip install virtualenv
virtualenv virtualenv
source virtualenv/bin/activate
pip install -r requirements.txt
powershell
docker run -v ${pwd}:/tmp python:3.9 /bin/bash -c "cd tmp && ./exec.bash"

カレントディレクトリにrequirements.txt, x.bashを置き上記コマンドを実行すると、
「bashで指定のコマンドを実行」と同じ結果が得られます。

既存コンテナにログイン
powershell
docker exec -it {container name} /bin/bash
Python
package import 整理
powershell
# isort install
pip install isort

# Python srcディレクトリにてisort実行
isort .
Python ImportのFormat (不要なImportの削除)
powershell
pip install autoflake
autoflake --remove-all-unused-imports --in-place --recursive .
Python Cache(pyc file)を再帰的に削除
powershell
Get-ChildItem *.pyc -Recurse | Remove-Item
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?