mongo带web_ip6访问

初始化脚本

sysctl net.ipv6.bindv6only=0
sysctl net.ipv6.conf.default.forwarding=1
sysctl net.ipv6.conf.all.forwarding=1


vi /etc/docker/daemon.json

{
  "ipv6": true,
  "fixed-cidr-v6": "2001:db8:1::/64"
}

Save the file.
Reload the Docker configuration file.

$ systemctl reload docker

docker volume rm mongodata
docker volume rm mongoclientdata


docker volume create --name=mongodata
docker volume create --name=mongoclientdata

docker network create -d bridge --ipv6 --subnet "2001:db8:10::/64" --gateway="2001:db8:10::1" --subnet=172.30.10.0/24 mynet

docker run -it    --net=mynet  --ip=172.30.10.10  --privileged=true    -v  mongodata:/data/db -p 27017:27017 --name mongodb1 -d  --restart=always   mongo  --ipv6 --bind_ip_all  --auth 



docker exec -it mongodb1  mongo admin

db.enableFreeMonitoring()

db.createUser(
  {
    user: "root",
    pwd: "830698db-aeff-4323-89e9-8c9d03f70ad9",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
  }
)


docker logs mongodb1


docker run -d  --net=mynet  --ip=172.30.10.11  -p 27000:3000 -e BIND_IP="::"   -e MONGO_URL="mongodb://root:[email protected]:27017"  -v   mongoclientdata:/data/db  --name=mongoclient1  --restart=always  mongoclient/mongoclient


# other client 另一种 风格的 web控制台 ,没有第一种好看
docker run -d --net=mynet --ip=172.30.10.12  -e VCAP_APP_HOST="::" -e ME_CONFIG_MONGODB_SERVER="172.30.10.10"  -e ME_CONFIG_MONGODB_ADMINUSERNAME="root" -e ME_CONFIG_MONGODB_ADMINPASSWORD="830698db-aeff-4323-89e9-8c9d03f70ad9" -p 27001:8081 --restart=always --name=mongoexpress mongo-express

db.system.users.find().pretty()

mongo auth

Authentication Methods
To authenticate as a user, you must provide a username, password, and the authentication database associated with that user.

To authenticate using the mongo shell, either:

Use the mongo command-line authentication options (--username, --password, and --authenticationDatabase) when connecting to the mongod or mongos instance, or

参数讲解

# 怎么发现 这些 官网没有的 环境变量的呢, 通过 简单 观察 源代码 发现的。
# 监听 ip6
-e VCAP_APP_HOST="::" 

# 不同于 mongoclint 监听 
-e ME_CONFIG_MONGODB_SERVER="172.30.10.10"

socat 端口转发

socat TCP6-LISTEN:8082,reuseaddr,fork TCP4:127.0.0.1:8081

# 杀死 所有 端口转发
ps -aux | grep socat | grep -v grep | awk '{print $2}' | xargs kill -9

web 见面参数配置

https://hub.docker.com/_/mongo-express

To fix the problem, use the -s option or set the environment variable TINI_SUBREAPER to register Tini as a child subreaper, or run Tini as PID 1.

docker run -it --net=mynet --ip=172.30.10.11 -e VCAP_APP_HOST="::" -e ME_CONFIG_MONGODB_SERVER="172.30.10.10" -p 8081:8081 mongo-express 


WORKDIR /app

COPY . /app

RUN cp config.default.js config.js

RUN set -x \
    && apt-get update && apt-get install -y git --no-install-recommends \
    && npm install \
    && apt-get purge --auto-remove -y git \
    && rm -rf /var/lib/apt/lists/*

RUN npm run build

CMD ["tini", "--", "npm", "start"]

你可能感兴趣的:(dockermongodb)