Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error docker run from Dockerfile #20

Open
pablorcruh opened this issue Jun 18, 2017 · 3 comments
Open

Error docker run from Dockerfile #20

pablorcruh opened this issue Jun 18, 2017 · 3 comments

Comments

@pablorcruh
Copy link

I have an error running docker container, i don't have much experience using Docker and redis that is why i open this issue to ask for help

Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/redis/connection.py", line 439, in connect
sock = self._connect()
File "/usr/local/lib/python3.5/site-packages/redis/connection.py", line 464, in _connect
socket.SOCK_STREAM):
File "/usr/local/lib/python3.5/socket.py", line 733, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/redis/client.py", line 572, in execute_command
connection.send_command(*args)
File "/usr/local/lib/python3.5/site-packages/redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File "/usr/local/lib/python3.5/site-packages/redis/connection.py", line 538, in send_packed_command
self.connect()
File "/usr/local/lib/python3.5/site-packages/redis/connection.py", line 442, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error -2 connecting to redis:6379. Name or service not known.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/redis/connection.py", line 439, in connect
sock = self._connect()
File "/usr/local/lib/python3.5/site-packages/redis/connection.py", line 464, in _connect
socket.SOCK_STREAM):
File "/usr/local/lib/python3.5/socket.py", line 733, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "app.py", line 7, in
cache.set(default_key, "one")
File "/usr/local/lib/python3.5/site-packages/redis/client.py", line 1072, in set
return self.execute_command('SET', *pieces)
File "/usr/local/lib/python3.5/site-packages/redis/client.py", line 578, in execute_command
connection.send_command(*args)
File "/usr/local/lib/python3.5/site-packages/redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File "/usr/local/lib/python3.5/site-packages/redis/connection.py", line 538, in send_packed_command
self.connect()
File "/usr/local/lib/python3.5/site-packages/redis/connection.py", line 442, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error -2 connecting to redis:6379. Name or service not known.

@pablorcruh
Copy link
Author

This error is because we need to link the container running the app with a redis container

@awsdevopro
Copy link

screenshot from 2017-11-08 14-31-13
screenshot from 2017-11-08 15-21-50

I have attached the screenshots and three files as suggested

template has

<title>key value lookup service</title>

app.py contains


from flask import Flask, request, render_template
app = Flask(name)
default_key = '1'
cache = {default_key: "one"}

@app.route('/', methods=['GET', 'POST'])
def mainpage():

key = default_key
if 'key' in request.form:
key = request.form['key']

if request.method == 'POST' and request.form['submit'] == 'save':
cache.set(key, request.form['cache_value'])

cache_value = None;
if cache.get(key):
cache_value = cache.get(key).decode('utf-8')

return render_template('index.html', key=key, cache_value=cache_value)

if name == 'main':
app.run(host='0.0.0.0')


Dockerfile contains


FROM python:3.5
RUN pip install Flask==0.11.1
RUN useradd -ms /bin/bash admin
USER admin
COPY app /app
WORKDIR /app
CMD ["python", "app.py"]

When I go to the browser and hit my localhost which is 192.168.0.101:5000, it says

"The Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application."

What is the solution?

@Davidrjx
Copy link

Davidrjx commented Aug 9, 2019

@pablorcruh any solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants