Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Losing the Redis data after restart docker, please help #1210

Closed
2 of 3 tasks
MacMillan13 opened this issue Feb 24, 2021 · 12 comments
Closed
2 of 3 tasks

Losing the Redis data after restart docker, please help #1210

MacMillan13 opened this issue Feb 24, 2021 · 12 comments

Comments

@MacMillan13
Copy link

MacMillan13 commented Feb 24, 2021

  • This is a bug report
  • This is a feature request
  • I searched existing issues before opening this one

Expected behavior

Don't lose Redis data from volume after restart docker.

Actual behavior

Lose the Redis data after the restart docker. My docker-compose is
`
redis:

image: bitnami/redis:latest
container_name: face_redis
restart: always
command:
  - 'redis-server'
  - '--loglevel ${REDIS_LOGLEVEL:-warning}'
  - '--databases 2'
  - '--save 900 1'
  - '--save 300 10'
  - '--save 60 10000'
  - '--maxmemory ${REDIS_MAXMEM:-50mb}'
  - '--maxmemory-policy ${REDIS_POLICY:-noeviction}'
  - '--requirepass ${REDIS_PASSWORD}'
ports:
  - "6379:6379"
volumes:
  - ./docker/redis/data:/var/lib/redis
environment:
  - REDIS_REPLICATION_MODE=master
networks:
  - internal

`

Steps to reproduce the behavior

Changed volumes, changed Redis image, added commands.

Output of docker version:

Docker version 19.03.6

Additional environment details (AWS, VirtualBox, physical, etc.)

@thaJeztah
Copy link
Member

thaJeztah commented Feb 25, 2021

I suspect you're bind-mounting your data directory to the wrong location in the container. Note that unlike the official Redis image from Docker Hub (https://hub.docker.com/_/redis), which stores persistent data in /data inside the container, the Bitnami redis variant uses a different path for data storage; see "Persisting your database" section in their documentation

For persistence you should mount a directory at the /bitnami path. If the mounted directory is empty, it will be initialized on the first run.

Generally, I would recommend using the official Redis image from Docker Hub; https://hub.docker.com/_/redis, which also provide multi-arch images (allowing deployment on different architectures); be sure to read the "start with persistent storage" section in the documentation for the image on Docker Hub; https://hub.docker.com/_/redis

