Docker: Upload large sql file

Asked

Viewed 432 times

-1

People are having problems with Docker. I’m using Docker and the docker-compose to create and configure a web environment quickly and practically. I’ve been using Docker for a while, but I’ve never had to upload a large file to a bunch of data. I’m using Mysql 5.5 for compatibility in some of my projects.

I did some research and found that I could upload a file. sh from host to mysql container and there run what I wanted, however I always get the following error:

mysql: unrecognized service

My file Dockerfile

FROM php:5.6-apache
RUN docker-php-ext-install mysqli
RUN a2enmod rewrite
COPY setup.sh /mysql/setup.sh
COPY setup.sql /mysql/setup.sql
RUN /mysql/setup.sh

My file docker-compose.yml

php:
  build: .
  ports:
   - "80:80"
   - "443:443"
  volumes:
   - ./www:/var/www/html
  links:
   - mysql   
mysql:
  image: mysql:5.5
  volumes:
   - /var/lib/mysql
  environment:
   - MYSQL_ROOT_PASSWORD=1234
   - MYSQL_DATABASE=my_db

This is my file setup.sh

#!/bin/bash
set -e
service mysql start
mysql uroot -p1234 my_db < /mysql/setup.sql
service mysql stop

Everything goes well, the error happens in the setup.sh line: service mysql start

Thank you in advance.

1 answer

1


Duke, don’t you want to go up the dump after the machine? after the container start, could run for example:

docker exec -i CONTAINER mysql -u root --password=1234 my_db < ./MySQLDump.sql

This would solve your problem in a simpler way. It allows you to better control the bank, not needing to climb a dump every time you build.

  • This way it worked perfectly, but only with files that don’t have comment lines with --. I removed the comments and it worked. But if I have to remove possible comments every time I upload a file, then it will get too complicated. One solution that worked perfectly without errors is: Log into the container in /bin/bash, use Docker cp to copy the HOST file into the container and then log into mysql and climb up there.

  • Really? I climb dump so always, never gave problem. How are you doing the dump?

  • Seriously! The SQL file dump I have was not made by me.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.