- 使用docker-compose 构建,然后可以在8081端口看到mongo-express
version: '3.1'
services:
mongo_test:
image: mongo
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
volumes:
- "/home/hadoop/dockerFile/mongoDb/data:/data/db"
mongo-express_test:
image: mongo-express
restart: always
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: example
links:
- mongo_test:mongo
- 启动:
docker-compose -f stack.yml up -d
这时查看docker 日志会发现
$ docker logs mongodb_mongo_test_1
Permission denied
修改权限:
具体看:
https://blog.csdn.net/rznice/article/details/52170085
临时修改:
$ sudo setenforce 0
重新启动:
docker-compose -f stack.yml up -d
启动成功登录docker的container
docker ps
查看docker container 列表
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a363f438f7e2 mongo "docker-entrypoint..." About an hour ago Up 12 minutes 27017/tcp mongodb_mongo_test_1
bd041fce506c mongo-express "tini -- node app" About an hour ago Up 10 seconds 0.0.0.0:8081->8081/tcp mongodb_mongo-express_test_1
- 登录mongodb_mongo_test_1 容器
docker exec -it mongodb_mongo_test_1 bash
-
mongo -u root -p example --authenticationDatabase admin
登录 mongoDB完成.
- 使用容器登录:
docker run -it --rm --link mongodb_mongo_test_1:mongo --net mongodb_default mongo mongo --host mongo -u root -p example --authenticationDatabase admin test
总结
其中会遇到两个问题:
挂载目录权限问题
解决办法 : https://blog.csdn.net/rznice/article/details/52170085第七步如果不加
--net mongodb_default
会报
/usr/bin/docker-current: Error response from daemon: Cannot link to /mongodb_mongo_test_1, as it does not belong to the default network.