Docker使用札记 - 使用中遇到的问题总结

1. 启动容器时报错误“: No such file or directory”mysql

通常来讲做为容器应用的入口都是entrypoint.sh文件,也就是Dockerfile最后一条指令为是:linux

ENTRYPOINT ["/entrypoint.sh"]

 

开始觉得是修改的部分哪里不对,将内部内容改成只有一行命令:git

date && pwd

  

从新构建并启动容器,仍然不行。网上有说是文件权限的,可是因为Windows系统将文件放入Linux镜像中是默认加了执行权限(+x),详细解释可参看这里github

原文:sql

That warning was added, because the Windows filesystem does not have an option to mark a file as 'executable'. Building a linux image from a Windows machine would therefore break the image if a file has to be marked executable.docker

For that reason, files are marked executable by default when building from a windows client; the warning is there so that you are notified of that, and (if needed), modify the Dockerfile to change/remove the executable bit afterwards.shell

因此这解释跳过。数据库

后面在SO看到一条回答才猛然醒悟,这个问题每次在Windows上编写shell脚本常常遇到。问题就出在换行符上,将CRLF改成LF,保持再次构建并启动容器,问题获得解决。windows

 2. 在使用Docker-compose中使用MySQL时,没有按预期建立数据库,用户等信息bash

在设置了所需的环境变量MYSQL_DATABASE等没有按预期建立数据库等信息:

mysql:
     image: mysql:5.7
     volumes:
       - dbdata:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: test
       MYSQL_DATABASE: test
       MYSQL_USER: test
       MYSQL_PASSWORD: test  

 进过屡次实验和查询得知原来是因为其中的volumes项致使的,固然并非不能使用该项,并且很是有必要。缘由出在以前构建时使用的volume中已经存在MySQL文件,则上述的环境变量再也不生效,须要删掉volume,删掉后从新建立启动便可:

docker volume ls //得到相应的volume名称
docker volume rm project_db 

或者:

docker-compose down //停掉当前项目的服务
docker volume prune //删除全部未使用的volume

而后重建并重启服务:

docker up -d

更多详情请参看这里

相关文章
相关标签/搜索