BOP - The Future of Creative Engineers -


← ホームに戻る

🛠️ Dockerイメージのビルド

コマンド build

docker build -t <イメージ名>:<タグ名> <Dockerfileのあるディレクトリ>

# (例)
docker build -t todo_app_web:latest .

💬 Dockerコンテナ起動(対話モード)

コマンド run

docker run --name <コンテナ名> -it <イメージ名>:<タグ名> /bin/bash

# (例)
docker run --name web_container -it todo_app_web:latest /bin/bash

💻 Dockerコンテナの起動(バックグラウンド)

コマンド run

docker run --name <コンテナ名> -p <ローカルポート番号>:<Dockerポート番号> -it -d <イメージ名>:<タグ名> /bin/bash

# (例)
docker run --name web_container -p 80:9000 -it -d todo_app_web:latest /bin/bash

👀 Docker起動中プロセスの確認

コマンド ps

# (例)
docker ps

結果

CONTAINER ID   IMAGE          COMMAND                  CREATED       STATUS       PORTS                    NAMES
0575dab5a255   todo_app_web   "/wait-for-it.sh db:…"   2 hours ago   Up 2 hours   0.0.0.0:9000->5000/tcp   todo_app_web_1
ec944cff9f83   postgres:15    "docker-entrypoint.s…"   2 hours ago   Up 2 hours   0.0.0.0:5432->5432/tcp   todo_app_db_1


🚪 PostgreSQLコンテナにログイン

コマンド exec

docker exec -it <コンテナ名> psql -U <ユーザー名> -d <データベース名>

# (例)
docker exec -it db_container psql -U your_user -d your_database