CentOS Stream 10

Docker : Use Dockerfile2025/08/08

 

Use Dockerfile and create Docker images automatically.
It is also useful for configuration management.

[1] For example, Create a Dockerfile that Apache httpd is installed and started.
[root@dlp ~]#
vi Dockerfile
# create new

FROM quay.io/centos/centos:stream10
LABEL maintainer="ServerWorld <admin@srv.world>"

RUN dnf -y install httpd
RUN echo "Dockerfile Test on Aapche httpd" > /var/www/html/index.html

EXPOSE 80
CMD ["-D", "FOREGROUND"]
ENTRYPOINT ["/usr/sbin/httpd"]

# build image ⇒ docker build -t [image name]:[tag] .

[root@dlp ~]#
docker build -t srv.world/centos-httpd:latest ./

[+] Building 0.0s (0/1)                                                                                          docker:default
 => [internal] load build definition from Dockerfile                                                                       0.0s
[+] Building 10.3s (4/6)                                                                                         docker:default
 => [internal] load build definition from Dockerfile                                                                       0.0s
 => => transferring dockerfile: 339B                                                                                       0.0s
 => [internal] load metadata for quay.io/centos/centos:stream10                                                            0.0s
 => [internal] load .dockerignore                                                                                          0.0s
 => => transferring context: 2B                                                                                            0.0s
 => [1/3] FROM quay.io/centos/centos:stream10                                                                              0.0s
 => [2/3] RUN dnf -y install httpd                                 
 
.....
.....

[root@dlp ~]#
docker images

REPOSITORY               TAG        IMAGE ID       CREATED          SIZE
srv.world/centos-httpd   latest     134889cd315b   6 minutes ago    351MB
srv.world/centos-nginx   latest     b587aa926cbf   14 minutes ago   345MB
quay.io/centos/centos    stream10   02ae49ff109e   7 weeks ago      306MB

# run container

[root@dlp ~]#
docker run -d -p 8081:80 srv.world/centos-httpd

9cb332807144fd30c61ba9b7e3aaf45b7d215d34ece8444f1d0ac759091fa69c

[root@dlp ~]#
docker ps

CONTAINER ID   IMAGE                    COMMAND                  CREATED         STATUS         PORTS                                     NAMES
9cb332807144   srv.world/centos-httpd   "/usr/sbin/httpd -D ..."   9 seconds ago   Up 9 seconds   0.0.0.0:8081->80/tcp, [::]:8081->80/tcp   admiring_cori

# verify accesses

[root@dlp ~]#
curl localhost:8081

Dockerfile Test on Aapche httpd
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.
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