Debian 13 trixie

Docker : Use Dockerfile2025/08/26

 

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

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

FROM debian
LABEL Maintainer "ServerWorld <admin@srv.world>"

RUN apt-get update
RUN apt-get -y install tzdata
RUN apt-get -y install apache2
RUN echo "Dockerfile Test on Apache2" > /var/www/html/index.html

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

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

root@dlp:~#
docker build -t srv.world/debian-apache2:latest ./

 => [1/5] FROM docker.io/library/debian:latest                                                   
 => [2/5] RUN apt-get update                                                                     
 => [3/5] RUN apt-get -y install tzdata                                                          
 => [4/5] RUN apt-get -y install apache2                                                         
 => [5/5] RUN echo "Dockerfile Test on Apache2" > /var/www/html/index.html                    
 => exporting to image                                                                           
 => => exporting layers                                                                       
 => => writing image sha256:8101aa733631a4aad6bf36cb571fc775f42473d1a0e82bea814f78c4a57d5da3  
 => => naming to srv.world/debian-apache2:latest                               

root@dlp:~#
docker images

REPOSITORY                 TAG       IMAGE ID       CREATED          SIZE
srv.world/debian-apache2   latest    8101aa733631   57 seconds ago   226MB
srv.world/debian-nginx     latest    64fe195a727d   12 minutes ago   153MB
debian                     latest    047bd8d81940   2 weeks ago      120MB

# run container

root@dlp:~#
docker run -d -p 8081:80 srv.world/debian-apache2

3ec383b45bad97b2db381eb4e907c14fddd7203addc0f12b5546ced741dc7a84
root@dlp:~#
docker ps

CONTAINER ID   IMAGE                      COMMAND                  CREATED          STATUS         PORTS                                   NAMES
3ec383b45bad   srv.world/debian-apache2   "/usr/sbin/apachectl…"   10 seconds ago   Up 9 seconds   0.0.0.0:8081->80/tcp, :::8081->80/tcp   affectionate_pike

# verify accesses

root@dlp:~#
curl localhost:8081

Dockerfile Test on Apache2
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