1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[全部無料] Cloudflare Tunnelを使って余った M1 Mac miniをDockerサーバーとしてネットに公開する

Last updated at Posted at 2025-12-05

自宅に余っていた M1 Mac miniを再利用して好きにいじれるサーバー(今回はDocker runさせたサービスを公開する目的)を立てました。

手順

ブラウザでの作業

  1. ドメインを購入
    初年度100円くらいの格安ドメインを取得(以下 oreore.me で説明)
    ※更新が高いので1年後にはドメインを買い直す予定です。

  2. Cloudflareに登録
    Cloudflare の無料プランに登録します。

  3. Cloudflareを日本語化
    ダッシュボード画面右上の Profile → Language でUIを日本語に変更します。

  4. Cloudflareにドメイン登録

    • 青いボタン「+ドメインのオンボード」を押す
    • 既存のドメインを入力欄に oreore.me と入力して「続行」
    • DNSレコードを確認して「アクティベーション」
  5. ドメインにSSL適用

    • ダッシュボードでoreore.meドメインをクリックし、ドメイン設定画面へ
    • 左メニューから SSL/TLS → 概要を選択
    • 現在の暗号化モード:フレキシブル に設定(ローカル側がhttpなので)

Mac miniでの作業

  • macにcloudflaredをインストール
  $ brew install cloudflare/cloudflare/cloudflared

  • cloudflaredにログインしてドメインを選択
  $ cloudflared tunnel login

ブラウザでcloudflareにログイン画面が開くのでログインし、
トンネルで使うoreore.meドメインを選択


  • トンネル作成 & トンネルIDをどこかにメモ
  $ cloudflared tunnel create <トンネル名> 

すると以下が表示がされるので、トンネルIDをメモ
c11---****-72a***e```の部分がトンネルID(実際は伏せ字なし)

  Tunnel credentials written to /Users/<ユーザー名>/.cloudflared/c1*****1-****-****-****-72a********e.json. cloudflared chose this file based on where your origin certificate was found. Keep this file secret. To revoke these credentials, delete the tunnel.

  Created tunnel <トンネル名> with id c1*****1-****-****-****-72a********e
  • ~/.cloudflared/ にconfig.yml(トンネル設定ファイル)作成
tunnel: <トンネルID>
credentials-file: /Users/<ユーザー名>/.cloudflared/<トンネルID>.json

ingress:

  - hostname: <サブドメイン1>.oreore.me
    service: http://localhost:8080

  - hostname: <サブドメイン2>.oreore.me
    service: http://localhost:3456

  - service: http_status:404

複数のdockerを公開したい場合は、上例のように複数 -hostname & service の行を書く

  • Cloudflared を使って、各サブドメインをDNS設定する
    Aレコードが〜とか気にしなくていいので楽ちん
cloudflared tunnel route dns itxtunnel <サブドメイン1>.oreore.me
cloudflared tunnel route dns itxtunnel <サブドメイン2>.oreore.me
  • 公開したいdockerイメージをlocalhostで動かす
  $ cd /my-docker-img/lamp(例)
  $ docker-compose up -d
  • トンネルを起動!(5秒くらいで開通)
$ cloudflared tunnel run <トンネルの名前>
  • ブラウザからアクセスしてみる
    https://<サブドメイン>.oreore.me/

感想

以前はMyDNSサービスを使って変動する自宅IPアドレスを定期報告する必要がありました。
ちょっとしたことでその更新が途切れたりしてたもんですが、この方法だとそれもなく便利です。

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?