How To Deal With Persistent Storage (e.g. Databases) In Docker?
The best way to deal with persistent data storage (such as a database) in Docker is to use Docker’s volume API (for docker 1.9.0 or newer) or use data-only containers for older versions of Docker.
Docker 1.9.0 or newer
The best approach for you is to use docker volume
API as shown in the following example:
docker volume create --name myvolume
docker run -d -v myvolume:/container/path/for/volume container_image my_command
Let’s break down the example command:
- The first command creates a new volume named
myvolume
in the current working directory - The second command runs the container image
container_image
and configures it to consume the newly created volumemyvolume
If you create a container with a -v volume_name:/container/fs/path
Docker will automatically create a named volume for you that can:
- Be listed through the
docker volume ls
- Be identified through the
docker volume inspect volume_name
- Backed up as a regular directory
- Backed up as before through a
--volumes-from
connection
You can also identify dangling volumes (unused volumes)
docker volume ls -f dangling=true
And then remove them using their name:
docker volume rm <volume_name>
Docker 1.8.X and older
The approach that seems to work best for production is to use a data-only container. The data-only container is run on a barebones image and does nothing except expose a data volume.
Then you can run any other container to have access to the data container volumes:
docker run --volumes-from data_container some_other_container command_to_exec
You can read more about this technique in the official documentation.
-
Solved: Cron missing newline before EOF
This error may also happen when a crontab file is generated automatically and the generator failed to insert a newline character at the end of the crontab file.
Questions -
Solved: Errors in crontab file, can't install
You may encounter this error while creating a new crontab or updating an existing one that has a syntax error.
Questions -
How To Deal With Persistent Storage (e.g. Databases) In Docker?
The best way to deal with persistent data storage (such as a database) in Docker is to use Docker’s volume API (for docker 1.9.0 or newer) or use data-only containers for older versions of Docker. ...
Questions -
How to Include Files outside of Docker’s Build Context?
You may have ended up in a situation where you wanted to include a file from outside of Docker's build context using the ADD command, but the ADD command requires the path to be within the build co...
Questions