### Full MariaDB Docker run example Source: https://context7.com/mariadb-corporation/mariadb-server-docker/llms.txt A comprehensive example showing various configuration options including port mapping, persistent volumes, initialization scripts, and custom server arguments. ```bash docker run -d \ --name mariadb-full \ -p 3306:3306 \ -e MARIADB_ROOT_PASSWORD=rootsecret \ -e MARIADB_ROOT_HOST='192.168.%.%' \ -e MARIADB_DATABASE=production \ -e MARIADB_USER=produser \ -e MARIADB_PASSWORD=prodpassword \ -v mariadb-prod:/var/lib/mysql \ -v ./init:/docker-entrypoint-initdb.d:ro \ mariadb/server:10.4 \ --innodb-buffer-pool-size=2G \ --max-connections=1000 ``` -------------------------------- ### Run MariaDB Server Container Source: https://github.com/mariadb-corporation/mariadb-server-docker/blob/master/README.md Starts a MariaDB Server container with a defined root password. ```bash docker run -d --name maria -eMARIADB_ROOT_PASSWORD=mypassword mariadb/server:10.5 ``` -------------------------------- ### Run MariaDB with Root Password Source: https://context7.com/mariadb-corporation/mariadb-server-docker/llms.txt Start a MariaDB container with a specified root password using the MARIADB_ROOT_PASSWORD environment variable. This is the most common way to initialize a new database server. Use the -p flag to expose the default MariaDB port (3306) for external connections. ```bash # Basic run with root password docker run -d \ --name mariadb-server \ -e MARIADB_ROOT_PASSWORD=mypassword \ mariadb/server:10.4 ``` ```bash # Run with exposed port for external connections docker run -d \ --name mariadb-server \ -p 3306:3306 \ -e MARIADB_ROOT_PASSWORD=mypassword \ mariadb/server:10.4 ``` ```bash # Connect to the running container docker exec -it mariadb-server mysql -uroot -pmypassword ``` -------------------------------- ### Configure Root Host Access Source: https://context7.com/mariadb-corporation/mariadb-server-docker/llms.txt Control which hosts the root user can connect from using the MARIADB_ROOT_HOST environment variable. The default is '%' (all hosts). Examples show allowing connections only from localhost or a specific subnet. ```bash # Allow root connections only from localhost docker run -d \ --name mariadb-secure \ -e MARIADB_ROOT_PASSWORD=secret \ -e MARIADB_ROOT_HOST=localhost \ mariadb/server:10.4 ``` ```bash # Allow root from specific subnet docker run -d \ --name mariadb-subnet \ -e MARIADB_ROOT_PASSWORD=secret \ -e MARIADB_ROOT_HOST='192.168.1.%' \ mariadb/server:10.4 ``` -------------------------------- ### Create Database and User on Initialization Source: https://context7.com/mariadb-corporation/mariadb-server-docker/llms.txt Automatically create a database and user with full privileges during container startup using environment variables. Connect as the application user to the created database. ```bash # Create database, user, and grant privileges docker run -d \ --name mariadb-app \ -e MARIADB_ROOT_PASSWORD=rootsecret \ -e MARIADB_DATABASE=myappdb \ -e MARIADB_USER=appuser \ -e MARIADB_PASSWORD=apppassword \ mariadb/server:10.4 ``` ```bash # Connect as the application user docker exec -it mariadb-app mysql -uappuser -papppassword myappdb ``` ```sql # Verify database and user were created # MariaDB [myappdb]> SHOW DATABASES; # +--------------------+ # | Database | # +--------------------+ # | information_schema | # | myappdb | # +--------------------+ ``` -------------------------------- ### Mount Custom Initialization Scripts Source: https://context7.com/mariadb-corporation/mariadb-server-docker/llms.txt Execute SQL or shell scripts during the first container startup by mounting them to the entrypoint directory. ```bash # Create initialization scripts cat > /tmp/initdb/01-schema.sql << 'EOF' CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY, username VARCHAR(50) NOT NULL, email VARCHAR(100) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE orders ( id INT AUTO_INCREMENT PRIMARY KEY, user_id INT NOT NULL, total DECIMAL(10,2), FOREIGN KEY (user_id) REFERENCES users(id) ); EOF cat > /tmp/initdb/02-seed.sql << 'EOF' INSERT INTO users (username, email) VALUES ('john', 'john@example.com'), ('jane', 'jane@example.com'); EOF cat > /tmp/initdb/03-setup.sh << 'EOF' #!/bin/bash echo "Running custom setup script..." mysql -uroot -p$MARIADB_ROOT_PASSWORD -e "GRANT SELECT ON mydb.* TO 'readonly'@'%' IDENTIFIED BY 'readpass';" EOF chmod +x /tmp/initdb/03-setup.sh # Run with initialization scripts docker run -d \ --name mariadb-init \ -e MARIADB_ROOT_PASSWORD=secret \ -e MARIADB_DATABASE=mydb \ -v /tmp/initdb:/docker-entrypoint-initdb.d:ro \ mariadb/server:10.4 ``` -------------------------------- ### Custom MySQL Configuration Source: https://context7.com/mariadb-corporation/mariadb-server-docker/llms.txt Apply server settings via configuration files or direct command-line arguments. ```bash # Create custom configuration cat > /tmp/custom.cnf << 'EOF' [mysqld] max_connections = 500 innodb_buffer_pool_size = 1G slow_query_log = 1 slow_query_log_file = /var/log/mysql/slow.log long_query_time = 2 EOF # Mount custom configuration docker run -d \ --name mariadb-custom \ -e MARIADB_ROOT_PASSWORD=secret \ -v /tmp/custom.cnf:/etc/mysql/conf.d/custom.cnf:ro \ mariadb/server:10.4 # Pass mysqld options directly docker run -d \ --name mariadb-opts \ -e MARIADB_ROOT_PASSWORD=secret \ mariadb/server:10.4 \ --max-connections=500 \ --innodb-buffer-pool-size=1G \ --character-set-server=utf8mb4 \ --collation-server=utf8mb4_unicode_ci ``` -------------------------------- ### Run MariaDB with MARIADB-style variables Source: https://context7.com/mariadb-corporation/mariadb-server-docker/llms.txt This command demonstrates running a MariaDB container using MariaDB-native environment variables. ```bash docker run -d \ --name mariadb-native \ -e MARIADB_ROOT_PASSWORD=secret \ -e MARIADB_DATABASE=mydb \ -e MARIADB_USER=myuser \ -e MARIADB_PASSWORD=mypassword \ -e MARIADB_ROOT_HOST='%' \ mariadb/server:10.4 ``` -------------------------------- ### Run MariaDB with MySQL-style variables Source: https://context7.com/mariadb-corporation/mariadb-server-docker/llms.txt Use this command to run a MariaDB container using MySQL-compatible environment variables for configuration. ```bash docker run -d \ --name mariadb-compat \ -e MYSQL_ROOT_PASSWORD=secret \ -e MYSQL_DATABASE=mydb \ -e MYSQL_USER=myuser \ -e MYSQL_PASSWORD=mypassword \ -e MYSQL_ROOT_HOST='%' \ mariadb/server:10.4 ``` -------------------------------- ### Run as Non-Root User Source: https://context7.com/mariadb-corporation/mariadb-server-docker/llms.txt Execute the container with specific user permissions for enhanced security. ```bash # Run with specific user docker run -d \ --name mariadb-nonroot \ --user 1000:1000 \ -e MARIADB_ROOT_PASSWORD=secret \ -v mariadb-data:/var/lib/mysql \ mariadb/server:10.4 # The entrypoint automatically handles permissions # when running as root and drops privileges to mysql user ``` -------------------------------- ### Run MariaDB with Empty Root Password Source: https://context7.com/mariadb-corporation/mariadb-server-docker/llms.txt Allow an empty root password for development or testing environments. This is not recommended for production use. Connect without a password. ```bash # Run with empty root password (development only) docker run -d \ --name mariadb-dev \ -e MARIADB_ALLOW_EMPTY_PASSWORD=yes \ mariadb/server:10.4 ``` ```bash # Connect without password docker exec -it mariadb-dev mysql -uroot ``` -------------------------------- ### Pull MariaDB Server Image Source: https://github.com/mariadb-corporation/mariadb-server-docker/blob/master/README.md Downloads the specified version of the MariaDB Server Docker image. ```bash docker pull mariadb/server:10.5 ``` -------------------------------- ### Docker Compose Configuration Source: https://context7.com/mariadb-corporation/mariadb-server-docker/llms.txt Orchestrate multi-container applications using YAML configuration and CLI commands. ```yaml # docker-compose.yml version: '3.8' services: mariadb: image: mariadb/server:10.4 container_name: mariadb restart: unless-stopped environment: MARIADB_ROOT_PASSWORD: rootpassword MARIADB_DATABASE: webapp MARIADB_USER: webuser MARIADB_PASSWORD: webpassword ports: - "3306:3306" volumes: - mariadb-data:/var/lib/mysql - ./initdb:/docker-entrypoint-initdb.d:ro - ./config/custom.cnf:/etc/mysql/conf.d/custom.cnf:ro healthcheck: test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-prootpassword"] interval: 10s timeout: 5s retries: 5 app: image: myapp:latest depends_on: mariadb: condition: service_healthy environment: DB_HOST: mariadb DB_NAME: webapp DB_USER: webuser DB_PASS: webpassword volumes: mariadb-data: ``` ```bash # Start the stack docker-compose up -d # View logs docker-compose logs mariadb # Stop and remove docker-compose down # Stop, remove, and delete volumes docker-compose down -v ``` -------------------------------- ### Persist Data with Volumes Source: https://context7.com/mariadb-corporation/mariadb-server-docker/llms.txt Use named volumes or host directories to ensure database data survives container lifecycle events. ```bash # Using a named volume docker volume create mariadb-data docker run -d \ --name mariadb-persistent \ -e MARIADB_ROOT_PASSWORD=secret \ -v mariadb-data:/var/lib/mysql \ mariadb/server:10.4 # Using a host directory docker run -d \ --name mariadb-hostmount \ -e MARIADB_ROOT_PASSWORD=secret \ -v /path/to/data:/var/lib/mysql \ mariadb/server:10.4 # Backup the volume docker run --rm \ -v mariadb-data:/data:ro \ -v /backup:/backup \ busybox tar cvf /backup/mariadb-backup.tar /data ``` -------------------------------- ### Skip Timezone Info Loading Source: https://context7.com/mariadb-corporation/mariadb-server-docker/llms.txt Disable timezone information loading during initialization to improve startup performance. ```bash # Skip timezone setup docker run -d \ --name mariadb-fast \ -e MARIADB_ROOT_PASSWORD=secret \ -e MARIADB_INITDB_SKIP_TZINFO=yes \ mariadb/server:10.4 ``` -------------------------------- ### Run MariaDB with Random Root Password Source: https://context7.com/mariadb-corporation/mariadb-server-docker/llms.txt Generate a secure random root password automatically. The generated password is output to the container logs during initialization. Retrieve the password using 'docker logs'. ```bash # Run with auto-generated root password docker run -d \ --name mariadb-random \ -e MARIADB_RANDOM_ROOT_PASSWORD=yes \ mariadb/server:10.4 ``` ```bash # Retrieve the generated password from logs docker logs mariadb-random 2>&1 | grep "GENERATED ROOT PASSWORD" ``` -------------------------------- ### Pull MariaDB Server Docker Images Source: https://context7.com/mariadb-corporation/mariadb-server-docker/llms.txt Pull specific versions of the MariaDB Server Docker image using version tags. These correspond to major MariaDB releases. ```bash docker pull mariadb/server:10.4 ``` ```bash docker pull mariadb/server:10.3 ``` ```bash docker pull mariadb/server:10.2 ``` ```bash docker pull mariadb/server:10.1 ``` -------------------------------- ### Use Docker Secrets for Passwords Source: https://context7.com/mariadb-corporation/mariadb-server-docker/llms.txt Pass sensitive credentials securely using Docker secrets by appending _FILE to environment variable names. The container reads the password from the specified file. This method is suitable for both standalone Docker and Docker Swarm. ```bash # Create secret files echo "supersecretpassword" > /run/secrets/mariadb_root_password echo "userpassword" > /run/secrets/mariadb_password ``` ```bash # Run with file-based secrets docker run -d \ --name mariadb-secrets \ -v /run/secrets:/run/secrets:ro \ -e MARIADB_ROOT_PASSWORD_FILE=/run/secrets/mariadb_root_password \ -e MARIADB_DATABASE=appdb \ -e MARIADB_USER=appuser \ -e MARIADB_PASSWORD_FILE=/run/secrets/mariadb_password \ mariadb/server:10.4 ``` ```bash # Using Docker Swarm secrets docker service create \ --name mariadb-service \ --secret mariadb_root_password \ --secret mariadb_password \ -e MARIADB_ROOT_PASSWORD_FILE=/run/secrets/mariadb_root_password \ -e MARIADB_PASSWORD_FILE=/run/secrets/mariadb_password \ mariadb/server:10.4 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.