安装docker-compose

https://docs.docker.com/compose/install/

  1. $ curl -L https://github.com/docker/compose/releases/download/1.8.0/run.sh > /usr/local/bin/docker-compose
  2. $ chmod +x /usr/local/bin/docker-compose$ docker-compose --version
  3. [root@localhost ~]# curl -L https://github.com/docker/compose/releases/download/1.8.0/run.sh > /usr/local/bin/docker-compose
  4. % Total % Received % Xferd Average Speed Time Time Time Current
  5. Dload Upload Total Spent Left Speed
  6. 100 596 100 596 0 0 593 0 0:00:01 0:00:01 --:--:-- 593
  7. 100 1400 100 1400 0 0 551 0 0:00:02 0:00:02 --:--:-- 1348
  8. [root@localhost ~]# chmod +x /usr/local/bin/docker-compose
  9. [root@localhost ~]# docker-compose --version
  10. Unable to find image 'docker/compose:1.8.0' locally
  11. Trying to pull repository docker.io/docker/compose ...
  12. 1.8.0: Pulling from docker.io/docker/compose
  13. e110a4a17941: Pull complete
  14. 92120570534d: Pull complete
  15. 47d26c525b40: Pull complete
  16. 40a1d6f501ac: Pull complete
  17. 643031e197d8: Pull complete
  18. 0841ec069338: Pull complete
  19. Digest: sha256:9bb1d2f141b4511b52dac37e5ea0aecadaf7786bc47184c133c566a4f678061d
  20. Status: Downloaded newer image for docker.io/docker/compose:1.8.0
  21. docker-compose version 1.8.0, build f3628c7
  22. [root@localhost ~]#

创建/home/mongotest目录。
通过创建docker-compose.yml文件:

  1. version: "2"
  2. services:
  3. mongo:
  4. image: mongo
  5. restart: always
  6. environment:
  7. MONGO_INITDB_ROOT_USERNAME: root
  8. MONGO_INITDB_ROOT_PASSWORD: example
  9. ports:
  10. - 27016:27017
  11. volumes:
  12. - /home/mongotest:/data/db

然后执行docker-compose命令:

  1. docker-compose up -d

推荐阅读