Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 185860
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 10, 20222022-06-10T08:31:33+00:00 2022-06-10T08:31:33+00:00

python – During docker build “socket.gaierror: [Errno -2] Name or service not known” – RabbitMQ Connection

  • 0

[ad_1]

Good morning,

I am facing a weird issue during the composing of my RabbitMQ container.

When I build the container without my python script, which creates the test structure of my RabbitMQ, it works fine. I access the container, run the script manually, and everything gets created perfectly, with no errors.

If I run the script with the same command (“python3 manager.py”), but in a RUN entry at the Dockerfile, it’s like it is suddenly unable to find the hostname or something like that during the RabbitMQ connector creation. So, it aborts the creation of the container.

I have tried executing it as a background Linux process, and the container is created, but the RabbitMQ structure creation keeps failing.

Docker-compose

version: "3.8"
services:
  rabbitmq:
    container_name: rabbitmq
    image: rabbitmq
    build: src/server/
    env_file:
      - src/server/server.env
    ports:
      - "15672:15672"
      - "5672:5672"
    hostname: rabbitmq
    networks:
      - rabbitmqnet

networks:
  rabbitmqnet:
    name: rabbitmqnet
    driver: bridge

Dockerfile

FROM rabbitmq:3-management
WORKDIR /app
EXPOSE 15672
COPY . /app
RUN apt-get update -y
RUN apt-get install -y python python3-pip
RUN pip install -r requirements.txt
RUN python3 manager.py

manager.py

import pika
import config

connection = pika.BlockingConnection(pika.ConnectionParameters(config.server, config.port, "https://stackoverflow.com/", pika.PlainCredentials(config.user, config.password)))
channel = connection.channel()

def main():
    createQueue("test-queue")
    createExchange("test-exchange")
    createBinding("test-exchange", "test-queue", "test")

# This method creates a queue.
def createQueue(qName):
    channel.queue_declare(queue=qName)

# This method creates an exchange.
def createExchange(eName):
    channel.exchange_declare(
        exchange=eName, 
        exchange_type="direct"
        )

# This method creates a binding routing key between an exchange and a queue. This allows the publisher to send messages to the queue through the exchange.
def createBinding(eName, qName, routingKey):
    channel.queue_bind(
        exchange=eName, 
        queue=qName, 
        routing_key=routingKey
        )

if __name__ == "__main__":
    main()

config.py

server="rabbitmq"
port= 5672
user="user"
password= 'password'

[ad_2]

  • 0 0 Answers
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 325 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 295 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 292 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.