Ubuntu 25.04
Sponsored Link

Podman : Use Dockerfile2025/04/22

 

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 ubuntu
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/ubuntu-nginx:latest .

STEP 1/7: FROM ubuntu
STEP 2/7: MAINTAINER ServerWorld <admin@srv.world>
--> e49d0cbab6b1
STEP 3/7: RUN apt-get update

.....
.....

STEP 7/7: CMD ["/usr/sbin/nginx", "-g", "daemon off;"]
COMMIT srv.world/ubuntu-nginx:latest
--> 1fbf2477f02c
Successfully tagged srv.world/ubuntu-nginx:latest
1fbf2477f02cd01968a529fc12d5b01f95367a533117b0ef57851514080956ea

root@dlp:~#
podman images

REPOSITORY                TAG         IMAGE ID      CREATED         SIZE
srv.world/ubuntu-nginx    latest      1fbf2477f02c  58 seconds ago  137 MB
srv.world/ubuntu-apache2  latest      b7f1351d1b3c  8 minutes ago   246 MB
docker.io/library/ubuntu  latest      602eb6fb314b  13 days ago     80.6 MB

# run container

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

092dcbb88514700160d12b9fb514d3f4d0861aaa6eae505b5c59a2f3a3c7eb92

root@dlp:~#
podman ps

CONTAINER ID  IMAGE                          COMMAND               CREATED        STATUS         PORTS               NAMES
092dcbb88514  srv.world/ubuntu-nginx:latest  /usr/sbin/nginx -...  9 seconds ago  Up 10 seconds  0.0.0.0:80->80/tcp  nervous_blackwell

# 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.2",
                    "IPAddress": "10.88.0.2",

root@dlp:~#
curl 10.88.0.2

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