devops-exercises/topics/containers/solutions/containerized_db_persistent_storage.md
abregman 99c4e02ecf Rename exercises dir
Name it instead "topics" so it won't be
strange if some topics included "exercises" directory.
2022-08-02 01:53:56 +03:00

986 B

Containerized DB with Persistent Storage

  1. Run a container with a database of any type of you prefer (MySql, PostgreSQL, Mongo, etc.)
  2. Use a mount point on the host for the database instead of using the container storage for that
  3. Explain why using the host storage instead of the container one might be a better choice
  4. Verify the container is running

Solution

# Create the directory for the DB on host
mkdir -pv ~/local/mysql
sudo semanage fcontext -a -t container_file_t '/home/USERNAME/local/mysql(/.*)?'
sudo restorecon -R /home/USERNAME/local/mysql

# Run the container
podman run --name mysql -e MYSQL_USER=mario -e MYSQL_PASSWORD=tooManyMushrooms -e MYSQL_DATABASE=university -e MYSQL_ROOT_PASSWORD=MushroomsPizza -d mysql -v /home/USERNAME/local/mysql:/var/lib/mysql/db

# Verify it's running
podman ps

It's better to use the storage host because in case the container ever gets removed (or storage reclaimed) you have the DB data still available.