Debian 11 Bullseye
Sponsored Link

Podman : Use Dockerfile2021/08/28

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

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

STEP 1: FROM debian
STEP 2: MAINTAINER ServerWorld <admin@srv.world>
--> 7716e72324f
STEP 3: RUN apt-get update

.....
.....

STEP 6: EXPOSE 80
--> d509d0caa34
STEP 7: CMD ["/usr/sbin/nginx", "-g", "daemon off;"]
STEP 8: COMMIT srv.world/debian-nginx:latest
--> 37125087a75
37125087a75f79f7aca97b415ac309c91d7d9abcc3cbba8f2839746a3abf4f06

root@dlp:~#
podman images

REPOSITORY                TAG     IMAGE ID      CREATED         SIZE
srv.world/debian-nginx    latest  37125087a75f  49 seconds ago  216 MB
srv.world/debian-apache2  latest  68a7269c5457  11 minutes ago  260 MB
docker.io/library/debian  latest  fe3c5de03486  10 days ago     129 MB

# run container

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

c88c4c048837db18a719b86e91ffd78c72eea9fd9cf78547aa132763c26b946d

root@dlp:~#
podman ps

CONTAINER ID  IMAGE                   COMMAND               CREATED         STATUS             PORTS               NAMES
c88c4c048837  srv.world/debian-nginx  /usr/sbin/nginx -...  12 seconds ago  Up 13 seconds ago  0.0.0.0:80->80/tcp  amazing_archimedes

# 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": "172.16.16.8",
                    "IPAddress": "172.16.16.8",

root@dlp:~#
curl 172.16.16.8

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 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