I am trying to build a custom image for SQL Server and need to apply some initialization scripts and data migrations before the application connects to it. So I searched for this in the official docs but I am facing a weird problem, where my entrypoint.sh
file is not able to find the sqlservr
binary. This is my Dockerfile
FROM mcr.microsoft.com/mssql/server:2022-latest
USER root
WORKDIR /usr/src/app
# Copy the entrypoint.sh and migrations.sh files for running all the required migrations
COPY . .
# Setup the environment for the mssql container
ENV ACCEPT_EULA=Y
ENV MSSQL_SA_PASSWORD=testPass#1234
ENV MSSQL_PID=Developer
# Expose the port 1433 for other services
EXPOSE 1433
# Make both the files executable
RUN chmod +x ./entrypoint.sh
RUN chmod +x ./migrations.sh
RUN chmod +x /opt/mssql/bin/sqlservr
# CMD "/bin/bash"
ENTRYPOINT ["/bin/bash", "./entrypoint.sh"]
This is my entrypoint.sh
file
echo "********************************* Started SQL Server Image *********************************"
/opt/mssql/bin/sqlservr
This is my docker run output
[+] Building 0.2s (11/11) FINISHED docker:default
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 618B 0.0s
=> [internal] load metadata for mcr.microsoft.com/mssql/server:2022-latest 0.0s
=> [1/6] FROM mcr.microsoft.com/mssql/server:2022-latest 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 97B 0.0s
=> CACHED [2/6] WORKDIR /usr/src/app 0.0s
=> CACHED [3/6] COPY . . 0.0s
=> CACHED [4/6] RUN chmod +x ./entrypoint.sh 0.0s
=> CACHED [5/6] RUN chmod +x ./migrations.sh 0.0s
=> CACHED [6/6] RUN chmod +x /opt/mssql/bin/sqlservr 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:a9ff35832dec4ba79f8ca2d36580ddef2d13d221f646068eaa896dc2d165b921 0.0s
=> => naming to docker.io/library/todo-db 0.0s
database-test
********************************* Started SQL Server Image *********************************
: No such file or directorypt/mssql/bin/sqlservr
1条答案
按热度按时间qvk1mo1f1#
As suggested in the comments the problem was in the file endings being CRLF instead of LF. Posting this answer for anyone who stumbles upon the same problem.
Updated Dockerfile