2

New to Docker, and moving on to docker compose. In the past I would start up a container with: docker run -v /localFolder:/containerFolder containerName

I am trying to do the same in a docker-compose.yml, or even in Dockerfile.

Norstorin
  • 71
  • 1
  • 10
  • 1
    Does this answer your question? [Docker-Compose persistent data MySQL](https://stackoverflow.com/questions/39175194/docker-compose-persistent-data-mysql) – Adiii Nov 29 '19 at 04:20

2 Answers2

4

Use volumes

volumes: 

# Just specify a path and let the Engine create a volume
 - /var/lib/mysql 

# Specify an absolute path mapping
 - /opt/data:/var/lib/mysql 

# Path on the host, relative to the Compose file
 - ./cache:/tmp/cache 

# User-relative path
 - ~/configs:/etc/configs/:ro 

# Named volume
 - datavolume:/var/lib/mysql

See also detailed post: Use volumes

Yasen
  • 4,241
  • 1
  • 16
  • 25
2

This is the way to persist the data in volume to the instance

services:
  redis:
    volumes:
      - '_data:/var/lib/data'

volumes:
  _data:
    driver: local
stchr
  • 201
  • 1
  • 7