CentOS Stream 10
Sponsored Link

Podman : Use Dockerfile2025/01/21

 

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 ~]#
vi Dockerfile
# create new

FROM quay.io/centos/centos:stream10
LABEL Maintainer "ServerWorld <admin@srv.world>"

RUN dnf -y install nginx
RUN echo "Dockerfile Test on Nginx" > /usr/share/nginx/html/index.html

EXPOSE 80
CMD ["/usr/sbin/nginx", "-g", "daemon off;"]

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

[root@dlp ~]#
podman build -t srv.world/centos-nginx:latest .

STEP 1/6: FROM quay.io/centos/centos:stream10
STEP 2/6: LABEL Maintainer "ServerWorld <admin@srv.world>"
--> f56fe93572b6
STEP 3/6: RUN dnf -y install nginx

.....
.....

STEP 5/6: EXPOSE 80
--> a359719d7431
STEP 6/6: CMD ["/usr/sbin/nginx", "-g", "daemon off;"]
COMMIT srv.world/centos-nginx:latest
--> 451cd94e6c28
Successfully tagged srv.world/centos-nginx:latest
451cd94e6c28ad9a8c31bf9ebec39a200c2fa9f6ae4eb9119b28f48bfdedf424

[root@dlp ~]#
podman images

REPOSITORY              TAG         IMAGE ID      CREATED            SIZE
srv.world/centos-nginx  latest      d64d577f9a9e  46 minutes ago     347 MB
srv.world/centos-httpd  latest      ff3843182253  About an hour ago  354 MB
quay.io/centos/centos   stream10    1ef274445e32  7 days ago         311 MB

# run container

[root@dlp ~]#
podman run -d -p 80:80 srv.world/centos-nginx

925839be591b3e8cf1d776eb77e289cd6a8fc2cca757dfbe37d8e5b6ef0dd5a5

[root@dlp ~]#
podman ps

CONTAINER ID  IMAGE                          COMMAND               CREATED         STATUS         PORTS               NAMES
925839be591b  srv.world/centos-nginx:latest  /usr/sbin/nginx -...  12 seconds ago  Up 13 seconds  0.0.0.0:80->80/tcp  agitated_engelbart

# if Firewalld is running, change setting

[root@dlp ~]#
vi /etc/firewalld/firewalld.conf
# line 98 : change to [no]

StrictForwardPorts=
no
[root@dlp ~]#
systemctl restart firewalld
# verify accesses

[root@dlp ~]#
curl localhost

Dockerfile Test on Nginx
# also possible to access via container network

[root@dlp ~]#
podman inspect -l | grep \"IPAddress

               "IPAddress": "10.88.0.13",
                         "IPAddress": "10.88.0.13",

[root@dlp ~]#
curl 10.88.0.13

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