远程链接docker容器中的mongodb

远程链接docker容器中的mongodb

在上篇文章中介绍了在服务器上部署sharelatex。sharelatex使用的数据库是mongodb,这里将介绍使用NoSQLBooster for MongoDB远程链接服务器上docker容器中的mongodb的方法。

0. Windows机下载安装 NoSQLBooster for MongoDB

官方下载地址

1.查看存在的容器:

docker ps

2.进入mongodb所在的容器

docker exec -it mongo bash

docker中没有安装任何文本编辑器,我们在这里安装vim

3.apt改源(注意版本,这里使用的Ubuntu16.04):

cd /etc/apt
echo "">sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse">>sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse">>sources.list
echo" deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse">>sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse">>sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse">>sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse">>sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse">>sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse">>sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse">>sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse">>sources.list

更新

apt update

可以看到下载源已经更换为阿里的镜像

4.安装vim

apt install vim

5.修改mongodb的配置文件

vim /etc/mongod.conf.orig

bindIp: 127.0.0.1修改为 bindIp: 0.0.0.0
保存退出

6.退出mongodb

exit

7.获取mongo容器的IP

cat /etc/hosts

这里mongo容器的IP为172.19.0.2

8.使用NoSQLBooster for MongoDB远程链接mongodb

  • 在服务器的安全组中添加27017端口(mongodb的默认端口)

打开NoSQLBooster,点击Connect,点击Create
远程链接docker容器中的mongodb_第1张图片

先通过ssh链接服务器
远程链接docker容器中的mongodb_第2张图片
之后链接docker中的mongodb,IP填写容器的IP
远程链接docker容器中的mongodb_第3张图片
保存并连接即可

你可能感兴趣的:(服务器相关)