hi i have project with golang redis and postgress database in ubonto
my docker file is :
my table.sql is this :
<code>CREATE TABLE users ( username VARCHAR (200) PRIMARY KEY, pass VARCHAR (50) );
Alter User postgres WITH PASSWORD '123';
</code>
<code>CREATE TABLE users ( username VARCHAR (200) PRIMARY KEY, pass VARCHAR (50) );
Alter User postgres WITH PASSWORD '123';
</code>
CREATE TABLE users ( username VARCHAR (200) PRIMARY KEY, pass VARCHAR (50) );
Alter User postgres WITH PASSWORD '123';
<code># syntax=docker/dockerfile:1
FROM postgres:latest AS go2
ENV POSTGRES_USER postgress
ENV POSTGRES_PASSWORD ''
ENV POSTGRES_DB postgress
EXPOSE 5432
ADD table.sql /docker-entrypoint-initdb.d/
FROM redis:latest AS go3
FROM golang:latest AS go
LABEL maintainer=”[email protected]”
WORKDIR /app
COPY . .
RUN go build -o bin
ENTRYPOINT [ "/app/bin" ]
EXPOSE 8089
</code>
<code># syntax=docker/dockerfile:1
FROM postgres:latest AS go2
ENV POSTGRES_USER postgress
ENV POSTGRES_PASSWORD ''
ENV POSTGRES_DB postgress
EXPOSE 5432
ADD table.sql /docker-entrypoint-initdb.d/
FROM redis:latest AS go3
FROM golang:latest AS go
LABEL maintainer=”[email protected]”
WORKDIR /app
COPY . .
RUN go build -o bin
ENTRYPOINT [ "/app/bin" ]
EXPOSE 8089
</code>
# syntax=docker/dockerfile:1
FROM postgres:latest AS go2
ENV POSTGRES_USER postgress
ENV POSTGRES_PASSWORD ''
ENV POSTGRES_DB postgress
EXPOSE 5432
ADD table.sql /docker-entrypoint-initdb.d/
FROM redis:latest AS go3
FROM golang:latest AS go
LABEL maintainer=”[email protected]”
WORKDIR /app
COPY . .
RUN go build -o bin
ENTRYPOINT [ "/app/bin" ]
EXPOSE 8089
and i build it with this command :
<code>docker build . -t mycontiner
</code>
<code>docker build . -t mycontiner
</code>
docker build . -t mycontiner
and i run it with this command :
<code>docker run -t mycontiner --network=bridge
</code>
<code>docker run -t mycontiner --network=bridge
</code>
docker run -t mycontiner --network=bridge
and its show this :
<code>[error] failed to initialize database, got error failed to connect to `host=172.17.0.2 user=postgres database=postgres`: dial error (dial tcp 172.17.0.2:5432: connect: connection refused)
2024/07/29 13:52:27 IP:172.17.0.2
2024/07/29 13:52:27 IP:172.17.0.2
2024/07/29 13:52:27 server listening at 172.17.0.2:8089
2024/07/29 13:52:27 server listening at 172.17.0.2:8089
</code>
<code>[error] failed to initialize database, got error failed to connect to `host=172.17.0.2 user=postgres database=postgres`: dial error (dial tcp 172.17.0.2:5432: connect: connection refused)
2024/07/29 13:52:27 IP:172.17.0.2
2024/07/29 13:52:27 IP:172.17.0.2
2024/07/29 13:52:27 server listening at 172.17.0.2:8089
2024/07/29 13:52:27 server listening at 172.17.0.2:8089
</code>
[error] failed to initialize database, got error failed to connect to `host=172.17.0.2 user=postgres database=postgres`: dial error (dial tcp 172.17.0.2:5432: connect: connection refused)
2024/07/29 13:52:27 IP:172.17.0.2
2024/07/29 13:52:27 IP:172.17.0.2
2024/07/29 13:52:27 server listening at 172.17.0.2:8089
2024/07/29 13:52:27 server listening at 172.17.0.2:8089
My problem is:
1-i cant connect to postgress database 127.0.0.1:5432 with user postgress and pass 123
2-i cant connect to continer with port 8089
what can i do?
i tried to run it with
<code>docker run -t mycontiner --network=host
</code>
<code>docker run -t mycontiner --network=host
</code>
docker run -t mycontiner --network=host
but same
i cant connect to it or ping it and same postgres database cant be accessed