Going through docker introduction: https://docs.docker.com/get-started/part2/#dockerfile ). Trying to build a docker image, there are 3 files:
- dockerfile;
- requirements.txt;
- app.py;
Contents of dockerfile:
#Use an official Python runtime as a parent image FROM python:2.7-slim # Set the working directory to /app WORKDIR /app # Copy the current directory contents into the container at /app COPY . /app # Install any needed packages specified in requirements.txt RUN pip install --trusted-host pypi.python.org -r requirements.txt # Make port 80 available to the world outside this container EXPOSE 80 # Define environment variable ENV NAME World # Run app.py when the container launches CMD ["python", "app.py"] Content requirements:
Flask Redis Promotional app:
from flask import Flask from redis import Redis, RedisError import os import socket # Connect to Redis redis = Redis(host="redis", db=0, socket_connect_timeout=2, socket_timeout=2) app = Flask(__name__) @app.route("/") def hello(): try: visits = redis.incr("counter") except RedisError: visits = "<i>cannot connect to Redis, counter disabled</i>" html = "<h3>Hello {name}!</h3>" \ "<b>Hostname:</b> {hostname}<br/>" \ "<b>Visits:</b> {visits}" return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname(), visits=visits) if __name__ == "__main__": app.run(host='0.0.0.0', port=80) When trying to install the Flask and Redis libraries for Python with the pip install -r requirements.txt command
Gives out:
pip : ΠΠΌΡ "pip" Π½Π΅ ΡΠ°ΡΠΏΠΎΠ·Π½Π°Π½ΠΎ ΠΊΠ°ΠΊ ΠΈΠΌΡ ΠΊΠΎΠΌΠ°Π½Π΄Π»Π΅ΡΠ°, ΡΡΠ½ΠΊΡΠΈΠΈ, ΡΠ°ΠΉΠ»Π° ΡΡΠ΅Π½Π°ΡΠΈΡ ΠΈΠ»ΠΈ Π²ΡΠΏΠΎΠ»Π½ΡΠ΅ΠΌΠΎΠΉ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ. ΠΡΠΎΠ²Π΅ΡΡΡΠ΅ ΠΏΡΠ°Π²ΠΈΠ»ΡΠ½ΠΎΡΡΡ Π½Π°ΠΏΠΈΡΠ°Π½ΠΈΡ ΠΈΠΌΠ΅Π½ΠΈ, Π° ΡΠ°ΠΊΠΆΠ΅ Π½Π°Π»ΠΈΡΠΈΠ΅ ΠΈ ΠΏΡΠ°Π²ΠΈΠ»ΡΠ½ΠΎΡΡΡ ΠΏΡΡΠΈ, ΠΏΠΎΡΠ»Π΅ ΡΠ΅Π³ΠΎ ΠΏΠΎΠ²ΡΠΎΡΠΈΡΠ΅ ΠΏΠΎΠΏΡΡΠΊΡ. ΡΡΡΠΎΠΊΠ°:1 Π·Π½Π°ΠΊ:1 + pip install -r requirements.txt + ~~~ + CategoryInfo : ObjectNotFound: (pip:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
Now the problem is as follows: With the docker build --tag=friendlyhello . .Gives an error message :
unable to prepare context: unable to evaluate symlinks in Dockerfile path: GetFileAttributesEx C:\docker\Dockerfile: The system cannot find the file specified.