Home:ALL Converter>Docker Compose: Import MySQL database into a running docker container from CLI

Docker Compose: Import MySQL database into a running docker container from CLI

Ask Time:2021-05-04T18:50:47         Author:Blackbam

Json Formatter

After trying various things whatever I do I get certain error messages - I want to import a local SQL file database into a running docker container.

This is what I try to do:

sudo docker-compose exec project-db mysql -uuser -ppassword database_name < "/localpath/2020-05-03-14_00-hexagon_brainformance.sql"

This is my docker compose file:

  db:
    image: mysql:5.7.25
    container_name: "project-db"
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 'root'
    ports:
      - 3306:3306
    volumes:

This is what sudo docker ps gives me:

cb2c5e884c90 mysql:5.7.25 "docker-entrypoint.s…" 19 hours ago Up 3 hours 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp project-db

This is my current error:

ERROR: No such service: project-db

Tried various variations with using db instead of project-db and also with -it flag to go into the container first. What am I doing wrong?

Author:Blackbam,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/67383339/docker-compose-import-mysql-database-into-a-running-docker-container-from-cli
yy