Search code examples
pythondockerdocker-composedockerfiledocker-stack

View Docker Swarm CMD Line Output


I am trying to incorporate a python container and a dynamodb container into one stack file to experiment with Docker swarm. I have done tutorials on docker swarm seeing web apps running across multiple nodes before but never built anything independently. I am able to run docker-compose up with no issues, but struggling with swarm.

My docker-compose.yml looks like

version: '3.3'
services:
  dynamodb:
    image: "amazon/dynamodb-local"
    ports:
      - "8000:8000"
  track-count:
    image: "my-app"
    links:
      - "dynamodb:localhost"

Running docker stack deploy -c docker-compose.yml trial_stack brings up no errors however printing 'hello world' as the first line of python code is not displayed in the terminal. I get the following as CMD line output

Ignoring unsupported options: links

Creating network trial_stack_default
Creating service trial_stack_dynamodb
Creating service trial_stack_track-count

My question is:

1) Why is the deploy service ignoring the links? I have noticed this is repeated in the docs https://docs.docker.com/engine/reference/commandline/stack_deploy/ but unsure if this will cause my stack to fail.

2) Assuming the links issue is fixed, where will any command line output be shown, to confirm the system is running? Currently I only have one node, my local machine, which is the manager.

For reference, my python image is being built by the following Dockerfile:

FROM python:3.8-slim-buster

RUN mkdir /app
WORKDIR /app

RUN pip install --upgrade pip
COPY ./requirements.txt ./
RUN pip install -r ./requirements.txt

COPY / /
COPY /resources/secrets.py /resources/secrets.py

CMD [ "python", "/main.py" ]

Solution

  • You can update docker-compose.yaml to enable tty for the services for which you want to see the stdout on console.

    Updated docker-compose.yaml should look like this:

    version: '3.3'
    services:
      dynamodb:
        image: "amazon/dynamodb-local"
        ports:
          - "8000:8000"
      track-count:
        image: "my-app"
        tty: true
        links:
          - "dynamodb:localhost"
    

    and then when once you have the task deployed, to check service logs you can run:

    # get the service name
    docker stack services <STACK_NAME>
    
    # display the service logs, edited based on user's suggestion
    docker service logs --follow --raw <SERVICE_NAME>