PostgreSQL After docker-compose down the used port cant be used again









up vote
0
down vote

favorite












I am working with a project that uses express as the server and postgres as the db to learn dockers.
the server depends on the db to be up.
The first time i use docker-compose up it all works fine but when i restart it
(docker-compose down and docker-compose up again) it says that something is wrong with the port



version: '3'
services:
db:
image: postgres:10
ports:
- "5433:5432"
environment:
POSTGRES_USER: 'Donald'
POSTGRES_PASSWORD: 'Aa123456'
POSTGRES_DB: 'twitter'

backend:
build: twitter
ports:
- "3000:3000"
depends_on:
- db
environment:
PGHOST: "db"
PGPORT: '5432'
PGDATABASE: 'twitter'
PGUSER: 'Donald'
PGPASSWORD: 'Aa123456'


The error



 code: 'ECONNREFUSED',
backend_1


ports before docker-compose down



CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b000b9a02257 excer_backend "node server" 5 minutes ago Up 3 minutes 0.0.0.0:3000->3000/tcp excer_backend_1
40ca65adcc46 postgres:10 "docker-entrypoint.s…" 5 minutes ago Up 3 minutes 0.0.0.0:5433->5432/tcp excer_db_1


after i use docker-compose down and see the ports its all clean and no open ports are left



Than i found something very interesting a when i used docker-compose up it always worked if i use ctr + c and use compose up again still work same when i restart docker but as soon as i use docker-compose down the error is shown.
I tried man combinations with restarting my docker and ctr + c and compose-up
all worked but as soon as i use docker-compose down it dosent work why is that ?










share|improve this question























  • It could be the port is still being used. Check by seeing if the port is still open
    – mjwatts
    Nov 9 at 22:25










  • Already checked ports there are none open ports after docker-compose down
    – David Nachimov
    Nov 9 at 22:37










  • Are you sure 179.19.0.2 is the correct address? Is it possible that the new postgres container has received a different address? You can use the hostname db or your environment variable PGHOSTNAME. Also postgresql has a bit of a spin up time, so if you start both containers at the same time, you might have to let your application server sleep for a few seconds before attempting to connect to the database.
    – Håken Lid
    Nov 10 at 14:20















up vote
0
down vote

favorite












I am working with a project that uses express as the server and postgres as the db to learn dockers.
the server depends on the db to be up.
The first time i use docker-compose up it all works fine but when i restart it
(docker-compose down and docker-compose up again) it says that something is wrong with the port



version: '3'
services:
db:
image: postgres:10
ports:
- "5433:5432"
environment:
POSTGRES_USER: 'Donald'
POSTGRES_PASSWORD: 'Aa123456'
POSTGRES_DB: 'twitter'

backend:
build: twitter
ports:
- "3000:3000"
depends_on:
- db
environment:
PGHOST: "db"
PGPORT: '5432'
PGDATABASE: 'twitter'
PGUSER: 'Donald'
PGPASSWORD: 'Aa123456'


The error



 code: 'ECONNREFUSED',
backend_1


ports before docker-compose down



CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b000b9a02257 excer_backend "node server" 5 minutes ago Up 3 minutes 0.0.0.0:3000->3000/tcp excer_backend_1
40ca65adcc46 postgres:10 "docker-entrypoint.s…" 5 minutes ago Up 3 minutes 0.0.0.0:5433->5432/tcp excer_db_1


after i use docker-compose down and see the ports its all clean and no open ports are left



Than i found something very interesting a when i used docker-compose up it always worked if i use ctr + c and use compose up again still work same when i restart docker but as soon as i use docker-compose down the error is shown.
I tried man combinations with restarting my docker and ctr + c and compose-up
all worked but as soon as i use docker-compose down it dosent work why is that ?










