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

Docker-compose + TailscaleでTailnet専用にWebサービスをホスティングする (Giteaを例に)

Last updated at Posted at 2025-08-08

Tailscale、便利ですよね。

$ tailscale serve --bg 3000

これだけでTailnet用に3000番をHTTPSに包んで待ち受けることができます。超便利。
ただしlocalhostのポートしか包めません。Cloudflaredみたいにローカルの別のマシンにリバースプロキシすることが認めらていません。

Tailscaleをdocker-composeしたい!

すると、docker-composeしたときにちょっと一癖あるわけです。
cloudflaredだったら普通に一緒にcomposeされた別のコンテナのHTTPを直接つつけばいいところ、composeで tailscale serve --bg 3000 するには、どうかして見せたい別コンテナのアプリケーションをTailscaleコンテナの 127.0.0.1:3000 で待受けさせる必要があります。困った。

答え: network: "service:tailscale"

答えを言ってしまうと、ネットワークを別コンテナのネットワークと共有させるオプションがちゃんとあります。

# docker-compose.yml
services:
  server:
    image: docker.gitea.com/gitea:1.23.5
    environment:
      - USER_UID=1000
      - USER_GID=1000
      - GITEA__database__DB_TYPE=postgres
      - GITEA__database__HOST=/var/run/postgresql
      - GITEA__database__NAME=gitea
      - GITEA__database__USER=gitea
      - GITEA__database__PASSWD=gitea
    restart: unless-stopped
    volumes:
      - ./gitea:/data
      - pgsocket:/var/run/postgresql
    depends_on:
      - tailscale
      - db
    network_mode: "service:tailscale"

  db:
    image: docker.io/library/postgres:14
    restart: unless-stopped
    environment:
      - POSTGRES_USER=gitea
      - POSTGRES_PASSWORD=gitea
      - POSTGRES_DB=gitea
    volumes:
      - ./postgres:/var/lib/postgresql/data
      - pgsocket:/var/run/postgresql
      - ./postgresql.conf:/etc/postgresql/postgresql.conf:ro

  tailscale:
    image: tailscale/tailscale:latest
    restart: unless-stopped
    cap_add:
      - NET_ADMIN
      - NET_RAW
    environment:
      - TS_STATE_DIR=/var/lib/tailscale
      - TS_EXTRA_ARGS=--advertise-exit-node=false
    volumes:
      - ./tailscale_state:/var/lib/tailscale
      - /dev/net/tun:/dev/net/tun

volumes:
  pgsocket:
# postgresql.conf
listen_addresses = ''  # TCPを無効化
unix_socket_directories = '/var/run/postgresql'

こんな感じにします。ちなみに、volumeをディレクトリマウントにしているのは好み。ソケットをホストのディレクトリに生やすのはそこはかとなく嫌なので、そこだけDocker Volume。

起動してTailscaleコンテナでserveのコマンドを叩きます。

docker-compose up -d
docker-compose exec tailscale sh
tailscale up
tailscale serve --bg 3000

これでgiteaがTailnetから使えるようになります。

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