安装docker-compose
https://docs.docker.com/compose/install/
$ curl -L https://github.com/docker/compose/releases/download/1.8.0/run.sh > /usr/local/bin/docker-compose
$ chmod +x /usr/local/bin/docker-compose$ docker-compose --version
[root@localhost ~]# curl -L https://github.com/docker/compose/releases/download/1.8.0/run.sh > /usr/local/bin/docker-compose
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 596 100 596 0 0 593 0 0:00:01 0:00:01 --:--:-- 593
100 1400 100 1400 0 0 551 0 0:00:02 0:00:02 --:--:-- 1348
[root@localhost ~]# chmod +x /usr/local/bin/docker-compose
[root@localhost ~]# docker-compose --version
Unable to find image 'docker/compose:1.8.0' locally
Trying to pull repository docker.io/docker/compose ...
1.8.0: Pulling from docker.io/docker/compose
e110a4a17941: Pull complete
92120570534d: Pull complete
47d26c525b40: Pull complete
40a1d6f501ac: Pull complete
643031e197d8: Pull complete
0841ec069338: Pull complete
Digest: sha256:9bb1d2f141b4511b52dac37e5ea0aecadaf7786bc47184c133c566a4f678061d
Status: Downloaded newer image for docker.io/docker/compose:1.8.0
docker-compose version 1.8.0, build f3628c7
[root@localhost ~]#
创建/home/mongotest目录。
通过创建docker-compose.yml文件:
version: "2"
services:
mongo:
image: mongo
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
ports:
- 27016:27017
volumes:
- /home/mongotest:/data/db
然后执行docker-compose命令:
docker-compose up -d