share|improve this question























  • It could be the port is still being used. Check by seeing if the port is still open
    – mjwatts
    Nov 9 at 22:25










  • Already checked ports there are none open ports after docker-compose down
    – David Nachimov
    Nov 9 at 22:37










  • Are you sure 179.19.0.2 is the correct address? Is it possible that the new postgres container has received a different address? You can use the hostname db or your environment variable PGHOSTNAME. Also postgresql has a bit of a spin up time, so if you start both containers at the same time, you might have to let your application server sleep for a few seconds before attempting to connect to the database.
    – Håken Lid
    Nov 10 at 14:20













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am working with a project that uses express as the server and postgres as the db to learn dockers.
the server depends on the db to be up.
The first time i use docker-compose up it all works fine but when i restart it
(docker-compose down and docker-compose up again) it says that something is wrong with the port



version: '3'
services:
db:
image: postgres:10
ports:
- "5433:5432"
environment:
POSTGRES_USER: 'Donald'
POSTGRES_PASSWORD: 'Aa123456'
POSTGRES_DB: 'twitter'

backend:
build: twitter
ports:
- "3000:3000"
depends_on:
- db
environment:
PGHOST: "db"
PGPORT: '5432'
PGDATABASE: 'twitter'
PGUSER: 'Donald'
PGPASSWORD: 'Aa123456'


The error



 code: 'ECONNREFUSED',
backend_1


ports before docker-compose down



CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b000b9a02257 excer_backend "node server" 5 minutes ago Up 3 minutes 0.0.0.0:3000->3000/tcp excer_backend_1
40ca65adcc46 postgres:10 "docker-entrypoint.s…" 5 minutes ago Up 3 minutes 0.0.0.0:5433->5432/tcp excer_db_1


after i use docker-compose down and see the ports its all clean and no open ports are left



Than i found something very interesting a when i used docker-compose up it always worked if i use ctr + c and use compose up again still work same when i restart docker but as soon as i use docker-compose down the error is shown.
I tried man combinations with restarting my docker and ctr + c and compose-up
all worked but as soon as i use docker-compose down it dosent work why is that ?










share|improve this question















I am working with a project that uses express as the server and postgres as the db to learn dockers.
the server depends on the db to be up.
The first time i use docker-compose up it all works fine but when i restart it
(docker-compose down and docker-compose up again) it says that something is wrong with the port



version: '3'
services:
db:
image: postgres:10
ports:
- "5433:5432"
environment:
POSTGRES_USER: 'Donald'
POSTGRES_PASSWORD: 'Aa123456'
POSTGRES_DB: 'twitter'

backend:
build: twitter
ports:
- "3000:3000"
depends_on:
- db
environment:
PGHOST: "db"
PGPORT: '5432'
PGDATABASE: 'twitter'
PGUSER: 'Donald'
PGPASSWORD: 'Aa123456'


The error



 code: 'ECONNREFUSED',
backend_1


ports before docker-compose down



CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b000b9a02257 excer_backend "node server" 5 minutes ago Up 3 minutes 0.0.0.0:3000->3000/tcp excer_backend_1
40ca65adcc46 postgres:10 "docker-entrypoint.s…" 5 minutes ago Up 3 minutes 0.0.0.0:5433->5432/tcp excer_db_1


after i use docker-compose down and see the ports its all clean and no open ports are left



Than i found something very interesting a when i used docker-compose up it always worked if i use ctr + c and use compose up again still work same when i restart docker but as soon as i use docker-compose down the error is shown.
I tried man combinations with restarting my docker and ctr + c and compose-up
all worked but as soon as i use docker-compose down it dosent work why is that ?







javascript postgresql express docker docker-compose






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 14:13









Håken Lid

10.4k62441




10.4k62441










asked Nov 9 at 22:09









David Nachimov

34




34











  • It could be the port is still being used. Check by seeing if the port is still open
    – mjwatts
    Nov 9 at 22:25










  • Already checked ports there are none open ports after docker-compose down
    – David Nachimov
    Nov 9 at 22:37










  • Are you sure 179.19.0.2 is the correct address? Is it possible that the new postgres container has received a different address? You can use the hostname db or your environment variable PGHOSTNAME. Also postgresql has a bit of a spin up time, so if you start both containers at the same time, you might have to let your application server sleep for a few seconds before attempting to connect to the database.
    – Håken Lid
    Nov 10 at 14:20

















  • It could be the port is still being used. Check by seeing if the port is still open
    – mjwatts
    Nov 9 at 22:25










  • Already checked ports there are none open ports after docker-compose down
    – David Nachimov
    Nov 9 at 22:37










  • Are you sure 179.19.0.2 is the correct address? Is it possible that the new postgres container has received a different address? You can use the hostname db or your environment variable PGHOSTNAME. Also postgresql has a bit of a spin up time, so if you start both containers at the same time, you might have to let your application server sleep for a few seconds before attempting to connect to the database.
    – Håken Lid
    Nov 10 at 14:20
















