skip to Main Content

I have two containers that run via docker-compose, my docker-compose looks like this
version: "3.7"

services: 
    mssql:
        build: ./Db
        ports:
            - 1433:1433

    planning-poker:
        build: .
        restart: always
        env_file:
            - env.list
        ports:
            - 80:8080
        depends_on:
            - mssql

Dockerfile go-app:

FROM golang:latest

RUN apt-get -y update && 
        apt-get install -y net-tools && 
        apt-get install -y iputils-ping && 
        apt-get install -y telnet

ADD . /go/src/planning-poker
WORKDIR /go/src/planning-poker

RUN go build -o main .
ENTRYPOINT ["./main"]

Dockerfile mssql:

FROM mcr.microsoft.com/mssql/server

ENV ACCEPT_EULA=Y
ENV MSSQL_SA_PASSWORD=Yukon_900

EXPOSE 1433

USER root

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY . /usr/src/app

RUN chmod +x ./run-initialization.sh

USER mssql

CMD /bin/bash ./entrypoint.sh

I am using database initialization scripts:

for i in {1..50};
do
    /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Yukon_900 -d master -i SQL_PlanningPoker.sql
    if [ $? -eq 0 ]
    then
        echo "SQL_PlanningPoker.sql completed"
        break
    else
        echo "not ready yet..."
        sleep 1
    fi
done

So is my entrypoint:

./run-initialization.sh & /opt/mssql/bin/sqlservr

The problem is that I can’t connect to mssql from the container with the golang application in any way, the connection passes from the host, I tried to connect via telnet to mssql from the go-app container on localhost 1433, 127.0.0.1 1433, 0.0.0.0 1433 but always I get an error that the connection is either reset or telnet cannot resolve the addresses.
MyProject: https://github.com/philomela/PlanningPoker/tree/master – master branch.
What am I doing wrong? thank you in advance!

2

Answers


  1. Chosen as BEST ANSWER

    The issue is resolved, I suffered for several days, but did not pay attention to port forwarding in my application, now everything is working stably!


  2. try adding network and kepp all services run in same network

    networks:
        my-network:
    services: 
    mssql:
        build: ./Db
        ports:
            - 1433:1433
        networks:
           - my-network
    
    planning-poker:
        build: .
        restart: always
        env_file:
            - env.list
        ports:
            - 80:8080
        depends_on:
            - mssql
        networks:
           - my-network
    

    Also there is a possibility to check service is healthy with some heath check rather than just depends_on because docker may be up but SQL server would take some time to be up and running

    https://docs.docker.com/engine/reference/builder/#healthcheck

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search