Fedora 31
Sponsored Link

Podman : Use Dockerfile
2019/11/19
 
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/nginx_server:latest .

STEP 1: FROM fedora
STEP 2: MAINTAINER ServerWorld <admin@srv.world>
8f9f2e01a343a7e8caff0a48658f55e3ca2f7895c48325403825ad568750d489
STEP 3: RUN dnf -y install nginx
.....
.....
STEP 6: CMD ["/usr/sbin/nginx", "-g", "daemon off;"]
STEP 7: COMMIT srv.world/nginx_server:latest
0311ace27400d80a643591ce434d7fae0b9d8dea43cb1363540a5d6918e6020c

[root@dlp ~]#
podman images

REPOSITORY                 TAG      IMAGE ID       CREATED          SIZE
srv.world/nginx_server     latest   0311ace27400   23 seconds ago   991 MB
srv.world/fedora_httpd     latest   bb6f86826d3f   7 minutes ago    622 MB
docker.io/library/fedora   latest   f0858ad3febd   2 weeks ago      201 MB

# run container

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

8eec6fea0d0bbb86f641f3219db0291e9b5163b1cbeb70a032b5a37967bd84b4

[root@dlp ~]#
podman ps

CONTAINER ID  IMAGE                          COMMAND               CREATED         STATUS             PORTS               NAMES
8eec6fea0d0b  srv.world/nginx_server:latest  /usr/sbin/nginx -...  23 seconds ago  Up 22 seconds ago  0.0.0.0:80->80/tcp  confident_zhukovsky

# 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.9",
[root@dlp ~]#
curl 10.88.0.9

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