Podman : Dockerfile を利用する2026/05/07 |
|
Dockerfile を利用してコンテナーイメージを作成し、コンテナーを実行します。 |
|
| [1] | 例として、Nginx のインストールと起動を行う Dockerfile を作成します。 |
|
root@dlp:~#
vi Dockerfile # 新規作成 FROM ubuntu LABEL Maintainer="ServerWorld <admin@srv.world>" RUN apt-get update RUN apt-get -y install nginx RUN echo "Dockerfile Test on Nginx" > /var/www/html/index.html EXPOSE 80 CMD ["/usr/sbin/nginx", "-g", "daemon off;"] # イメージのビルド ⇒ podman build -t [イメージ名]:[タグ] . root@dlp:~# podman build -t srv.world/ubuntu-nginx:latest . STEP 1/7: FROM ubuntu STEP 2/7: LABEL Maintainer "ServerWorld <admin@srv.world>" --> 89e71a7c9f66 STEP 3/7: RUN apt-get update ..... ..... STEP 6/7: EXPOSE 80 --> 325f7fae25c1 STEP 7/7: CMD ["/usr/sbin/nginx", "-g", "daemon off;"] COMMIT srv.world/ubuntu-nginx:latest --> 4bb5563726cd Successfully tagged srv.world/ubuntu-nginx:latest 4bb5563726cd2b6c91cf786b842f17ecfb3c86c769595674475dd46be832b479root@dlp:~# podman images REPOSITORY TAG IMAGE ID CREATED SIZE srv.world/ubuntu-nginx latest 4bb5563726cd About a minute ago 153 MB srv.world/ubuntu-apache2 latest 53b7e6d878bc 7 minutes ago 231 MB docker.io/library/ubuntu latest 30ba44506a6d 2 weeks ago 111 MB # コンテナー起動 root@dlp:~# podman run -d -p 80:80 --security-opt apparmor=unconfined srv.world/ubuntu-nginx 6a4cb8eccff34b83fe547d2405d8a69b578965f0d4c15d0510e76a467e5a7da0root@dlp:~# podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6a4cb8eccff3 srv.world/ubuntu-nginx:latest /usr/sbin/nginx -... 10 seconds ago Up 11 seconds 0.0.0.0:80->80/tcp intelligent_ptolemy # アクセス確認 root@dlp:~# curl localhost Dockerfile Test on Nginx # コンテナーネットワーク経由でもアクセス可 root@dlp:~# podman inspect -l | grep \"IPAddress
"IPAddress": "10.88.0.12",
"IPAddress": "10.88.0.12",
root@dlp:~# curl 10.88.0.12 Dockerfile Test on Nginx |
Docker ファイルでの記述フォーマットは [INSTRUCTION arguments] (指示 引数) の形となっており、INSTRUCTION
には主に下記のような種類があります。なお、INSTRUCTION の必須項目は FROM のみで、その他は任意です。FROM
が指定されていれば Docker ファイルは動作します。
|
| Sponsored Link |