Fedora 34
Sponsored Link

Podman : Use Dockerfile2021/05/14

 
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 fedora
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 ⇒ docker build -t [image name]:[tag] .

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

STEP 1: FROM fedora
STEP 2: MAINTAINER ServerWorld <admin@srv.world>
--> bcd6681d3b3
STEP 3: RUN dnf -y install nginx
.....
.....
Successfully tagged srv.world/fedora-nginx:latest
c2f266c51e583f0c09b47aedf4cc47d843c1b309ccd799091aa72ba85fd53d05

[root@dlp ~]#
podman images

REPOSITORY                         TAG     IMAGE ID      CREATED         SIZE
srv.world/fedora-nginx             latest  c2f266c51e58  20 seconds ago  425 MB
srv.world/fedora-httpd             latest  810bed9d1157  7 minutes ago   529 MB
registry.fedoraproject.org/fedora  latest  5f05951e2065  2 weeks ago     187 MB

# run container

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

a1fbd8a8d83db23062a4452103c531c2ce811e2b5a5dea5018dcd921a081d44c

[root@dlp ~]#
podman ps

CONTAINER ID  IMAGE                          COMMAND               CREATED        STATUS            PORTS               NAMES
a1fbd8a8d83d  srv.world/fedora-nginx:latest  /usr/sbin/nginx -...  7 seconds ago  Up 8 seconds ago  0.0.0.0:80->80/tcp  jovial_curie

# 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.11",
                    "IPAddress": "10.88.0.11",

[root@dlp ~]#
curl 10.88.0.11

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