FreeBSD 14
Sponsored Link

Podman : Access to Services on Containers2024/02/28

 
If you'd like to access to services like HTTP or SSH that are running on Containers as daemons, Configure like follows.
[1] For example, use a Container that [apache24] is installed.
root@dlp:~ #
podman images

REPOSITORY                TAG         IMAGE ID      CREATED        SIZE
localhost/freebsd-httpd   latest      add46dedb2b7  7 minutes ago  1.44 GB
localhost/freebsd-base    latest      2527bfa5eeb4  20 hours ago   1.05 GB
quay.io/centos/centos     stream9     ce3ac91d4020  13 days ago    161 MB
docker.io/library/ubuntu  latest      3db8720ecbf5  2 weeks ago    80.4 MB

# run a container and also start [httpd]
# map with [-p xxx:xxx] to [(Host Port):(Container Port)]

root@dlp:~ #
podman run -dt -p 8081:80 freebsd-httpd /usr/local/sbin/httpd -D FOREGROUND

2f8e6e5da3702c12b84dd99f929a0e14a25b0b782f8cca56ca3a6dce071f0376

root@dlp:~ #
podman ps

CONTAINER ID  IMAGE                           COMMAND               CREATED        STATUS        PORTS                 NAMES
2f8e6e5da370  localhost/freebsd-httpd:latest  /usr/local/sbin/h...  8 seconds ago  Up 8 seconds  0.0.0.0:8081->80/tcp  sweet_edison

# create a test page

root@dlp:~ #
podman exec 2f8e6e5da370 /bin/sh -c 'echo "httpd on Podman Container" > /usr/local/www/apache24/data/index.html'
# verify to access to httpd from any remote host

root@dlp:~ #
ssh freebsd@node01.srv.world "curl -s http://`hostname`:8081"

(freebsd@node01.srv.world) Password for freebsd@node01.srv.world:
httpd on Podman Container
# to access from localhost, specify container IP address directly

root@dlp:~ #
podman exec 2f8e6e5da370 /sbin/ifconfig eth0 | grep inet

        inet 10.88.0.2 netmask 0xffff0000 broadcast 10.88.255.255

root@dlp:~ #
curl 10.88.0.2

httpd on Podman Container
Matched Content