Podman : Dockerfile を利用する2026/01/09 |
|
Dockerfile を利用してコンテナーイメージを作成し、コンテナーを実行します。 |
|
| [1] | 例として、Nginx のインストールと起動を行う Dockerfile を作成します。 |
|
root@dlp:~ # podman images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/freebsd-httpd latest dbf5f8b9e7e2 6 minutes ago 1.19 GB localhost/freebsd-base latest afb96df72092 36 minutes ago 902 MB quay.io/centos/centos stream10 e9ac565bc256 2 days ago 316 MB docker.io/library/ubuntu latest c3a134f2ace4 2 months ago 80.6 MB
root@dlp:~ #
vi Dockerfile # 新規作成 FROM localhost/freebsd-base LABEL Maintainer "ServerWorld <admin@srv.world>" RUN pkg install -y nginx RUN echo "Dockerfile Test on Nginx" > /usr/local/www/nginx/index.html EXPOSE 80 CMD ["/usr/local/sbin/nginx", "-g", "daemon off;"] # イメージのビルド ⇒ podman build -t [イメージ名]:[タグ] . root@dlp:~ # podman build -t localhost/freebsd-nginx:latest ./ STEP 1/6: FROM localhost/freebsd-base STEP 2/6: LABEL Maintainer "ServerWorld <admin@srv.world>" --> 2b8cb95daa5f STEP 3/6: RUN pkg install -y nginx ..... ..... Successfully tagged localhost/freebsd-nginx:latest 3cd54285ea87fb3aa5d7bfe94baca214e45de99b1dc41e4eb563961e51af9c9aroot@dlp:~ # podman images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/freebsd-nginx latest 3cd54285ea87 29 seconds ago 1.02 GB localhost/freebsd-httpd latest dbf5f8b9e7e2 8 minutes ago 1.19 GB localhost/freebsd-base latest afb96df72092 39 minutes ago 902 MB quay.io/centos/centos stream10 e9ac565bc256 2 days ago 316 MB docker.io/library/ubuntu latest c3a134f2ace4 2 months ago 80.6 MB # コンテナー起動 root@dlp:~ # podman run -d -p 80:80 freebsd-nginx df11659c41ba21f596766ed4e92932debd428ea832ae454e8b46fff5127a3055root@dlp:~ # podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES df11659c41ba localhost/freebsd-nginx:latest /usr/local/sbin/n... 22 seconds ago Up 22 seconds 0.0.0.0:80->80/tcp serene_blackburn # 任意のリモートホストからアクセス確認 root@dlp:~ # ssh freebsd@node01.srv.world "curl -s http://`hostname`" (freebsd@node01.srv.world) Password for freebsd@node01.srv.world: Dockerfile Test on Nginx # ローカルホストからアクセスする場合はコンテナーの IP アドレスを指定 root@dlp:~ # podman exec df11659c41ba /sbin/ifconfig eth0 | grep inet
inet 10.88.0.18 netmask 0xffff0000 broadcast 10.88.255.255
root@dlp:~ # curl 10.88.0.18 Dockerfile Test on Nginx |
Docker ファイルでの記述フォーマットは [INSTRUCTION arguments] (指示 引数) の形となっており、INSTRUCTION
には主に下記のような種類があります。なお、INSTRUCTION の必須項目は FROM のみで、その他は任意です。FROM
が指定されていれば Docker ファイルは動作します。
|
| Sponsored Link |
|
|