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?

(個人メモ)パスワード認証をかけたRedisをDockerで動かす手順

Posted at

はじめに

パスワード認証をかけたRedisをDockerで動かす手順です。
Dockerfileとdocker-compose.yaml等を作成して、Redisを動かします。
docker-compose.yamlを用意しておけば、どのコンテナもdocker-compose upで起動できるので、便利だと思ってます。

前提環境(動作確認環境)

  • Mac OS
  • Rancher Desktop

セットアップ

  • 作業用ディレクトリを作成
$ mkdir redis
  • Dockerfileを作成
$ vi Dockerfile

以下の内容を記載

FROM redis:latest
COPY redis.conf /usr/local/etc/redis/redis.conf
CMD ["redis-server", "/usr/local/etc/redis/redis.conf"]
  • docker-compose.yamlを作成
$ vi docker-compose.yaml

以下の内容を記載

version: '3.8'
services:
 redis:
  image: redis:latest
  container_name: my_redis
  restart: always
  ports:
   - "6379:6379"
  volumes:
   - ./redis_data:/data
   - ./redis.conf:/usr/local/etc/redis/redis.conf
  command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
  • redis.confを作成
$vi redis.conf

以下の内容を記載

user myuser on >mypassword allcommands allkeys

→この場合、myuser/mypasswordが認証情報

ここまでの手順で3個ファイルが作成されていることを確認してください

$ tree
.
├── Dockerfile
├── docker-compose.yaml
└── redis.conf

Redis起動

$ docker-compose up

ポート6379でredisが起動します

Redis操作

  • コンテナにログイン(ホスト側での操作)
$ docker exec -it my_redis /bin/bash

→このコマンドでコンテナ内部にログインします

  • redisにログイン(コンテナ内部での操作)
$ redis-cli

実行例

image.png

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?