Thursday, November 27, 2025

Podman : Use Dockerfile

 

Podman : Use Dockerfile

 

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 debian
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;"]

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

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

STEP 1/7: FROM debian
STEP 2/7: LABEL Maintainer "ServerWorld <admin@srv.world>"
--> b297213dbe62
STEP 3/7: RUN apt-get update

.....
.....

COMMIT srv.world/debian-nginx:latest
--> 33b7b5b10b13
Successfully tagged srv.world/debian-nginx:latest
33b7b5b10b139dea3a74317cc07172214360a6df956f4799b84dfb3e8b1b2cc0

root@dlp:~# 
podman images

REPOSITORY                TAG         IMAGE ID      CREATED             SIZE
srv.world/debian-nginx    latest      33b7b5b10b13  About a minute ago  157 MB
srv.world/debian-apache2  latest      a0aca892bf29  8 minutes ago       234 MB
docker.io/library/debian  latest      047bd8d81940  11 days ago         124 MB

# run container

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

05470306188d35c1a6367f585d5f8656c041fe88ca2ec50f2cc7db4588d23691

root@dlp:~# 
podman ps

CONTAINER ID  IMAGE                          COMMAND               CREATED        STATUS        PORTS               NAMES
05470306188d  srv.world/debian-nginx:latest  /usr/sbin/nginx -...  9 seconds ago  Up 9 seconds  0.0.0.0:80->80/tcp  exciting_noyce

# 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.15",
                         "IPAddress": "10.88.0.15",

root@dlp:~# 
curl 10.88.0.15

Dockerfile Test on Nginx
The format of Dockerfile is [INSTRUCTION arguments] .
Refer to the following description for INSTRUCTION.
INSTRUCTIONDescription
FROMIt sets the Base Image for subsequent instructions.
RUNIt will execute any commands when Docker image will be created.
CMDIt will execute any commands when Docker container will be executed.
ENTRYPOINTIt will execute any commands when Docker container will be executed.
LABELIt adds metadata to an image.
EXPOSEIt informs Docker that the container will listen on the specified network ports at runtime.
ENVIt sets the environment variable.
ADDIt copies new files, directories or remote file URLs.
COPYIt 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.
VOLUMEIt creates a mount point with the specified name and marks it as holding externally mounted volumes from native host or other containers.
USERIt sets the user name or UID.
WORKDIRIt sets the working directory.

No comments:

Post a Comment