windows 下的 docker-compose 并不在 linux 虚拟机上,需要先执行
eval "$(docker-machine env default)"
然后 docker-compose 可以在 windows 下 bash 执行。
docker-compose.yml
version: '2'
services:
mongodb:
image: bitnami/mongodb:latest
volumes:
- /mnt/src/docker-containers/wyrover-mongo/mongo-data:/bitnami/mongodb
在 windows 下 bash 运行
docker-compose up
这样,mongo 就在 linux 虚拟机上运行了一个 container。
完整过程
ROVER@ROVER-PC MINGW64 /H/docker_shared_folder/src/docker-containers/wyrover-mongo (master)
$ eval "$(docker-machine env default)"
ROVER@ROVER-PC MINGW64 /H/docker_shared_folder/src/docker-containers/wyrover-mongo (master)
$ docker-compose up
Creating network "wyrovermongo_default" with the default driver
Pulling mongodb (bitnami/mongodb:latest)...
latest: Pulling from bitnami/mongodb
Digest: sha256:e7c13aeb4c1f6b888c255a3583855f0fe49109dbe96595f5e320b78369c18093
Status: Downloaded newer image for bitnami/mongodb:latest
Creating wyrovermongo_mongodb_1
Attaching to wyrovermongo_mongodb_1
mongodb_1 | nami INFO Initializing mongodb
mongodb_1 | mongodb INFO
mongodb_1 | mongodb INFO ########################################################################
mongodb_1 | mongodb INFO Installation parameters for mongodb:
mongodb_1 | mongodb INFO Password: Not set during installation
mongodb_1 | mongodb INFO RootPassword: Not set during installation
mongodb_1 | mongodb INFO (Passwords are not shown for security reasons)
mongodb_1 | mongodb INFO ########################################################################
mongodb_1 | mongodb INFO
mongodb_1 | nami INFO mongodb successfully initialized
mongodb_1 | Starting application ...
mongodb_1 |
mongodb_1 | *** Welcome to the mongodb image ***
mongodb_1 | *** Brought to you by Bitnami ***
mongodb_1 | *** More information: https://github.com/bitnami/bitnami-docker-mongodb ***
mongodb_1 | *** Issues: https://github.com/bitnami/bitnami-docker-mongodb/issues ***
mongodb_1 |
mongodb_1 |
mongodb_1 | *** Your container is up to date! ***
注意
windows 下使用虚拟机装 docker 再装 mongo ,如果将 windows 文件目录挂载到 linux 主机再映射到 container ,会出现错误,暂找不到解决方法,不行就在 windows 上安装原生的 mongo,用 container 应用去连。