skip to Main Content

with docker-compose I know how to do that:

version: '3.0'

services:

  redis:

    image: redis

    volumes:

      - redis_data:/data

volumes:

  redis_data:

How to run the same without dockerfile/compose file?

Thank you

3

Answers


  1. With plain Docker, you use the -v option:

    docker run -v redis_data:/data redis
    

    Here you can find more on this.

    Login or Signup to reply.
  2. Try this one:

    docker run -d -p 6379:6379 -v redis_data:/data --name rds redis 
    
    Login or Signup to reply.
  3. Since you are already using docker-compose, use external option for volume:

    version: '3.0'
    services:
      redis:
        image: redis
        volumes:
          - redis_data:/data
    
    volumes:
      redis_data:
        external: false
    

    From docs:

    If set to true, specifies that this volume has been created outside of
    Compose. docker-compose up does not attempt to create it, and raises
    an error if it doesn’t exist.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search