FreeBSD 14
Sponsored Link

Podman : Use Dockerfile2024/02/28

 
Use Dockerfile and create Container images automatically.
It is also useful for configuration management for Container images.
[1] For example, Create a Dockerfile that Nginx is installed and started.
root@dlp:~ #
podman images

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

root@dlp:~ #
vi Dockerfile
# create new

FROM localhost/freebsd-base
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;"]

# build image ⇒ podman build -t [image name]:[tag] .

root@dlp:~ #
podman build -t localhost/freebsd-nginx:latest ./

STEP 1/6: FROM localhost/freebsd-base
STEP 2/6: MAINTAINER ServerWorld <admin@srv.world>
--> 94a83aae8186
STEP 3/6: RUN pkg install -y nginx
.....
.....
Successfully tagged localhost/freebsd-nginx:latest
a0a053cc78a36337f6d2ed5d91b03faca848c90ef957d3574246bc804a7a7be3

root@dlp:~ #
podman images

REPOSITORY                TAG         IMAGE ID      CREATED         SIZE
localhost/freebsd-nginx   latest      a0a053cc78a3  13 seconds ago  1.17 GB
localhost/freebsd-httpd   latest      add46dedb2b7  6 hours ago     1.44 GB
localhost/freebsd-base    latest      2527bfa5eeb4  26 hours ago    1.05 GB
quay.io/centos/centos     stream9     ce3ac91d4020  2 weeks ago     161 MB
docker.io/library/ubuntu  latest      3db8720ecbf5  2 weeks ago     80.4 MB

# run container

root@dlp:~ #
podman run -d -p 80:80 freebsd-nginx

26508ff7f0d95d58c16e055fc15be1701535299c51258356f893e0c6ed0ef296

root@dlp:~ #
podman ps

CONTAINER ID  IMAGE                           COMMAND               CREATED        STATUS        PORTS               NAMES
26508ff7f0d9  localhost/freebsd-nginx:latest  /usr/local/sbin/n...  8 seconds ago  Up 7 seconds  0.0.0.0:80->80/tcp  boring_newton

# verify to access to nginx from any remote host

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
# to access from localhost, specify container IP address directly

root@dlp:~ #
podman exec 26508ff7f0d9 /sbin/ifconfig eth0 | grep inet

        inet 10.88.0.5 netmask 0xffff0000 broadcast 10.88.255.255

root@dlp:~ #
curl 10.88.0.5

Dockerfile Test on Nginx
The format of Dockerfile is [INSTRUCTION arguments] .
Refer to the following description for INSTRUCTION.
INSTRUCTION Description
FROM It sets the Base Image for subsequent instructions.
MAINTAINER It sets the Author field of the generated images.
RUN It will execute any commands when Docker image will be created.
CMD It will execute any commands when Docker container will be executed.
ENTRYPOINT It will execute any commands when Docker container will be executed.
LABEL It adds metadata to an image.
EXPOSE It informs Docker that the container will listen on the specified network ports at runtime.
ENV It sets the environment variable.
ADD It copies new files, directories or remote file URLs.
COPY It copies new files or directories.
The differences of [ADD] are that it's impossible to specify remote URL and also it will not extract archive files automatically.
VOLUME It creates a mount point with the specified name and marks it as holding externally mounted volumes from native host or other containers.
USER It sets the user name or UID.
WORKDIR It sets the working directory.

Matched Content