Docker Community Forums

Share and learn in the Docker community.

Can't See Ports When running docker-compose ps

Hello Everyone… I am using docker for the first time
And I am attempting to host a python script on a docker container from my windows 10 laptop
The issue is that… the container starts successfully, but when I run docker-compose ps I can’t see the ports I defined in the docker-compose file.

Here are my codes

Docker File:
FROM python:3.7-alpine



CMD [ "python", "./"  ]


version: "3.9"
      context: .
      dockerfile: Dockerfile.dockerfile
    - "80:80"

Python Script
import json as j, urllib.request

with urllib.request.urlopen("") as url:

    d = j.loads(

import xml.etree.cElementTree as e        

r = e.Element("Employee")

e.SubElement(r,"Name").text = d["Name"]

e.SubElement(r,"Designation").text = d["Designation"]

e.SubElement(r,"Salary").text = str(d["Salary"])

e.SubElement(r,"Age").text = str(d["Age"])

a = e.ElementTree(r)


Docker-compose output

   Name                Command         State    Ports
devopsproject_web_1   python ./   Exit 0

Please where is this issue coming from?

The state of the container should be “Up”, not “Exit”. A container needs a running service in the foreground to stay alive. If your script just runs one time and then exits the container will be stopped.

1 Like

Thank you very much, I modified my script to run a loop and verified your answer