Docker Compose port mapping: 127.0.0.1 refused to connect
I am currently working with Docker and a simple Flask website to which I want to send images. For this I'm working on port 8080, but the mapping from docker to host is not working properly as I am unable to connect. Could someone explain to me what I am doing wrong?
docker-compose.yml
version: "2.3"
services:
dev:
container_name: xvision-dev
build:
context: ./
dockerfile: docker/dev.dockerfile
working_dir: /app
volumes:
- .:/app
- /path/to/images:/app/images
ports:
- "127.0.0.1:8080:8080"
- "8080"
- "8080:8080"
dev.dockerfile
FROM tensorflow/tensorflow:latest
WORKDIR /app
COPY requirements.txt ./
RUN pip install -r requirements.txt
RUN apt update && apt install -y python-tk
EXPOSE 8080
CMD ["python", "-u", "app.py"]
app.py
@APP.route('/test', methods=['GET'])
def hello():
return "Hello world!"
def main():
"""Start the script"""
APP.json_encoder = Float32Encoder
APP.run(host="127.0.0.1", port=os.getenv('PORT', 8080))
I start my docker with docker-compose up
, this gives the output: Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
.
But when I do a get request to 127.0.0.1:8080/test I get that there is no response.
I have also tried docker-compose run --service-port dev
as some people have suggested online but this says that there is no service dev.
Can someone help me for what I am doing wrong?
docker flask docker-compose
add a comment |
I am currently working with Docker and a simple Flask website to which I want to send images. For this I'm working on port 8080, but the mapping from docker to host is not working properly as I am unable to connect. Could someone explain to me what I am doing wrong?
docker-compose.yml
version: "2.3"
services:
dev:
container_name: xvision-dev
build:
context: ./
dockerfile: docker/dev.dockerfile
working_dir: /app
volumes:
- .:/app
- /path/to/images:/app/images
ports:
- "127.0.0.1:8080:8080"
- "8080"
- "8080:8080"
dev.dockerfile
FROM tensorflow/tensorflow:latest
WORKDIR /app
COPY requirements.txt ./
RUN pip install -r requirements.txt
RUN apt update && apt install -y python-tk
EXPOSE 8080
CMD ["python", "-u", "app.py"]
app.py
@APP.route('/test', methods=['GET'])
def hello():
return "Hello world!"
def main():
"""Start the script"""
APP.json_encoder = Float32Encoder
APP.run(host="127.0.0.1", port=os.getenv('PORT', 8080))
I start my docker with docker-compose up
, this gives the output: Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
.
But when I do a get request to 127.0.0.1:8080/test I get that there is no response.
I have also tried docker-compose run --service-port dev
as some people have suggested online but this says that there is no service dev.
Can someone help me for what I am doing wrong?
docker flask docker-compose
I'm not that experienced in python or flask but it seems like your server never starts as you're never callingmain
.
– tkausl
Nov 14 '18 at 13:23
The server is starting as based on the output provided, the code included seems incomplete though.
– Uku Loskit
Nov 14 '18 at 13:25
add a comment |
I am currently working with Docker and a simple Flask website to which I want to send images. For this I'm working on port 8080, but the mapping from docker to host is not working properly as I am unable to connect. Could someone explain to me what I am doing wrong?
docker-compose.yml
version: "2.3"
services:
dev:
container_name: xvision-dev
build:
context: ./
dockerfile: docker/dev.dockerfile
working_dir: /app
volumes:
- .:/app
- /path/to/images:/app/images
ports:
- "127.0.0.1:8080:8080"
- "8080"
- "8080:8080"
dev.dockerfile
FROM tensorflow/tensorflow:latest
WORKDIR /app
COPY requirements.txt ./
RUN pip install -r requirements.txt
RUN apt update && apt install -y python-tk
EXPOSE 8080
CMD ["python", "-u", "app.py"]
app.py
@APP.route('/test', methods=['GET'])
def hello():
return "Hello world!"
def main():
"""Start the script"""
APP.json_encoder = Float32Encoder
APP.run(host="127.0.0.1", port=os.getenv('PORT', 8080))
I start my docker with docker-compose up
, this gives the output: Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
.
But when I do a get request to 127.0.0.1:8080/test I get that there is no response.
I have also tried docker-compose run --service-port dev
as some people have suggested online but this says that there is no service dev.
Can someone help me for what I am doing wrong?
docker flask docker-compose
I am currently working with Docker and a simple Flask website to which I want to send images. For this I'm working on port 8080, but the mapping from docker to host is not working properly as I am unable to connect. Could someone explain to me what I am doing wrong?
docker-compose.yml
version: "2.3"
services:
dev:
container_name: xvision-dev
build:
context: ./
dockerfile: docker/dev.dockerfile
working_dir: /app
volumes:
- .:/app
- /path/to/images:/app/images
ports:
- "127.0.0.1:8080:8080"
- "8080"
- "8080:8080"
dev.dockerfile
FROM tensorflow/tensorflow:latest
WORKDIR /app
COPY requirements.txt ./
RUN pip install -r requirements.txt
RUN apt update && apt install -y python-tk
EXPOSE 8080
CMD ["python", "-u", "app.py"]
app.py
@APP.route('/test', methods=['GET'])
def hello():
return "Hello world!"
def main():
"""Start the script"""
APP.json_encoder = Float32Encoder
APP.run(host="127.0.0.1", port=os.getenv('PORT', 8080))
I start my docker with docker-compose up
, this gives the output: Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
.
But when I do a get request to 127.0.0.1:8080/test I get that there is no response.
I have also tried docker-compose run --service-port dev
as some people have suggested online but this says that there is no service dev.
Can someone help me for what I am doing wrong?
docker flask docker-compose
docker flask docker-compose
asked Nov 14 '18 at 13:20
Anna JeanineAnna Jeanine
1,41911441
1,41911441
I'm not that experienced in python or flask but it seems like your server never starts as you're never callingmain
.
– tkausl
Nov 14 '18 at 13:23
The server is starting as based on the output provided, the code included seems incomplete though.
– Uku Loskit
Nov 14 '18 at 13:25
add a comment |
I'm not that experienced in python or flask but it seems like your server never starts as you're never callingmain
.
– tkausl
Nov 14 '18 at 13:23
The server is starting as based on the output provided, the code included seems incomplete though.
– Uku Loskit
Nov 14 '18 at 13:25
I'm not that experienced in python or flask but it seems like your server never starts as you're never calling
main
.– tkausl
Nov 14 '18 at 13:23
I'm not that experienced in python or flask but it seems like your server never starts as you're never calling
main
.– tkausl
Nov 14 '18 at 13:23
The server is starting as based on the output provided, the code included seems incomplete though.
– Uku Loskit
Nov 14 '18 at 13:25
The server is starting as based on the output provided, the code included seems incomplete though.
– Uku Loskit
Nov 14 '18 at 13:25
add a comment |
1 Answer
1
active
oldest
votes
Use:
APP.run(host="0.0.0.0", port=os.getenv('PORT', 8080))
Using only:
ports:
- "8080:8080"
is enough
And still use docker-compose up to start the docker?
– Anna Jeanine
Nov 14 '18 at 13:36
yes, that's right
– Uku Loskit
Nov 14 '18 at 14:24
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301190%2fdocker-compose-port-mapping-127-0-0-1-refused-to-connect%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use:
APP.run(host="0.0.0.0", port=os.getenv('PORT', 8080))
Using only:
ports:
- "8080:8080"
is enough
And still use docker-compose up to start the docker?
– Anna Jeanine
Nov 14 '18 at 13:36
yes, that's right
– Uku Loskit
Nov 14 '18 at 14:24
add a comment |
Use:
APP.run(host="0.0.0.0", port=os.getenv('PORT', 8080))
Using only:
ports:
- "8080:8080"
is enough
And still use docker-compose up to start the docker?
– Anna Jeanine
Nov 14 '18 at 13:36
yes, that's right
– Uku Loskit
Nov 14 '18 at 14:24
add a comment |
Use:
APP.run(host="0.0.0.0", port=os.getenv('PORT', 8080))
Using only:
ports:
- "8080:8080"
is enough
Use:
APP.run(host="0.0.0.0", port=os.getenv('PORT', 8080))
Using only:
ports:
- "8080:8080"
is enough
answered Nov 14 '18 at 13:23
Uku LoskitUku Loskit
30.8k86981
30.8k86981
And still use docker-compose up to start the docker?
– Anna Jeanine
Nov 14 '18 at 13:36
yes, that's right
– Uku Loskit
Nov 14 '18 at 14:24
add a comment |
And still use docker-compose up to start the docker?
– Anna Jeanine
Nov 14 '18 at 13:36
yes, that's right
– Uku Loskit
Nov 14 '18 at 14:24
And still use docker-compose up to start the docker?
– Anna Jeanine
Nov 14 '18 at 13:36
And still use docker-compose up to start the docker?
– Anna Jeanine
Nov 14 '18 at 13:36
yes, that's right
– Uku Loskit
Nov 14 '18 at 14:24
yes, that's right
– Uku Loskit
Nov 14 '18 at 14:24
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301190%2fdocker-compose-port-mapping-127-0-0-1-refused-to-connect%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I'm not that experienced in python or flask but it seems like your server never starts as you're never calling
main
.– tkausl
Nov 14 '18 at 13:23
The server is starting as based on the output provided, the code included seems incomplete though.
– Uku Loskit
Nov 14 '18 at 13:25