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



{ Error: connect ECONNREFUSED 172.19.0.2:5432
backend_1 | at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1117:14)
backend_1 | errno: 'ECONNREFUSED',
backend_1 | code: 'ECONNREFUSED',
backend_1 | syscall: 'connect',
backend_1 | address: '172.19.0.2',
backend_1 | port: 5432 }


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



{ Error: connect ECONNREFUSED 172.19.0.2:5432
backend_1 | at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1117:14)
backend_1 | errno: 'ECONNREFUSED',
backend_1 | code: 'ECONNREFUSED',
backend_1 | syscall: 'connect',
backend_1 | address: '172.19.0.2',
backend_1 | port: 5432 }


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



{ Error: connect ECONNREFUSED 172.19.0.2:5432
backend_1 | at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1117:14)
backend_1 | errno: 'ECONNREFUSED',
backend_1 | code: 'ECONNREFUSED',
backend_1 | syscall: 'connect',
backend_1 | address: '172.19.0.2',
backend_1 | port: 5432 }


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



{ Error: connect ECONNREFUSED 172.19.0.2:5432
backend_1 | at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1117:14)
backend_1 | errno: 'ECONNREFUSED',
backend_1 | code: 'ECONNREFUSED',
backend_1 | syscall: 'connect',
backend_1 | address: '172.19.0.2',
backend_1 | port: 5432 }


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

            鏡平學校

            ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

            Why https connections are so slow when debugging (stepping over) in Java?