通过 ssh 启动时 Docker 容器 mongod 错误 [英] Docker container mongod error when starting via ssh

查看:41
本文介绍了通过 ssh 启动时 Docker 容器 mongod 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 docker 容器上安装了 mongodb,并在 ubuntu 14.04 上安装了 openssh.容器使用 ssh 运行,但是当我 ssh 进入容器时,尝试启动 mongod 时出现以下错误.

I have installed mongodb on a docker container together with openssh on ubuntu 14.04. The container is running with ssh but when I ssh into the container I get the following error when trying to start mongod.

root@430f9502ba2d:~# service mongod start
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mongod start

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start mongod

另外 start mongod 不会影响任何东西.

Also start mongod does not affect anything.

也试过查看这个 Mongo 守护进程没有't 由 service mongod start 运行 没有它的帮助.

Tried looking at this also Mongo daemon doesn't run by service mongod start without it helping.

mongod --config/your/path/to/mongod.conf 似乎也不起作用,只是锁定.

mongod --config /your/path/to/mongod.conf doesn't seem to work also, just locks up.

以下错误是标准错误,当然没有运行 mongod 服务器.

The error below is standard as of course there is no mongod server running.

root@430f9502ba2d:/# mongo
MongoDB shell version: 2.6.9
connecting to: test
2015-05-07T20:49:56.213+0000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-05-07T20:49:56.214+0000 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed

推荐答案

这里的问题是你的方法.Docker 没有像您在传统系统上习惯的那样的初始化系统.docker 所做的是将 PID 1 替换为您在 CMDENTRYPOINT Dockerfile 命令.现在,忽略 ENTRYPOINT,因为它替换了运行 CMD 的内容(通常是 /bin/sh -c).您需要使用 CMD 命令指示 docker 在 Dockerfile 中启动 mongod 服务,例如:

The problem here is your approach. Docker does not have an init system like you are used to on traditional systems. What docker does is replace PID 1 with the process you specify in the CMD or ENTRYPOINT Dockerfile commands. For now, ignore ENTRYPOINT, because it replaces what your CMD is run with (normally, it's /bin/sh -c). You need to instruct docker to start your mongod service in your Dockerfile with the CMD command, like:

CMD usr/bin/mongod

当您运行容器时,mongod 将成为您的 PID 1.现在,您可能想知道但是我的 SSH 服务器呢?"答案是:不要在 docker 容器上运行 SSH 服务器. 有一些用例可以运行 SSH 服务器,但几乎所有正常"原因(调试、C&C 等)都因获取 shell 的最佳实践"而无效在您的容器上:

And when you run your container, mongod will be your PID 1. Now, you're probably wondering at this point "But what about my SSH server?" and the answer is: Don't run an SSH server on your docker containers. There are some use cases where running an SSH server is okay, but almost all of the "normal" reasons (debug, C&C, etc) are nullified with the "best practice" for getting a shell on your container:

docker exec -it myContainer/bin/bash

这会将您放入正在运行的容器的外壳中.此处用于管理 docker 容器中的配置和更改的建议是使用 Ansible 之类的东西.但是,请记住 docker 容器是短暂的,您不应该重新启动服务并更改它们的配置状态.如果您需要更改配置,请更改 Dockerfile 或配置数据,然后启动一个新容器.祝你好运!这里 是关于 Dockerizing MongoDB 的更多信息,但请记住,那里描述的方法会改变 ENTRYPOINT 在 Dockerfile 中,这涉及更多一点,需要更好地了解 Dockerfiles 中发生的事情.

This will drop you into a shell on your running container. The recommendation here for managing configuration and changes in your docker container is to use something like Ansible. However, remember that docker containers are ephemeral, and you shouldn't be restarting services and changing configuration state on them. If you need a config change, change the Dockerfile or config data, and then start a new container. Good luck! Here is a little more information on Dockerizing MongoDB, but keep in mind that the method described there alters the ENTRYPOINT in the Dockerfile, which is a little more involved and requires a better understanding of what's going on in Dockerfiles.

这篇关于通过 ssh 启动时 Docker 容器 mongod 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