2015-12-21 6 views
9

Ich möchte die mongoDB Daten außerhalb des Containers und auf einem bestimmten Volume beibehalten. Ich bin mit Docker-compose und die yml Datei sieht aus wieWie man externes Volume für mongoDB mit docker-compose und docker-machine einbindet

web: 
    build: . 
    command: python -u app.py 
    ports: 
    - "5000:5000" 
    volumes: 
    - .:/todo 
    links: 
    - db 
db: 
    image: mongo:3.0.2 
+0

Welche Version laufen? Sieht so aus als könnte es 2 sein. Ich suche Informationen zu Version 3. – Dagrooms

+0

@Dagrooms: hast du es gefunden? Ich habe versucht, aber die Daten bleiben nicht auf dem Host –

Antwort

6

Wie für das Bild auf der Docker Hub-Seite dokumentiert (https://hub.docker.com/_/mongo/) können Sie

volumes: 
    - './data:/data/db' 

verwenden, die den Host-Pfad verwenden ./data

+0

Ich habe dieses '' 'web: build:. Befehl: python -u app.py Ports: - "5000: 5000" Band: -./Todo Links: - db db: Bild: Mongo: 3.0.2 Band: - ./data:/data/db''', aber der Mongo-Container startet nicht und es scheint, dass er beschwert, dass er keine Schreibberechtigung für den ./data-Ordner hat. es sagt: ** 2015-12-27T06: 55: 19.002 + 0000 Ich STORAGE [initandlisten] Ausnahme in initAndListen: 98 Kann Sperrdatei nicht erstellen/öffnen: /data/db/mongod.lock errno: 13 Berechtigung verweigert Ist ein Mongod Instanz läuft bereits ?, beendet ** ich bin nicht sicher, was das Problem ist – casra

+0

Das Problem ist die Dateiberechtigungen. Mongo läuft wahrscheinlich als Mongo-Benutzer, der nicht die gleichen Berechtigungen wie Ihr Benutzer hat. – dnephin

+0

aber die ** /data/db/mongod.lock**** ist im Container, nicht auf meinem Host-Rechner. Doesnt this ** volumes: - ./data./data/db* bedeutet das **/data/db ** des Containers wird gleich sein wie ** ./data ** des Host-Rechners? – casra

7

Ich nehme an, Sie versuchen, den Container auf einem OSX-System wie mir zu starten? Das Volume-Verzeichnis des Host-Computers kann nicht unter/Users (oder ~) liegen, wie Joshuajabbour angibt here.

Versuchen zum Beispiel

volumes: 
    - /usr/local/mongodb:/todo 
0
#Mongo Dockerfile 
FROM alpine:edge 

MAINTAINER "loko" <[email protected]> 

# proxy settings 
ARG http_proxy=http://your-corporate-proxy-if-is-need-it/ 
ARG https_proxy=http://your-corporate-proxy-if-is-need-it/ 
ARG no_proxy=localhost,127.0.0.0/8,::1,15.0.0.0/8,16.0.0.0/8 

ADD run/
ADD dosu /sbin/ 

RUN chmod +x /sbin/dosu && \ 
    echo http://dl-4.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories && \ 
    apk add --no-cache mongodb 

VOLUME /data/db 
EXPOSE 27017 28017 

ENTRYPOINT [ "/run" ] 
CMD [ "mongod" ] 

# Docker Compose

version: '2.0' 

volumes: 
    data: 
    external: 
     name: "the-volume-name-you-want 
services: 
    web: 
     build: 
     context: . 
     dockerfile: "Dockerfile" 
     args: 
      - HTTP_PROXY 
      - HTTPS_PROXY 
      - http_proxy 
      - https_proxy 
      - no_proxy 
      - NO_PROXY 
     image: "docker-hub-OR-your-built-image-name" 
     environment: 
      - http_proxy=$http_proxy 
      - https_proxy=$https_proxy 
      - no_proxy=$no_proxy 
      - HTTP_PROXY=$HTTP_PROXY 
      - HTTPS_PROXY=$HTTPS_PROXY 
      - NO_PROXY=$NO_PROXY 
     ports: 
     - "8080" 
     restart: always 
     depends_on: 
     - mongo 
    mongo: 
     image: "your-favorite-mongodb-image-name" 
     environment: 
      - http_proxy=$http_proxy 
      - https_proxy=$https_proxy 
      - no_proxy=$no_proxy 
      - HTTP_PROXY=$HTTP_PROXY 
      - HTTPS_PROXY=$HTTPS_PROXY 
      - NO_PROXY=$NO_PROXY 
     restart: always 
     volumes: 
     - data:/data/db 

bauen und

docker-compose build . 
docker-compose up