2017-10-03 2 views
0

Ich habe diese Codes in meiner Dockerfile.Datei nicht gefunden von Dockerfile, docker-compose

FROM python:3 

# Create user named "airport". 
RUN adduser --disabled-password --gecos "" airport 

# Login as the newly created "airport" user. 
RUN su - airport 

# Change working directory. 
WORKDIR /home/airport/mount_point/ 

# Install Python packages at system-wide level. 
RUN pip install -r requirements.txt 

# Make sure to migrate all static files to the root of the project. 
RUN python manage.py collectstatic --noinput 

# This utility.sh script is used to reset the project environment. This includes 
# removing unecessary .pyc and __pycache__ folders. This is optional and not 
# necessary, I just prefer to have my environment clean before Docking. 
RUN utility_scripts/utility.sh 

Wenn ich rief docker-compose build es gibt /bin/sh: 1: requirements.txt: not found. Obwohl ich das notwendige Volumen in meinem docker-compose.yml geladen habe. Ich bin sicher, dass requirements.txt in ./ ist

web: 
    build: 
     context: ./ 
     dockerfile: Dockerfile 
    command: /home/airport/mount_point/start_web.sh 
    container_name: django_airport 
    expose: 
     - "8080" 
    volumes: 
     - ./:/home/airport/mount_point/ 
     - ./timezone:/etc/timezone 

Wie kann ich dieses Problem lösen?

Antwort

0

Bevor Sie RUN pip install -r requirements.txt ausführen, müssen Sie dem Image die Datei "requirements.txt" hinzufügen.

... 
ADD requirements.txt requirements.txt 

RUN pip install -r requirements.txt 
... 

Für eine Probe, wie eine django Anwendung dockerize, überprüfen https://docs.docker.com/compose/django/. Sie müssen die Anforderung.txt und den Code zum Bild hinzufügen.

+0

Kann ich stattdessen ein Volume mounten? Weil ich 'RUN python manage.py collectstatic --noinput' habe, das an meinem Django-Projekt funktioniert. Ich habe versucht, 'VOLUME [" ./ "]' zu benutzen, aber es gab mir, 'container_linux.go: 265: Start-Container-Prozess verursacht" process_linux.go: 368: container init verursacht "apparmor konnte Profil nicht anwenden: keine solche Datei oder Verzeichnis \ "' stattdessen. Zusätzlich wird die 'ADD'ed requirements.txt persistent nach dem Container-Setup? – notalentgeek

+0

@ AndrewGraham-Youll Montage ein Volume wird in Ihrem Fall nicht funktionieren, da thet pip install Befehl ausgeführt wird, wenn das Bild und Volumes zu erstellen Wenn Sie das Image ausführen, müssen Sie Ihre Projektquellen hinzufügen, sonst sind sie im Image nicht verfügbar und der Build schlägt fehl – yamenk

+0

@yamenk Ah yep, Sie haben recht. Mein Kommentar wurde entfernt Die App wird im Container erstellt und die requirements.txt wird benötigt, sie muss von Anfang an da sein. " –

Verwandte Themen