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. 
  • Did you pre-install pip and / or the python itself? What is your dockerfile? - VTT
  • The python is installed, "What is your docker-file" means that inside it? (I execute all commands in powershell) - Isaac Asimov
  • Of course. It was necessary to bring its contents immediately. Especially the part where you put the python (well, or where it comes from in your image), or the "Name" pip "is not recognized as the name of the cmdlet" suggests that the python is not installed. - VTT
  • Now the image of the assembly is not created - Isaac Asimov

1 answer 1

On the first question - install pip in the container:

 RUN apt-get update -y RUN apt-get install -y php5-mcrypt python-pip 

This is in case your image is installed on Ubuntu. If not, the appropriate package manager should be used.

Unable to prepare context: Unable to prepare the symlinks in the Dockerfile path: GetFileAttributesEx C: \ docker \ Dockerfile:

Check that the Dockerfile is in the current directory. And the file should be called that way - with a capital letter.

If the file is called differently, you can:

 docker build -t friendlyhello -f ./Dockerfile.txt .