LoginSignup
15
13

More than 5 years have passed since last update.

テスト用途のSFTP/FTPS/FTPサーバーを単独で起動するdocker-compose.ymlの例

Last updated at Posted at 2018-10-25

SFTP/FTPS/FTPで接続した先のファイルをバッチ処理するプログラムを開発したときに、テストのために用意したdocker-compose.ymlファイルを共有します。

docker-compose-remote-file-system / GitHub
https://github.com/miyanaga/docker-compose-remote-file-system

./remoteディレクトリは、開発マシン単独でローカルファイルシステムとしても、SFTP/FTPS/FTPとしても操作することができます。

貼り付けた画像_2018_10_25_11_27.png

例えばFTP越しのファイルに対する処理をテストするとき、このdocker-compose.ymlを使うと、以下の手順でテストを記述できます。

  1. ローカルファイルとしてテストデータを用意
  2. プログラムはFTP経由でそのファイルを処理
  3. ローカルファイルとして結果を検証・クリーンナップ

以下の点で嬉しいというものです。

  • 別途FTPサーバーを立てるより手間がかからず、テストファイルの扱いが楽で通信も速い
  • モックを使うより実際の環境に近く、モックの準備やメンテも不要

docker-compose.yml

鍵ファイルも必要なので、GitHubのリポジトリを参照ください。
使い方もREADMEに記載しました。

version: "3"
services:
  sftp-without-key:
    image: atmoz/sftp
    volumes:
      - ./remote:/home/sftp-without-key/remote
    ports:
      - "10220:22"
    command: sftp-without-key:pass:1001
  sftp-with-rsa-key:
    image: atmoz/sftp
    volumes:
      - ./remote:/home/sftp-with-rsa-key/remote
      - ./ssh/id_rsa.pub:/home/sftp-with-rsa-key/.ssh/keys/id_rsa.pub:ro
    ports:
      - "10221:22"
    command: sftp-with-rsa-key::1001
  sftp-with-ed25519-key:
    image: atmoz/sftp
    volumes:
      - ./remote:/home/sftp-with-ed25519-key/remote
      - ./ssh/id_ed25519.pub:/home/sftp-with-ed25519-key/.ssh/keys/id_ed25519.pub:ro
    ports:
      - "10222:22"
    command: sftp-with-ed25519-key::1001
  ftp:
    image: wildscamp/vsftpd
    volumes:
      - ./remote:/home/virtual/ftp/remote
    environment:
      VSFTPD_USER_1: "ftp:pass:1001:"
      PASV_MIN_PORT: 30100
      PASV_MAX_PORT: 30109
    ports:
      - "10210:21"
      - "30100-30109:30100-30109"
  ftps:
    image: phpstorm/ftps
    volumes:
      - ./remote:/home/virtual/ftps/remote
    environment:
      VSFTPD_USER_1: "ftps:pass:1001:"
      PASV_MIN_PORT: 30110
      PASV_MAX_PORT: 30119
    ports:
      - "10211:21"
      - "30110-30119:30110-30119"
15
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
13