Search code examples
dockerdockerfilepodman

How to enable port bindings on rootless containers?


I have a flask application running on Ec-2 instance. I could access it from the outside environment with http:ip-address:5000 where IP-address is the public address of my ec-2 instance.

My flask application code:

from flask import Flask

app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def my_form_post():
    return "Hello World"

if __name__ == '__main__':
    app.run(host="my-ec2-private-address", port=5000, debug=True)

I dockerized the flask application using the following Dockerfile:

FROM python:2.7
MAINTAINER noob-reaper
COPY . /Mini
WORKDIR /Mini
RUN pip install -r requirements.txt
EXPOSE 5000
CMD python miniRobot.py

My build command was : docker build -t robot . The build was successful. But when I try to run using the following command: docker run -p 5000:5000 robot
I get the following error--- port bindings are not yet supported by rootless containers

How to resolve the above issue? Is there a way to access flask service running in a Docker container in an ec-2 instance from outside?


Solution

  • Using sudo while building docker images and running docker container resolved this issue. sudo helps to run non-root containers