2017-01-11 7 views
0

初期化されたデータベースを持つMySQLサーバを含む単純なコンテナを作成したいとします。私Dockerfileは現在、次のようになります。DockerファイルにMySQLデータベースを作成する際のエラー

FROM ubuntu:16.10 

RUN apt-get update 

# install MySQL; root user with no password 
ENV DEBIAN_FRONTEND noninteractive 
RUN apt-get install -y mysql-server mysql-client 

RUN service mysql start 
RUN mysqladmin -u root create mydb 

CMD [ "bash" ] 

をしかし、私は次のエラーを取得するdocker build -t mysql-test .介して画像を作成するとき:

Step 7 : RUN mysqladmin -u root create mydb 
---> Running in a35c3d176d4f 
mysqladmin: connect to server at 'localhost' failed 
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)' 
Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists! 
The command '/bin/sh -c mysqladmin -u root create mydb' returned a non-zero code: 1 

私は、データベースを作成したい行をコメント

RUN mysqladmin -u root create mydb )イメージをビルドして起動し、コマンドラインからmysqladminコマンドを実行することができます。

# this works 
> docker run -it mysql-test 
[email protected]> service mysql start 
[email protected]> mysqladmin -u root create mydb 

daを作成するとエラーが発生するのはなぜですかDockerfileのtabase?ありがとうございました! RUN instructionのドキュメントを読ん

+1

私はこれが既に解決されていると思います。こちらを参照してください。http://stackoverflow.com/questions/29145370/docker-initialize-mysql-database-with-schema –

+0

[Docker - スキーマを使用してmysqlデータベースを初期化する]の可能な複製(http://stackoverflow.com/questions/29145370)/docker-initialize-mysql-database-with-schema) –

+0

私は少し質問を再定式化しようとしました:私はこのエラーが他の質問でどのように対処されて表示されません – Michael

答えて

0

が、それは明らかに:

The RUN instruction will execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile.

ので、各実行命令は、新しいイメージを作成し、MySQLサーバを起動し、データベースを作成することは同じRUN命令で結合する必要があります。

RUN service mysql start && mysqladmin -u root create mydb 

これで解決します。

関連する問題