🔥

Firebird 2.5 ServerのDocker化を行う

2023/02/21に公開1

動作環境

動作環境としてはintel版の2016年モデルのMacBook Proにて行いました。

全体のファイル構成

❯ tree -a
.
├── docker
│   └── firebird
│       ├── Dockerfile
│       └── data
│           └── ATHLETE.FDB (データベースのファイルとなるもの)
└── docker-compose.yml

Dockerfile

Dockerfile の中身は以下になります。

FROM debian:jessie

ENV DEBIAN_FRONTEND noninteractive

RUN \
  apt-get update && \
  apt-get install -y --force-yes firebird2.5-super && \
  sed -ri 's/RemoteBindAddress = localhost/RemoteBindAddress = /g' /etc/firebird/2.5/firebird.conf && \
  apt-get clean && \
  rm -rf /var/lib/apt/lists/*

RUN ln -sf /dev/stdout /var/log/firebird/firebird2.5.log

VOLUME /var/lib/firebird/2.5/data
VOLUME /var/lib/firebird/2.5/backup

EXPOSE 3050

CMD ["/usr/sbin/fbguard"]

Dockerfileに関する補足説明

32bit版のfirebirdサーバをコンテナで利用したい場合はイメージ名をdebian:jessie-i386に変えます。

docker-compose.yml

docker-compose.yml の中身は以下になります。

version: '3'

services:
  firebird:
    container_name: firebird  
    build: ./docker/firebird
    ports:
      - "3050:3050"
    volumes:
      - "./docker/firebird/data:/var/lib/firebird/2.5/data"

実行

実行する際はdocker-compose.yamlファイルがある位置でdocker-compose up -dコマンドを実行します。

docker-compose up -d
[+] Building 4.5s (7/7) FINISHED                                                
 => [internal] load build definition from Dockerfile                       0.1s
 => => transferring dockerfile: 560B                                       0.0s
 => [internal] load .dockerignore                                          0.0s
 => => transferring context: 2B                                            0.0s
 => [internal] load metadata for docker.io/library/debian:jessie           4.3s
 => [1/3] FROM docker.io/library/debian:jessie@sha256:32ad5050caffb2c7e96  0.0s
 => CACHED [2/3] RUN   apt-get update &&   apt-get install -y --force-yes  0.0s
 => CACHED [3/3] RUN ln -sf /dev/stdout /var/log/firebird/firebird2.5.log  0.0s
 => exporting to image                                                     0.0s
 => => exporting layers                                                    0.0s
 => => writing image sha256:06124ff02b29c234fdac17afd5fb56088c4d59715823b  0.0s
 => => naming to docker.io/library/firebird-firebird                       0.0s

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
[+] Running 2/2
 ⠿ Network firebird_default  Created                                       0.1s
 ⠿ Container firebird        Started                                       1.0s

firebirdツールのコマンドを使う場合

Firebirdでバックアップおよびリストアを行うためのユーティリティであるgbakコマンドを使う場合、以下のコマンドをterminalにて実行することで呼び出すことができます。

docker-compose exec firebird /bin/bash
root@cdd791fda36c:/# gbak
gbak:Usage:
     gbak -b <db set> <backup set> [backup options] [general options]
     gbak -c <backup set> <db set> [restore options] [general options]
     <db set> = <database> | <db1 size1>...<dbN> (size in db pages)
     <backup set> = <backup> | <bk1 size1>...<bkN> (size in bytes = n[K|M|G])
     -recreate overwrite and -replace can be used instead of -c
gbak:legal switches are:
	-B(ACKUP_DATABASE)    backup database to file
	-C(REATE_DATABASE)    create database from backup file (restore)
	-R(ECREATE_DATABASE) [O(VERWRITE)] create (or replace if OVERWRITE used)
				database from backup file (restore)
	-REP(LACE_DATABASE)   replace database from backup file (restore)
gbak:backup options are:
        -CO(NVERT)            backup external files as tables
	-E(XPAND)             no data compression
	-FA(CTOR)             blocking factor
	-G(ARBAGE_COLLECT)    inhibit garbage collection
	-IG(NORE)             ignore bad checksums
	-L(IMBO)              ignore transactions in limbo
	-NOD(BTRIGGERS)       do not run database triggers
	-NT                   Non-Transportable backup file format
	-OL(D_DESCRIPTIONS)   save old style metadata descriptions
	-T(RANSPORTABLE)      transportable backup -- data in XDR format
gbak:restore options are:
	-BU(FFERS)            override page buffers default
	-FIX_FSS_D(ATA)       fix malformed UNICODE_FSS data
	-FIX_FSS_M(ETADATA)   fix malformed UNICODE_FSS metadata
	-I(NACTIVE)           deactivate indexes during restore
	-K(ILL)               restore without creating shadows
	-MO(DE) <access>      "read_only" or "read_write" access
	-N(O_VALIDITY)        do not restore database validity conditions
	-O(NE_AT_A_TIME)      restore one table at a time
	-P(AGE_SIZE)          override default page size
	-USE_(ALL_SPACE)      do not reserve space for record versions
gbak:general options are:
        -FE(TCH_PASSWORD)     fetch password from file
	-M(ETA_DATA)          backup or restore metadata only
	-PAS(SWORD)           Firebird password
        -RO(LE)               Firebird SQL role
        -SE(RVICE)            use services manager
	-USER                 Firebird user name
	-V(ERIFY)             report each action taken
	-Y  <path>            redirect/suppress status message output
	-Z                    print version number

Firebirdデータベースに対するSQL文の実行や管理を行うためのコマンドラインツールであるisql-fbなども実行することができます。

# docker-compose exec firebird isql-fb

Use CONNECT or CREATE DATABASE to specify a database
SQL> CONNECT /var/lib/firebird/2.5/data/ATHLETE.FDB user sysdba password masterkey;
Database:  /var/lib/firebird/2.5/data/ATHLETE.FDB, User: sysdba
SQL> select * from result;

Discussion

NOGU.DNOGU.D

2023/10/10[追記]
security.debian.org に jessie のアップデートが含まれなくなったため、上記のDockerfileを実行すると以下のようなエラーが表示されます。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
省略
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9.413   404  Not Found
9.417 W: Failed to fetch http://security.debian.org/debian-security/dists/jessie/updates/main/binary-i386/Packages  404  Not Found [IP: 151.101.2.132 80]
9.417 
9.417 W: Failed to fetch http://deb.debian.org/debian/dists/jessie/main/binary-i386/Packages  404  Not Found
9.417 
9.417 W: Failed to fetch http://deb.debian.org/debian/dists/jessie-updates/main/binary-i386/Packages  404  Not Found
9.417 
9.417 E: Some index files failed to download. They have been ignored, or old ones used instead.
------
failed to solve: process "/bin/sh -c apt-get update &&   apt-get install -y --force-yes firebird2.5-super &&   sed -ri 's/RemoteBindAddress = localhost/RemoteBindAddress = /g' /etc/firebird/2.5/firebird.conf &&   apt-get clean &&   rm -rf /var/lib/apt/lists/*" did not complete successfully: exit code: 100

これを解決するためには、aptパッケージのダウンロード元を変更する必要があります。
以下の三行を追加し、apt update を実行します。

RUN rm /etc/apt/sources.list
RUN echo "deb http://archive.debian.org/debian-security jessie/updates main" >> /etc/apt/sources.list.d/jessie.list
RUN echo "deb http://archive.debian.org/debian jessie main" >> /etc/apt/sources.list.d/jessie.list