Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Dockerで最小限のPython実行環境を作る/Creating minimum Pyth...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
y_sone
October 31, 2021
Programming
780
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Dockerで最小限のPython実行環境を作る/Creating minimum Python container
Dockerで最小限のPython実行環境を作成しHello, World!するまでの体験談です。
2021年10月31日「とにかくほめる!マウントなしのLT会」にて初登壇。
y_sone
October 31, 2021
More Decks by y_sone
See All by y_sone
エンジニアの健康管理術 / Engineer Health Management Techniques
y_sone
13
11k
初心者でも使いやすい!PHPUnitアノテーション活用術/Easy to Use Even for Beginners! PHPUnit Annotation Utilization Techniques
y_sone
0
1.2k
Laravelコアファイルのコードリーディング/Reading the core code of Laravel
y_sone
0
570
Laravelのコアファイルを読んでみて/Impression of reading the core code of the Laravel framework
y_sone
0
260
2021年を振り返って/Reflection in 2021
y_sone
0
210
Exercismのすすめ / Recommend Exercism
y_sone
1
330
Other Decks in Programming
See All in Programming
学びを記事・スライド・Xへ高速展開する― AI-assisted Learning Loopで回すコンテンツ生成術
ochtum
0
200
自作Discord音声botをLambda MicroVMsに移行した話 / Migrating My Discord Voice Bot to Lambda MicroVMs
akihisaikeda
1
300
Kawaiicon: Kubernetes, it's no longer cool, but let's secure it anyway!
barnbarn
0
130
作れるエンジニアから、価値を届けるエンジニアへ
ryunakayama
1
250
AI時代のシニアエンジニアとは
yosuke_furukawa
PRO
15
11k
Secure Your Coding Agent Like It’s Malware (v1.5) 🇬🇧 @Code.talks 2026
richargh
0
110
React Native에 현대적인 빌드 도구 더하기: Rollipop 구현기
leegeunhyeok
0
180
Будущее локальных LLM – Алексей Голобурдин, PythoNN
sobolevn
0
120
Crash Auto Pipelines
veronikapj
1
410
地方こそサーバーレス — 10年続けた、顔が見えるチームで確かな基盤を / Serverless Matters Most in Regional Areas — 10 Years of Building Reliable Foundations with Close-Knit Teams
seike460
PRO
1
340
ActionController meets Protocol Buffers
sorah
1
800
はじめてのPLATEAU
nokonoko1203
1
640
Featured
See All Featured
Ethics towards AI in product and experience design
skipperchong
2
460
Making Projects Easy
brettharned
120
6.9k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
430
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.7k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Code Review Best Practice
trishagee
74
20k
Chasing Engaging Ingredients in Design
codingconduct
0
390
How Software Deployment tools have changed in the past 20 years
geshan
3
35k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k
エンジニアに許された特別な時間の終わり
watany
109
250k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
580
A Soul's Torment
seathinner
8
3.9k
Transcript
Dockerで最小限のPython実行環境を作る Hello, World!ができればヨシ! Presented by y_sone @20211031_とにかくほめる!マウントなしの LT会🎃
自己紹介 • 2018年8月にWebエンジニアへ転職 • 主な使用言語はPHP • たまにイベントに出没します(スタッフ経験あり)
今日話すこと • なぜPythonなのか • なぜDockerなのか • 最小限のPython実行環境を作りHello, World!を実行するまで
なぜPythonなのか • 今後仕事で使うから
なぜDockerなのか • 今後仕事で使うから • PCの環境を汚したくないから • 複数の環境で使いたいから
最小限のPython実行環境を作り Hello, World!を実行するまで 1. マイルール 2. ディレクトリ構成 3. Dockerfileの構成 4.
docker-compose.yamlの構成 5. コンテナを起動しPythonでHello, World!を実行する
マイルール • Docker Composeを利用したい • 適当なソースをコピペして理由はわからないけど動きましたーは嫌だ • よくわからないものを雰囲気で作るのは嫌なので、機能は最小限に • 最終的にHello,
World!ができればヨシ!
ディレクトリ構成 python_study ├── Dockerfile ├── docker-compose.yaml └── hello_world.py • コマンドはpython_studyディレクトリで実行する
• hello_world.pyはprint("Hello, World!")のみ記述
Dockerfileの構成 FROM python:3 WORKDIR /usr/src/app COPY . .
Dockerfileの構成 # Docker Hubからイメージを取得 FROM python:3 # コマンド実行場所の作業ディレクトリを指定 WORKDIR /usr/src/app
# ホストのファイルを作業ディレクトリへコピー COPY . .
docker-compose.yamlの構成 version: '3' services: web: build: . stdin_open: true
docker-compose.yamlの構成 # Composeファイルのバージョン version: '3' # コンテナの設定を定義 services: # コンテナの名前
web: # Dockerfileの存在するディレクトリのパス build: . # プロセスを継続させてコンテナの正常終了を防ぐ, tty: trueでもOK stdin_open: true
コンテナの構築 $ docker-compose up -d … Creating python_study_web_1 ... done
コンテナの起動確認 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES 9282080df68d python_study_web "python3" 48 seconds ago Up 47 seconds python_study_web_1
upコマンドが実行していること • 目的 docker-compose.yamlに定義されているサービスを起動する • 起動までの流れ Dockerイメージが存在しない →Dockerfileを元にイメージpython_study_webを構築(=ビルド) →イメージからコンテナpython_study_web_1を構築 →コンテナを起動
コンテナに入る $ docker-compose exec web bash root@9282080df68d:/usr/src/app# ls Dockerfile docker-compose.yaml
hello_world.py • docker-compose.yamlに記述したservice(web)に入りbashを実行する • docker container exec -it python_study_web_1 bashでもOK
PythonでHello, World! # python hello_world.py Hello, World!
おわりに • LTは久しぶりなので緊張しました • 他人への説明を前提にすると要求される理解度のレベルが跳ね上がる • しかし、他人へ説明できない=理解していないと同じではないか? • 何となくでスルーしていた部分に向き合う良い機会になった
参考 • Dockerfileの書き方 https://docs.docker.jp/engine/reference/builder.html • docker-compose.yamlの書き方 https://github.com/compose-spec/compose-spec/blob/master/spec.md https://ai-can-fly.hateblo.jp/entry/summary-of-docker-compose-for-beginners • docker-composeコマンド
https://docs.docker.jp/compose/reference/toc.html • stdin_open/tty/itオプション https://ohbarye.hatenablog.jp/entry/2019/05/05/learn-tty-with-docker https://zenn.dev/hohner/articles/43a0da20181d34