It could be the port is still being used. Check by seeing if the port is still open
– mjwatts
Nov 9 at 22:25




It could be the port is still being used. Check by seeing if the port is still open
– mjwatts
Nov 9 at 22:25












Already checked ports there are none open ports after docker-compose down
– David Nachimov
Nov 9 at 22:37




Already checked ports there are none open ports after docker-compose down
– David Nachimov
Nov 9 at 22:37












Are you sure 179.19.0.2 is the correct address? Is it possible that the new postgres container has received a different address? You can use the hostname db or your environment variable PGHOSTNAME. Also postgresql has a bit of a spin up time, so if you start both containers at the same time, you might have to let your application server sleep for a few seconds before attempting to connect to the database.
– Håken Lid
Nov 10 at 14:20





Are you sure 179.19.0.2 is the correct address? Is it possible that the new postgres container has received a different address? You can use the hostname db or your environment variable PGHOSTNAME. Also postgresql has a bit of a spin up time, so if you start both containers at the same time, you might have to let your application server sleep for a few seconds before attempting to connect to the database.
– Håken Lid
Nov 10 at 14:20













1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










Most likely the DB is not up yet.



When you do docker-compose down, it deletes the container and since you aren't using a volume for persistence, the DB has to run through its init process again which will take a few seconds (and hence works when you ctrl+c and docker-compose up again).



Do note that depends_on doesn't wait until the DB is up. You will have to using something like wait-on for that in your backend container.



Another solution would be to use a volume mount for the DB container.






share|improve this answer




















    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',
    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
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233888%2fpostgresql-after-docker-compose-down-the-used-port-cant-be-used-again%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








    up vote
    2
    down vote



    accepted










    Most likely the DB is not up yet.



    When you do docker-compose down, it deletes the container and since you aren't using a volume for persistence, the DB has to run through its init process again which will take a few seconds (and hence works when you ctrl+c and docker-compose up again).



    Do note that depends_on doesn't wait until the DB is up. You will have to using something like wait-on for that in your backend container.



    Another solution would be to use a volume mount for the DB container.






    share|improve this answer
























      up vote
      2
      down vote



      accepted










      Most likely the DB is not up yet.



      When you do docker-compose down, it deletes the container and since you aren't using a volume for persistence, the DB has to run through its init process again which will take a few seconds (and hence works when you ctrl+c and docker-compose up again).



      Do note that depends_on doesn't wait until the DB is up. You will have to using something like wait-on for that in your backend container.



      Another solution would be to use a volume mount for the DB container.






      share|improve this answer






















        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        Most likely the DB is not up yet.



        When you do docker-compose down, it deletes the container and since you aren't using a volume for persistence, the DB has to run through its init process again which will take a few seconds (and hence works when you ctrl+c and docker-compose up again).



        Do note that depends_on doesn't wait until the DB is up. You will have to using something like wait-on for that in your backend container.



        Another solution would be to use a volume mount for the DB container.






        share|improve this answer












        Most likely the DB is not up yet.



        When you do docker-compose down, it deletes the container and since you aren't using a volume for persistence, the DB has to run through its init process again which will take a few seconds (and hence works when you ctrl+c and docker-compose up again).



        Do note that depends_on doesn't wait until the DB is up. You will have to using something like wait-on for that in your backend container.



        Another solution would be to use a volume mount for the DB container.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 13:41









        Pramodh Valavala

        45627




        45627



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233888%2fpostgresql-after-docker-compose-down-the-used-port-cant-be-used-again%23new-answer', 'question_page');

            );

            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







            Popular posts from this blog

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo