AlmaLinux 9
Sponsored Link

Podman : Use Dockerfile2023/03/01

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

STEP 1/6: FROM almalinux
STEP 2/6: MAINTAINER ServerWorld <admin@srv.world>
--> 10096b868a1
STEP 3/6: RUN dnf -y install nginx

.....
.....

STEP 5/6: EXPOSE 80
--> 6b26f04ed36
STEP 6/6: CMD ["/usr/sbin/nginx", "-g", "daemon off;"]
COMMIT srv.world/almalinux-nginx:latest
--> 762eb0a249a
Successfully tagged srv.world/almalinux-nginx:latest
f556ccecaed8b13774c3a17270924a16d71afb25611021a0f2034b87dd56e8d2

[root@dlp ~]#
podman images

REPOSITORY                   TAG         IMAGE ID      CREATED         SIZE
srv.world/almalinux-nginx    latest      f556ccecaed8  56 seconds ago  310 MB
srv.world/almalinux-httpd    latest      ffd19e5b5339  10 minutes ago  251 MB
docker.io/library/almalinux  latest      d3ffa43c2567  6 days ago      196 MB

# run container

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

9dfa7f239072d74ab069dc1eff3c771c61db8eefdbab06dd34c6ad08846a5271

[root@dlp ~]#
podman ps

CONTAINER ID  IMAGE                             COMMAND               CREATED         STATUS             PORTS               NAMES
9dfa7f239072  srv.world/almalinux-nginx:latest  /usr/sbin/nginx -...  12 seconds ago  Up 13 seconds ago  0.0.0.0:80->80/tcp  wizardly_lumiere

# 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.10",
                         "IPAddress": "10.88.0.10",

[root@dlp ~]#
curl 10.88.0.10

Dockerfile Test on Nginx
The format of Dockerfile is [INSTRUCTION arguments] .
Refer to the following description for INSTRUCTION.
INSTRUCTION Description
FROM iIt 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 remore 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