为什么这个docker-compose yml文件不执行此dockerfile中详细说明的命令?

I have two docker images: a producer and a RabbitMQ queue. My goal is to get the producer (Python) to spit entries into the queue. I then want to call docker-compose up and watch the producer add things to the queue.

Now, I'm not the brightest crayon in the box, and I'd really appreciate it if someone could point out for me why things aren't working as I intended. My producer is a simple 2 files in a ./producer directory. The dockerfile for this directory appears as so:

FROM ubuntu:latest

ENV DEBIAN_FRONTEND=noninteractive

# Prepare to install 3.7 + GDAL libraries
RUN apt-get update --fix-missing
RUN apt-get install -y software-properties-common apt-utils
RUN add-apt-repository ppa:ubuntugis/ppa
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt-get update --fix-missing

# Install the packages for GDAL
RUN apt-get install libgdal-dev gdal-bin -y
# Install the packages for python
RUN apt-get install python3.7 python3-pip python3.7-dev -y

RUN python3.7 -m pip install pika

COPY ./example.py example.py

CMD [ "/bin/bash", "-c \"python3.7 example.py\"" ]

I've been swapping out the last line with ENTRYPOINT, CMD, various versions of /bin/bash, python3, python3.7. Running docker build -t blah && docker run --rm blah produces the behavior I expect (Can't connect to the queue because it's not running exception).

In the directory that holds ./producer, I have a docker-compose.yml file that appears as so:

version: "3.3"
services:

  # RabbitMQ that connects the backend to the frontend
  queue:
    image: rabbitmq:3-management
    expose:
      # The standard AMQP protocol port
      - 5672
    ports:
      # HTTP management UI
      - '15672:15672'
    environment:
      RABBITMQ_DEFAULT_USER: "guest"
      RABBITMQ_DEFAULT_PASS: "guest"
    networks:
      rakan:
        ipv4_address: 172.16.238.10
    deploy:
      replicas: 1
      update_config:
        parallelism: 1
        delay: 10s
      restart_policy:
        condition: on-failure
        delay: 10s
        max_attempts: 3
        window: 120s
    healthcheck:
      test: [ "CMD", "nc", "-z", "localhost", "5672" ]
      interval: 5s
      timeout: 15s
      retries: 1


  producer:
    depends_on: 
      - queue
    build: 
      context: ./producer
      dockerfile: dockerfile
    # entrypoint: "/bin/bash -c \"python example.py\""
    expose:
      - "5672"
    networks:
      rakan:
        ipv4_address: 172.16.238.11
    links:
      - "queue"
    networks:
      - rakan

networks:
  rakan:
    ipam:
      driver: default
      config:
        - subnet: "172.16.238.0/24"

What is terribly frustrating, is that docker-compose up no longer executes the command in ./producer/dockerfile. It will start up the queue, but it will choose to ignore my desired commands, saying:

Attaching to toyexample_queue_1, toyexample_producer_1
toyexample_producer_1 exited with code 0
... All the logs of the RabbitMQ ...

Why oh why is this happening? Why isn't it behaving the same way when I executed docker run? Any help would be greatly appreciated.

我尝试过的事情:

  • Adding entrypoint to docker-compose.yml of the form python3.7 example.py, bin/bash python3.7 example.py, bash python example.py. All will terminate with error code 127, claiming that python or python3.7 is an unrecognized command.
  • Adding cmd to docker-compose.yml with the same exact results as the last bullet point
  • Swapping out CMD with ENTRYPOINT in the ./producer/dockerfile
  • Trying different variations of python, python3.7 in both docker-compose.yml and dockerfile.

我不知道的事情是相关的,但可能会有所帮助

  • I'm running docker v19.03.8 on windows 10 (AMD Ryzen CPU)
  • 0 other containers are running
  • docker-compose down, docker network/container/image prune are all commands I've tried numerous during this epic journey
  • The code in example.py is as so:
import pika

connection = pika.BlockingConnection(pika.ConnectionParameters('172.16.238.10'))
channel = connection.channel()

for i in range(100):
    # make a lot of noise
    channel.queue_declare(queue=f'hello_{i}')
    channel.basic_publish(exchange='',
                        routing_key='hello_{i}',
                        body='Hello World!')
    print(f" [x] Sent 'Hello World!' to {i}")

connection.close()
  • 强制性的:“这不是家庭作业,我不是在试图作弊,等等”