linux - 如何使用 CoreOS 的云配置文件启动 Docker 容器?

标签 linux mongodb docker coreos

我正在尝试使用 Terraform 配置我的 CoreOS 服务器,使用 cloud-config file for CoreOS .我目前正在尝试在 Docker 容器中设置 Mongo 数据库。 这是我的配置文件:

write_files:
  - path: "/home/core/keyfile"
  permissions: "0600"
  owner: "999"
  content: |
    hUoQVrERB0*** <here is my key for MongoDB>

coreos:
  units:
    - name: "dockerstart.service"
      command: "start"
      content: |
        [Unit]
        Description=Start
        Author=Me

        [Service]
        Restart=always
        ExecStart=/usr/bin/docker run --name mongo -v /home/core:/opt --add-host node1.example.com:127.0.0.1 -p 27017:27017 -d mongo:2.6.5 --smallfiles --keyFile /opt/keyfile --replSet "rs0"
        ExecStop=/usr/bin/docker rm -f mongo

我不确定如何使用 coreOS units(当我通过 ssh 进入服务器时,docker 容器没有运行,所以配置文件不正确)。根据CoreOS Validator ,我的文件有效。另外,我不确定这是否是部署 MongoDB 服务器的最简单方法。 如何正确使用 CoreOS units?关于改进 Mongo 数据库部署方式的任何想法?

感谢任何帮助、意见和建议!

最佳答案

我终于找到了解决方案。

实际运行带有 -d 选项的 docker run 会守护命令。因此,当 systemd 发现此操作在后台运行时,它认为 Docker 正在崩溃。

这是服务器上的 journalctl -u dockerstart.service 结果:

docker[1237]: ace3978442a729420ecb87af224bd146ec6ac7912c5cc452570735f4a3be3a79
docker[1297]: mongo
systemd[1]: dockerstart.service: Service hold-off time over, scheduling restart.
systemd[1]: Stopped Start.
systemd[1]: Started Start.

这里可以清楚的看到systemd停止并重启了Start服务。

因此解决方案可能是docker run 命令中删除 -d

关于linux - 如何使用 CoreOS 的云配置文件启动 Docker 容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39877548/

相关文章:

linux - 读取文件后如何从文件中删除行?

mongodb - Mongoose :保存为子文档的关联数组与子文档数组

linux - 如果死了就开始进程

linux - 查找键盘、鼠标的事件设备

c - glibc中哪个函数调用了main函数

django - django cms filer上传失败

javascript - 在 apache 或 aws 上使用 docker 部署 React 构建

Spring-Mongo : mapping mongo document field/s to BasicDBObject/Map of BasicDBObject of an Entity

MongoDB 3.6.2 $out 因重复键错误而失败

docker - 从Kubernetes日志中提取行