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 ?
javascript postgresql express docker docker-compose
add a comment |
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 ?
javascript postgresql express docker docker-compose
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 sure179.19.0.2
is the correct address? Is it possible that the new postgres container has received a different address? You can use the hostnamedb
or your environment variablePGHOSTNAME
. 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
add a comment |
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 ?
javascript postgresql express docker docker-compose
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
javascript postgresql express docker docker-compose
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 sure179.19.0.2
is the correct address? Is it possible that the new postgres container has received a different address? You can use the hostnamedb
or your environment variablePGHOSTNAME
. 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
add a comment |
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 sure179.19.0.2
is the correct address? Is it possible that the new postgres container has received a different address? You can use the hostnamedb
or your environment variablePGHOSTNAME
. 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
add a comment |
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.
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 10 at 13:41
Pramodh Valavala
45627
45627
add a comment |
add a comment |
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%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
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
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 hostnamedb
or your environment variablePGHOSTNAME
. 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