amit
amit

Reputation: 2331

Running MYSQL for database generation

I'm attempting to run MYSQLD to generate some data for dump to file in docker image (I don't actually need to MYSQL running after that)

USER mysql
RUN mysqld --initialize-insecure 
RUN mysqld --daemonize --skip-networking    
RUN mysql --protocol=socket -uroot -hlocalhost -e "create table DDD"

All seems to go fine until I hit

"0.205 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)",

which is strange to me as I get it right after

/usr/sbin/mysqld: ready for connections. Version: '8.0.20'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server - GPL.

what am I'm doing wrong?

#15 [11/13] RUN mysqld --initialize-insecure
#15 0.210 2020-05-03T21:27:14.416004Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.20) initializing of server in progress as process 7
#15 0.211 2020-05-03T21:27:14.420895Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
#15 0.535 2020-05-03T21:27:14.744127Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
#15 1.665 2020-05-03T21:27:15.874257Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
#15 DONE 3.7s

#16 [12/13] RUN mysqld --daemonize --skip-networking
#16 0.434 2020-05-03T21:27:18.296394Z 0 [Warning] [MY-010101] [Server] Insecure configuration for --secure-file-priv: Location is accessible to all OS users. Consider choosing a different directory.
#16 0.434 2020-05-03T21:27:18.296447Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.20) starting as process 8
#16 0.435 2020-05-03T21:27:18.309882Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
#16 2.820 2020-05-03T21:27:20.693463Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
#16 3.005 2020-05-03T21:27:20.878562Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock'
#16 3.214 2020-05-03T21:27:21.087873Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
#16 3.230 2020-05-03T21:27:21.103997Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.20'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server - GPL.
#16 DONE 3.9s

#17 [13/13] RUN mysql --protocol=socket -uroot -hlocalhost -e "create table ...
#17 0.205 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
#17 ERROR: executor failed running [/bin/sh -c mysql --protocol=socket -uroot -hlocalhost -e "create table DDD"]: runc did not terminate sucessfully

Upvotes: 0

Views: 85

Answers (1)

danblack
danblack

Reputation: 14666

The RUN build stages of a docker file are executed sequentially. You can't run a daemon process there available for the next step.

Use the docker library's mysql, and under the "Initializing a fresh instance" heading lists a number of SQL/script mechanisms in /docker-entrypoint-initdb.d that will initialize a database for you.

You can immediately shutdown after this has been run (maybe even a script at the end of the /docker-entrypoint-initdb.d that returns failure)

Upvotes: 1

Related Questions