skip to Main Content

I am trying to run MSSQL-Server in Ubuntu 20.04 base image. Image gets created with no errors, but container does not start. Please help. Thanks in advance for your comments and helps. This is the files.

rams/ubuntu:base Dockerfile

# Use the official Ubuntu 20.04 as base image
FROM ubuntu:20.04

# Install dependencies
RUN apt-get update && 
    apt-get install -y 
    curl 
    wget 
    software-properties-common 
    dirmngr 
    apt-transport-https 
    lsb-release 
    ca-certificates && 
    apt-get clean && 
    rm -rf /var/lib/apt/lists/*

Dockerfile

# Use the official Ubuntu 20.04 as base image
FROM rams/ubuntu:base

ENV DEBIAN_FRONTEND=noninteractive

# Install dependencies
RUN apt-get update && 
    apt-get install -y gnupg2 && 
    apt-get clean

# Install MSSQL Server and command-line tools
RUN curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc
RUN add-apt-repository "$(curl -sSL https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2022.list)"
RUN apt-get update && 
    ACCEPT_EULA=Y apt-get install -y mssql-server && 
    apt-get clean

RUN curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc
RUN curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | tee /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update && 
    ACCEPT_EULA=Y apt-get install -y msodbcsql17 && 
    ACCEPT_EULA=Y apt-get install -y mssql-tools && 
    echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc && 
#    source ~/.bashrc && 
    apt-get install -y unixodbc-dev && 
    apt-get clean

# Expose the port for SQL Server
EXPOSE 1433

docker-compose.yaml

version: '3.8'

services:
  sql_server:
    build:
      context: .
      dockerfile: Dockerfile
    image: rams/mssql:base
    container_name: rams-mssql
    ports:
      - "1433:1433"
    environment:
      ACCEPT_EULA: "Y"
      SA_PASSWORD: "YourStrong!Passw0rd"
      MSSQL_PID: "Developer"

I checked the code with ChatGPT but not working.

2

Answers


  1. Chosen as BEST ANSWER

    Since I could not find a fix. I used the following files to fix my situation.

    docker-compose.yaml

    version: '3.7'
    services:
      ms_sql_server:
        image: mcr.microsoft.com/mssql/server:2019-latest
        ports:
          - "1433:1433"
        environment:
          ACCEPT_EULA: "Y"
          MSSQL_SA_PASSWORD: "YourStrong@Passw0rd"
          MSSQL_PID: "Developer"
        volumes:
          - db_data:/var/opt/mssql
        networks:
          mynetwork:
            ipv4_address: 172.18.0.2
    
    networks:
      mynetwork:
        external: true
    
    volumes:
      db_data:
    
    

    dockerfile

    FROM mcr.microsoft.com/mssql/server:2019-latest
    
    # Install SQL Server command line tools
    RUN apt-get update && 
        apt-get install -y curl gnupg && 
        curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && 
        curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list && 
        apt-get update && 
        ACCEPT_EULA=Y apt-get install -y mssql-tools unixodbc-dev
    
    # Add tools to PATH
    RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
    

  2. As mentioned in the comments you need to switch the container user and specify an ENTRYPOINT. You could try something like this Dockerfile…

    # syntax=docker/dockerfile:1.3-labs
    FROM ubuntu:20.04 as foundation
    ENV DEBIAN_FRONTEND=noninteractive
    RUN /bin/bash <<EOF ## Install dependencies
        set -ex
        apt-get update --fix-missing
        apt-get install --no-install-recommends --yes 
            apt-transport-https ca-certificates curl dirmngr gnupg2 
            lsb-release software-properties-common unixodbc-dev
        apt-get clean
        rm -rf /var/lib/apt/lists/*
    EOF
    
    FROM foundation as squirrel
    RUN /bin/bash <<EOF ## Install MSSQL
        set -ex
        curl -sSL https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc
        curl -sSL https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2022.list | tee /etc/apt/sources.list.d/microsoft-mssql2022.list
        curl -sSL https://packages.microsoft.com/config/ubuntu/20.04/prod.list | tee /etc/apt/sources.list.d/microsoft-prod.list
        apt-get update --fix-missing
        ACCEPT_EULA=Y apt-get install -y mssql-server msodbcsql17 mssql-tools
        echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
        echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~mssql/.bashrc
        apt-get clean
        rm -rf /var/lib/apt/lists/*
    EOF
    ENTRYPOINT [ "/opt/mssql/bin/sqlservr" ]
    EXPOSE 1433
    USER mssql
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search