Wednesday, December 14, 2022

[FIXED] Why does my docker image keep crashing when I try and build it due to a syntax error that is not making sense?

Issue

I am trying to build a mysql container using a docker file and an SQL file to create the tables but I keep getting this error in my terminal:> [3/3] RUN /docker-entrypoint-initdb.d/books.sql: #7 0.686 /docker-entrypoint-initdb.d/books.sql: line 1: syntax error near unexpected token`(' '7 0.686 /docker-entrypoint-initdb.d/books.sql: line 1: ``CREATE TABLE "articulos" (`

where it says I have a "`" in from of CREATE and I don't why that's showing up.

here is my docker file

FROM mysql:latest

ENV MYSQL_DATABASE books

COPY  ./sqlscript /docker-entrypoint-initdb.d/

RUN /docker-entrypoint-initdb.d/books.sql 

and this is my SQL file

CREATE TABLE "articulos" (
"id" int NOT NULL AUTO_INCREMENT,
"titulo" text,
"contenido" text,
"fechacreacion" date DEFAULT NULL,
"categoria" text,
PRIMARY KEY ("id")
) ENGINE=InnoDB AUTO_INCREMENT=143 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

Thank you in advance.


Solution

You could be facing two problems:

  1. Docker is trying to run your .sql file as if it was a bash script
  2. And anyway, your MySQL server might not be running when building

Try removing your last Dockerfile line (RUN /docker-entrypoint-initdb.d/books.sql ).

It might work like you want it to since I presume that .sql files placed in the /docker-entrypoint-initdb.d/ directory are executed on startup.



Answered By - Camille Louédoc
Answer Checked By - Willingham (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.