# Debian：Dockerカスタムイメージの作成

**URL:** <https://forum.ficusonline.com/t/topic/418>\
**Category:** Linux\
**Created:** [2021 年 4 月 24 日午前 2:54 UTC](https://forum.ficusonline.com/t/topic/418 "2021-04-24T02:54:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)\
**Post date:** [2021 年 4 月 24 日午前 2:54 UTC](https://forum.ficusonline.com/t/topic/418/1 "2021-04-24T02:54:56Z")

</div>

コンテナ内で複数のアプリ・サービスを稼働するため、システムデーモン **systemd** を組込んだベースとなるDockerイメージを作成、このベースイメージを雛形にし、必要なサービス（アプリ）を導入した新規イメージを作成します。

**Dockerhub Debian**  
[https://hub.docker.com/\_/debian](https://hub.docker.com/_/debian)

**jrei/systemd-debian**  
[https://hub.docker.com/r/jrei/systemd-debian/dockerfile](https://hub.docker.com/r/jrei/systemd-debian/dockerfile)

**ベースイメージのDockerfile**

`project/debian-buster-systemd-image/Dockerfile`

```auto
FROM debian:buster

ENV container docker
ENV LC_ALL C
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update \
    && apt-get install -y systemd \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN rm -f /lib/systemd/system/multi-user.target.wants/* \
    /etc/systemd/system/*.wants/* \
    /lib/systemd/system/local-fs.target.wants/* \
    /lib/systemd/system/sockets.target.wants/*udev* \
    /lib/systemd/system/sockets.target.wants/*initctl* \
    /lib/systemd/system/sysinit.target.wants/systemd-tmpfiles-setup* \
    /lib/systemd/system/systemd-update-utmp*

VOLUME ["/sys/fs/cgroup"]

CMD ["/lib/systemd/systemd"]

```

**ベースイメージの作成**

```auto
$ docker build --rm -t local/buster-systemd .

```

ベースイメージから、デーモン起動するサービス・アプリを導入したイメージを作成するための **Dockerfile:nginx-buster** を作成。

`project/nginx-buster`

```auto
FROM local/buster-systemd

RUN apt-get update && apt-get install -y \
  bash \
  nano \
  tzdata \
  git \
  nginx \
  certbot \
  dhcpcd5 \
  hostapd \
  dnsmasq \
  iptables-persistent \
  vnstat \
  qrencode \
  php-cgi \
  php php-fpm \
  init \
  && cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime \
  && echo "Asia/Tokyo" > /etc/timezone

# Set working directory
WORKDIR /var/www/html

COPY dnsmasq.conf /etc/

RUN systemctl enable nginx.service hostapd.service php7.3-fpm.service dnsmasq.service
CMD ["/sbin/init"]

```

**docker-composeファイルの作成**

`project/docker-compose.yml`

```auto
version: '3.5'

services:
  # nginx https://hub.docker.com/_/nginx?tab=description
  nginx:
    container_name: nginx
    build: 
      context: ./docker_files
      dockerfile: nginx-buster
    tty: true
    privileged: true
    volumes:
      # note) host directory mount into docker container directory (one way:host>container)
      # shared nginx default.conf between host and container
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
      # shared the directory /var/www/html in php-fpm container
      - ./html:/var/www/html
      # letsencrypt, cretated by nginx-certbot docker-compose 
      - letsencrypt:/etc/letsencrypt
      # For RaspAP
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
    cap_add:
      - SYS_ADMIN
    restart: unless-stopped
    network_mode: host

volumes:
    letsencrypt:
      external: true

```

**コンテナのビルド・起動**

```auto
＄ docker-compose up -d

```

**ビルド**

```auto
$ docker-compose build nginx

```

**注）php7.3-fpm.sock エラー**

```auto
$ docker exec -ti nginx bash

# mkdir /var/run/php
# service php7.3-fpm restart

```

---

<div class="post-metadata">

**Author:** ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)\
**Post date:** [2024 年 2 月 11 日午前 2:40 UTC](https://forum.ficusonline.com/t/topic/418/2 "2024-02-11T02:40:35Z")

</div>

## Geminiに質問

debianのdockerイメージのentrypointは？

Debian の Docker イメージの ENTRYPOINT は、イメージのバージョンと使用目的によって異なります。

**公式イメージの場合**

- **Debian 11 (“bullseye”)**
  - ベースイメージ (`debian:bullseye`)：`/bin/sh -c`
  - ツールイメージ (`debian:bullseye-tools`)：`/bin/bash`

- **Debian 10 (“buster”)**
  - ベースイメージ (`debian:buster`)：`/bin/sh -c`
  - ツールイメージ (`debian:buster-tools`)：`/bin/bash`

- **Debian 9 (“stretch”)**
  - ベースイメージ (`debian:stretch`)：`/bin/sh -c`
  - ツールイメージ (`debian:stretch-tools`)：`/bin/bash`

**その他のイメージの場合**

- イメージ作成者が ENTRYPOINT を設定していない場合：`/bin/sh -c`
- イメージ作成者が ENTRYPOINT を設定している場合：設定内容

**ENTRYPOINT の確認方法**

以下のコマンドを実行すると、イメージの ENTRYPOINT を確認できます。

`docker inspect <image-name>`

**例**

`docker inspect debian:bullseye`

出力結果の中に `Entrypoint` という項目があり、そこに ENTRYPOINT の内容が記述されています。

**ENTRYPOINT の変更方法**

Dockerfile で ENTRYPOINT を設定することで、イメージの ENTRYPOINT を変更できます。

**例**

`FROM debian:bullseye

ENTRYPOINT [“/bin/bash”]

CMD [“-c”, “echo Hello, world!”]`

この Dockerfile を基に作成されたイメージは、コンテナ起動時に `/bin/bash` が実行され、`Hello, world!` というメッセージが出力されます。
