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

Published

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?

Source: Docker Questions

Published
Categorised as devops, docker, docker-compose, import, mysql Tagged , , , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq