Skip to content

Error docker run from Dockerfile #20

Open

Description

@pablorcruh

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.

Activity

  1. pablorcruh commented on Jun 18, 2017

    @pablorcruh
    Author

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

  2. awsdevopro commented on Nov 8, 2017

    @awsdevopro

    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?

  3. Davidrjx commented on Aug 9, 2019

    @Davidrjx

    @pablorcruh any solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions