Giter Site home page Giter Site logo

docker-persistence-example's Introduction

This repository is to show a quick example of two ways to mount persisted storage inside of docker. Education purposes only.

Both of these options will start a mysql container. One will use storage from a local machine and one will use a docker volume to save storage. you can run the scripts in each option directory to see how it works.

Option 1 - Mounting storage from the local machine

In option 1, there is a single script, file_mount_commands.sh. This shell script is a simple command that starts a mysql container with its data persisted in a directory called persisted_data.

The benefits of this approach is that the data is right on the file system and its relatively easy to set up. One gotcha of this approach is that file permissions tend to get weird since the container can use any user / group ID they want. You'll need to root to manage those files.

Feel free to run this linux shell script in a linux vm to see how it works. You'll notice persisted_data gets created and its filled with mysql database files.

You can cleanup this container by running cleanup.sh in option1

Option 2 - Using a docker volume

If you don't want to use the filesystem, docker itself has the concept of a "named" volume. When you run named-volume.sh, I am creating a volume and using that volume to save my data.

All the named data volumes are accessible by the docker volume ps command and you'll notice it is NOT saved directly on the local filesystem where you mounted it but instead its managed by docker itself somewhere in the bowels of the docker daemon. This volume will stay regardless of how many times you bring up and down the container, until you delete it with docker volume rm "VOLUME_NAME"

You can clean up this container and volume by running cleanup.sh in option2

docker-persistence-example's People

Contributors

kydane avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.