如果我有data.sql,如何将数据库导入到我的mysql docker容器?如何导入数据库数据。在码头工人化的世界中,这增加了一层复杂性。请一些方法。
这是我的docker-compose.yml:
nginx: build: ./nginx/ container_name: nginx-container ports: - 80:80 links: - php volumes_from: - app-data php: build: ./php/ container_name: php-container expose: - 9000 links: - mysql volumes_from: - app-data app-data: image: php:7.0-fpm container_name: app-data-container volumes: - ./www/html/:/var/www/html/ command: "true" mysql: image: mysql:latest container_name: mysql-container ports: - 3306:3306 volumes_from: - mysql-data environment: MYSQL_ROOT_PASSWORD: secret MYSQL_DATABASE: name_db MYSQL_USER: user MYSQL_PASSWORD: password mysql-data: image: mysql:latest container_name: mysql-data-container volumes: - /var/lib/mysql command: "true"
我似乎无法使用最新的mysql或mysql:5.7进行此操作。所以我改用mariaDB。这是我的docker-compose.yaml代码。
docker-compose.yaml
version: '3' services: mysql: image: mariadb:10.3 container_name: mariadb volumes: - container-volume:/var/lib/mysql - ./dump.sql:/docker-entrypoint-initdb.d/dump.sql environment: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: name_db ports: - "3306:3306" volumes: container-volume: