zoukankan      html  css  js  c++  java
  • Docker使用札记

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

    一般来说作为容器应用的入口都是entrypoint.sh文件,也就是Dockerfile最后一条指令为是:

    ENTRYPOINT ["/entrypoint.sh"]
    

    开始以为是修改的部分哪里不对,将内部内容改为只有一行命令:

    date && pwd
    

      

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

    原文:

    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.

    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.

    所以这解释跳过。

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

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

    在设置了所需的环境变量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

    更多详情请参看这里

      

  • 相关阅读:
    Swift
    Swift
    Swift
    Swift
    Swift
    Swift
    Swift
    C++生产和使用的临时对象
    RecyclerView0基于使用
    Docker创建MySQL集装箱
  • 原文地址:https://www.cnblogs.com/xzysaber/p/8882502.html
Copyright © 2011-2022 走看看