Posts

Showing posts with the label docker

Docker Container mount to a mysteric folder which I don't know where is it.

Env:  Ubuntu 20.04  When install too many versions of docker on the same machine,  it could have a weird mount behavior. I have a folder called /media/xxx/uuid/prod/db, hereafter, "local db folder".   and I mount this folder to the /db folder inside container, hereafter "container db folder".    I start container like this:  docker run --rm --mount type=bind,source=/media/xxx/uuid/prod/db,target=/db image:latest As you can expected, something happened. the container was  up and running.  the mount seemed not right. If I add a new file to the local db folder , the new file was not available in container db folder ,  and vice versa,  if I add a new file to the container db folder ,  the file wasn't available in the local db folder either.   Looks like the local db folder and container db folder wasn't mapped.   Run docker inspect, I could see the mount configure was correct, from  /media/xxx/uuid/pr...

如何优雅的关闭容器,看这一篇就够了

 https://mp.weixin.qq.com/s/OojCtlC1HZkc5X9XYDecNg 不管你  Dockerfile  用其中哪个(ENTRYPOINT, CMD)  指令,两个指令都推荐使用 exec 格式,而不是 shell 格式。原因就是因为使用 shell 格式之后,程序会以  /bin/sh -c  的子命令启动,并且 shell 格式下不会传递任何信号给程序。这也就导致,在  docker stop  容器的时候,以这种格式运行的程序捕捉不到发送的信号,也就谈不上优雅的关闭了。 docker stop  停掉容器的时候,默认会发送一个  SIGTERM  的信号,默认 10s 后容器没有停止的话,就  SIGKILL  强制停止容器。

不要再docker里面跑数据库 - 读书笔记

https://www.toutiao.com/i6675622107390411276/   数据安全不高 不要将数据储存在容器中,这也是 Docker 官方容器使用技巧中的一条。容器随时可以停止、或者删除。 但是容器的 Volumes 设计是围绕 Union FS 镜像层提供持久存储,数据安全缺乏保证。如果容器突然崩溃,数据库未正常关闭,可能会损坏数据。另外,容器里共享数据卷组,对物理机硬件损伤也比较大。 性能不高 关系型数据库,对 IO 要求较高。当一台物理机跑多个时,IO 就会累加,导致 IO 瓶颈 解决办法 数据库程序与数据分离 数据库程序与数据需要进行分离,将数据存放到共享存储,程序放到容器里。如果容器有异常或 MySQL 服务异常,自动启动一个全新的容器。另外,建议不要把数据存放到宿主机里, 跑轻量级或分布式数据库 Docker 里部署轻量级或分布式数据库,Docker 本身就推荐服务挂掉,自动启动新容器,而不是继续重启容器服务。 状态问题 Docker 快速扩展的一个重要特征就是无状态,具有数据状态的都不适合直接放在 Docker 里面,如果 Docker 中安装数据库,存储服务需要单独提供。 资源隔离问题  Docker 是利用 Cgroup 实现资源限制的,只能限制资源消耗的最大值,而不能隔绝其他程序占用自己的资源。 应用场景 对数据丢失不敏感的业务(例如用户搜索商品)就可以数据化,利用数据库分片来来增加实例数,从而增加吞吐量。 Docker 适合跑轻量级或分布式数据库,当 Docker 服务挂掉,会自动启动新容器,而不是继续重启容器服务。 数据库利用中间件和容器化系统能够自动伸缩、容灾、切换、自带多个节点,也是可以进行容器化的。