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

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

问题描述

我已经在ubuntu 14.04上的portssh上安装了mongodb和docksh。容器正在运行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

另外开始mongod 不影响任何东西。

试图看这个也 Mongo守护进程无法通过服务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没有像您习惯于传统系统的init系统。什么码头工作是使用您在 中指定的过程替换 PID 1 CMD ENTRYPOINT Dockerfile命令。现在,忽略 ENTRYPOINT ,因为它取代了您的 CMD 的运行方式(通常是 / bin / sh -c )。您需要指示码头工具在您的Docker文件中使用 CMD 命令启动您的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等)都被取消了最佳做法在您的容器上:

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

这将把你放在运行容器的shell中。这里关于管理Docker容器的配置和更改的建议是使用像Ansible这样的东西。但是,请记住,docker容器是短暂的,您不应该重新启动服务并更改配置状态。如果需要配置更改,请更改Docker文件或配置数据,然后启动新的容器。祝你好运! 此处有关Dockerizing MongoDB的更多信息,但请记住,此处所述的方法会更改<$ c $在Docker文件中,c> ENTRYPOINT ,这是一个更多的参与,需要更好地了解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天全站免登陆