The proposed solution does not work for my system:
cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.3 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.3 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
Kernel info:
uname -a
Linux c3p0 4.10.0-28-generic #32~16.04.2-Ubuntu SMP Thu Jul 20 10:19:48 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
(FYI: This is running as a VM in Virtualbox (5.2.8 r121009 Qt5.6.2). The host is Windows 10 Enterprise.)
Docker details:
docker --version
Docker version 17.12.0-ce, build c97c6d6
docker info
Containers: 6
Running: 0
Paused: 0
Stopped: 6
Images: 16
Server Version: 17.12.0-ce
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 89623f28b87a6004d4b785663257362d1658a729
runc version: b2567b37d7b75eb4cf325b77297b140ea686ce8f
init version: 949e6fa
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 4.10.0-28-generic
Operating System: Ubuntu 16.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 3.857GiB
Name: c3p0
ID: ID7G:ZMDK:2VKT:HCIN:6MMT:7PI5:Z7DV:JJL2:QOFU:PZ3T:MQQ4:3YBO
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: No swap limit support
Here is the output:
docker build -t friendlyhello .
Sending build context to Docker daemon 5.12kB
Step 1/9 : FROM python:2.7-slim
---> 55d87c387a8c
Step 2/9 : ENV http_proxy http://proxy-chain.xxx.com:911/
---> Using cache
---> 2d1ddd1b37fc
Step 3/9 : ENV https_proxy http://proxy-chain.xxx.com:912/
---> Using cache
---> fdd11fdeb3bf
Step 4/9 : WORKDIR /app
---> Using cache
---> bf6b0f413e21
Step 5/9 : ADD . /app
---> Using cache
---> c1bd11eec254
Step 6/9 : RUN pip install --trusted-host pypi.python.org -r requirements.txt
---> Running in ab5a093344d0
Collecting Flask (from -r requirements.txt (line 1))
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError(': Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))': /simple/flask/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError(': Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))': /simple/flask/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError(': Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))': /simple/flask/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError(': Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))': /simple/flask/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError(': Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))': /simple/flask/
Could not find a version that satisfies the requirement Flask (from -r requirements.txt (line 1)) (from versions: )
No matching distribution found for Flask (from -r requirements.txt (line 1))
The command '/bin/sh -c pip install --trusted-host pypi.python.org -r requirements.txt' returned a non-zero code: 1
Dockerfile:
# Use an official Python runtime as a parent image
FROM python:2.7-slim
ENV http_proxy http://proxy-chain.xxx.com:911/
ENV https_proxy http://proxy-chain.xxx.com:912/
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /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"]
requirements.txt file:
Flask
Redis
app.py file:
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 = "cannot connect to Redis, counter disabled"
html = "Hello {name}!
" \
"Hostname: {hostname}
" \
"Visits: {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)