LoginSignup
1
0

More than 1 year has passed since last update.

EC2 に RDS for Redis と通信を行う Docker コンテナを起動する

Last updated at Posted at 2021-11-16

経緯

  • プライベートなサブネットに配置した RDS for Redis (TLS暗号化) と パブリックなサブネットに配置した EC2 内の Docker コンテナの間に通信が必要になった

対応

  • AWS 公式ドキュメントの "redis-cli を使用して送信中の暗号化を有効にした Redis クラスターに接続するには" 以降の手順を参考にし、dockerfile を作成した
  • 具体的には、stunnelを利用する方法を採用した

内容

  • それぞれのファイルを作成し、Docker イメージをビルド
  • API の Docker イメージにするときは、dockerfile にソースコード取り込みなどの処理を追加すればいい

dockerfile

FROM alpine:latest

RUN apk add --no-cache stunnel
COPY ./redis-stunnel.conf /etc/stunnel/redis-stunnel.conf
COPY ./docker-entrypoint.sh /usr/local/bin

ENTRYPOINT [ "docker-entrypoint.sh" ]

docker-entrypoint.sh

#!/bin/sh
stunnel /etc/stunnel/redis-stunnel.conf

redis-stunnel.conf

fips = no
setuid = root
setgid = root
pid = /var/run/stunnel.pid
debug = 7 
delay = yes
options = NO_SSLv2
options = NO_SSLv3
[redis-cli]
   client = yes
   accept = 127.0.0.1:6379
   connect = master.my-redis-cluster.xxxx.yyyy.cache.amazonaws.com
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