If you need to use the bitnami variant, be sure to read their documentation as well, to use the correct paths and configuration to persist your data (https://hub.docker.com/r/bitnami/redis)

Please keep in mind that the GitHub issue tracker is not intended as a general support forum,
but for reporting bugs and feature requests. For other type of questions, consider using one of;

I'm closing this issue because this is not a bug, but feel free to continue the conversation

@MacMillan13
Copy link
Author

MacMillan13 commented Feb 25, 2021

I suspect you're bind-mounting your data directory to the wrong location in the container. Note that unlike the official Redis image from Docker Hub (https://hub.docker.com/_/redis), which stores persistent data in /data inside the container, the Bitnami redis variant uses a different path for data storage; see "Persisting your database" section in their documentation

For persistence you should mount a directory at the /bitnami path. If the mounted directory is empty, it will be initialized on the first run.

Generally, I would recommend using the official Redis image from Docker Hub; https://hub.docker.com/_/redis, which also provide multi-arch images (allowing deployment on different architectures); be sure to read the "start with persistent storage" section in the documentation for the image on Docker Hub; https://hub.docker.com/_/redis

If you need to use the bitnami variant, be sure to read their documentation as well, to use the correct paths and configuration to persist your data (https://hub.docker.com/r/bitnami/redis)

Please keep in mind that the GitHub issue tracker is not intended as a general support forum,
but for reporting bugs and feature requests. For other type of questions, consider using one of;

I'm closing this issue because this is not a bug, but feel free to continue the conversation

@thaJeztah Thanks for the answer! But I also tried to do it by official Redis, but doesn't work. Please help..

  redis:
    image: redis:latest
    container_name: face_redis
    restart: always
    command:
      - 'redis-server'
      - '--loglevel ${REDIS_LOGLEVEL:-warning}'
      - '--databases 2'
      - '--save 900 1'
      - '--save 300 10'
      - '--save 60 10000'
      - '--maxmemory ${REDIS_MAXMEM:-50mb}'
      - '--maxmemory-policy ${REDIS_POLICY:-noeviction}'
      - '--requirepass ${REDIS_PASSWORD}'
    ports:
      - "6379:6379"
    volumes:
      - ./docker/redis/data:/data
    environment:
      - REDIS_REPLICATION_MODE=master
    networks:
      - internal

@thaJeztah
Copy link
Member

(also note that the REDIS_REPLICATION_MODE env-var looks to be something for the bitnami images only, so you may need to make changes in in your configuration if you need that setting)

@MacMillan13
Copy link
Author

MacMillan13 commented Feb 25, 2021

@thaJeztah yes I see data in ./docker/redis/data. I updated docker-compose, added --appendonly yes, but doesn't work.. After restart docker lost data from volumes... I lost more than 3 days on this.

redis:
image: redis:latest
container_name: face_redis
restart: always
command:
- 'redis-server'
- '--loglevel ${REDIS_LOGLEVEL:-warning}'
- '--requirepass ${REDIS_PASSWORD}'
- '--appendonly yes'
ports:
- "6379:6379"
volumes:
- ./docker/redis/data:/data
networks:
- internal

@thaJeztah
Copy link
Member

After restart docker lost data from volumes..

Do you mean your ./docker/redis/data directory is deleted (or files in it?)

@MacMillan13
Copy link
Author

@thaJeztah file exists, but data that was cached before docker restart is lost..

@thaJeztah
Copy link
Member

If you're running on Linux, then the ./docker/redis/data:/var/lib/redis bind-mount is literally that; it's a bind-mount in the container, so "files in the container === files on the host" (i.e., there's nothing "in between").
So if redis didn't write its cache to disk, it's most likely a redis configuration issue. You can try doing a manual save (https://redis.io/commands/save), but otherwise probably need some config changes described in (https://redis.io/topics/persistence).

before docker restart is lost..

With docker restart you mean a restart of the container, the docker daemon, or your machine? Where is ./docker/redis/data located on your host? Is it in your home-directory? (in case cryptfs is used, that won't be decrypted until you are logged in), is it on a separate storage? (if so: was it mounted the moment that the docker daemon started?)

@MacMillan13
Copy link
Author

MacMillan13 commented Feb 25, 2021

@thaJeztah This is my Ubuntu remote server. Redis saves work fine. Docker restarts means docker-compose down and then docker-compose up --build. Yes, this is my home-directory.

@thaJeztah
Copy link
Member

Not sure I have answers for your situation, and I would have to dive into that situation myself, but that's really out of scope for this issue tracker (it's very unlikely to be an issue with the docker daemon itself)

I did a quick search, and there's an old ticket on the issue tracker for the redis image about this; #1210, and I see an open ticket that may be related redis/docker-library-redis#262. Perhaps those provide more details to help you debug.

@MacMillan13
Copy link
Author

@thaJeztah this ticket 1210 is mine. Okay, thanks for trying.

@thaJeztah
Copy link
Member

Ah, sorry must've had the wrong url on my clipboard; this was the old issue I tried to link redis/docker-library-redis#4

@ch1ru
Copy link

ch1ru commented Jul 11, 2024

I had this issue and found that simply binding the data directory to a named volume with the appendonly flag solved the issue. Also I was using the redis:alpine image:

redis:
  container_name: redis
  image: redis:alpine
  restart: always
  command: redis-server --appendonly yes
  volumes:
    - redis_data:/data
  ports:
    - 6379:6379

volumes:
  redis_data:

Hope this helps anyone with this issue in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants