Docker Compose not exposing SQL Server port numbers

Hi

I have created a docker-compose file that builds a Microsoft SQL Server container and restores several SQL Server databases on it.

The image builds successfully. However, the ports specified in the file are not being exposed. Can you please advise on how I can fix the problem?

My docker-compose script is:

version: '3.9'

services:
  mssql-samples:
    container_name: mssql-server-samplesdb
    build: 
      context: .
      dockerfile: DockerFile
    ports:
      - "14430:1433"
    environment:
      - MSSQL_SA_PASSWORD="PaSSw0rd12#"
      - ACCEPT_EULA = "Y"
      - MSSQL_PID = "Developer"
      - MSSQL_AGENT_ENABLED="true"
    volumes:
      - ${LOCAL_MOUNTPOINT}:/var/opt/mssql/data
      - ${SHARED_FOLDER}:/var/opt/mssql/SHARED_FOLDER
volumes:
  LOCAL_MOUNTPOINT:
  SHARED_FOLDER:

I am running my container using the following command

docker-compose build --build-arg INCLUDE_ALL_DATABASES=1
docker run d7cd8aa37daf

docker run will only run a container from an image without using any configuration file. If you use docker compose, run the containers with docker compose.

docker-compose build --build-arg INCLUDE_ALL_DATABASES=1
docker-compose up -d

Or just simply use the second line since you can define build arguments in the compose file:

version: '3.9'

services:
  mssql-samples:
    container_name: mssql-server-samplesdb
    build:
      args:
        INCLUDE_ALL_DATABASES: 1
      context: .
      dockerfile: DockerFile
    ports:
      - "14430:1433"
    environment:
      - MSSQL_SA_PASSWORD="PaSSw0rd12#"
      - ACCEPT_EULA = "Y"
      - MSSQL_PID = "Developer"
      - MSSQL_AGENT_ENABLED="true"
    volumes:
      - ${LOCAL_MOUNTPOINT}:/var/opt/mssql/data
      - ${SHARED_FOLDER}:/var/opt/mssql/SHARED_FOLDER
volumes:
  LOCAL_MOUNTPOINT:
  SHARED_FOLDER:

If you want to make sure compose will rebuild your image, use this command:

docker-compose up -d --build