0

I'm learning how to use docker and got stuck on the following.

I have my flask app in /var/www/Skills The app tree is (I left out files under static/, templates/, tests/ and some pycache dirs):

.
├── config.py
├── docker-compose.yml
├── Dockerfile
├── package-lock.json
├── Pipfile
├── Pipfile.lock
├── README.md
├── requirements.txt
├── run.py
├── skills
│   ├── api
│   │   ├── errors.py
│   │   ├── __init__.py
│   │   ├── skills.py
│   │   └── validations.py
│   ├── auth
│   │   ├── emails.py
│   │   ├��─ __init__.py
│   │   ├── oauth.py
│   │   └── routes.py
│   ├── content
│   │   ├── forms.py
│   │   ├── __init__.py
│   │   └── routes.py
│   ├── errors
│   │   ├── handlers.py
│   │   └── __init__.py
│   ├── __init__.py
│   ├── main
│   │   ├── __init__.py
│   │   └── routes.py
│   ├── models.py
│   ├── static        
│   └── templates    
├── skills.db
└── tests

If I understand it correctly, I can put Dockerfile in the root dir of this project folder. The content of the file is as follows:

FROM python:3.7-alpine
WORKDIR /code
RUN apk add --no-cache gcc musl-dev linux-headers
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "run.py"]

That is basically what I got here: https://docs.docker.com/compose/gettingstarted/ I don't completely understand thit line RUN apk add --no-cache gcc musl-dev linux-headers, but otherwise I should copy requirements.txt from my current dir into the copy/ dir inside the docker image, the same with the rest (COPY . .).

Then I have docker-compose.yml:

version: '3'
services:
  skills:
    build: .
    ports:
      - "127.0.0.1:8080:8080"

It should build the image first based on the Dockerfile and then run and bind it to 127.0.0.1 and port 8080, and the last port (here again 8080) says what port is used inside the docker image.

When I run:

$ docker-compose up -d

it returns 0 and no error.

When I run:

$ docker ps -a

I can see my container running.

However, when I navigate to 127.0.0.1:8080, the page is loading forever and I never get any content.

I've also tried to run:

$ docker-compose up

, so I could see all output in the terminal. Again, I can see the python webserver is running on 0.0.0.0:8080 and ready to respond to requests.

skills_1  |  * Serving Flask app "skills" (lazy loading)
skills_1  |  * Environment: production
skills_1  |    WARNING: Do not use the development server in a production environment.
skills_1  |    Use a production WSGI server instead.
skills_1  |  * Debug mode: on
skills_1  |  * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)
skills_1  |  * Restarting with stat
skills_1  |  * Debugger is active!
skills_1  |  * Debugger PIN: 763-470-183

What I'm I doing wrong? It feels like this should be the easiest setup ever, I'm not using any other more robust webserver, so the configuration should be really easy here. But I just can't make it work.

I'm using docker 19.03.1-ce, docker-compose 1.24.1 if that is important to this problem.

Thank you

1 Answer 1

1

I'll answer my own question since I finally figured out.

One thing that most tutorials about docker leave out is how your firewall is set up. Docker is supposed to add some chains and rules for new containers, but in my case, they seem to have been faulty, so no connection could have been established.

When I flushed all my rules:

$ iptables -F

I'm able to get to my website on 127.0.0.1:8080.

EDIT: + docker version 19.03.1-ce still ignores parameter --iptables=false (https://github.com/docker/for-linux/issues/136)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .