如何在Docker SQL Server映像上运行安装脚本? [英] How to run a setup script on a Docker SQL Server image?
问题描述
我正在尝试在Docker SQL Server映像上运行安装脚本
I'm trying to run a setup script on a Docker SQL Server image
为此,我从mssql映像创建了一个Dockerfile
For this I have created a Dockerfile from the mssql image
FROM microsoft/mssql-server-linux:2017-CU8
# Create directory to place app specific files
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Copy setup scripts
COPY entrypoint.sh \
./
RUN chmod +x ./entrypoint.sh
CMD /bin/bash ./entrypoint.sh
在 entrypoint.sh
中,我正在启动SQL Server,我想运行一些安装命令.
In entrypoint.sh
I'm starting SQL Server and I want to run some setup commands.
#!/bin/bash
#start SQL Server
/opt/mssql/bin/sqlservr &
echo 'Sleeping 20 seconds before running setup script'
sleep 20s
echo 'Starting setup script'
#run the setup script to create the DB and the schema in the DB
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P <MyPassWd> -d master -i setup.sql
echo 'Finished setup script'
当我运行此脚本时,数据库将启动,安装程序将运行,并且在设置完成后,容器将关闭.
When I run this script, the database starts, the setup runs, and after the setup is finished, the container shuts down.
所以我认为脚本中的某些内容会导致容器关闭,因此我将脚本剥离到最低限度
So I thought something in the script makes the container shut down, therefore I stripped the script down to a bare minimum
#!/bin/bash
#start SQL Server
/opt/mssql/bin/sqlservr &
echo 'Sleeping 20 seconds before running setup script'
sleep 20s
这也会在 sleep 20s
完成后停止容器.
That also stops the container after sleep 20s
finished.
继续...
#!/bin/bash
#start SQL Server
/opt/mssql/bin/sqlservr &
哪个会立即停止容器
然后...
#!/bin/bash
#start SQL Server
/opt/mssql/bin/sqlservr
现在容器可以运行了,但是我无法进行任何初始化
Now the container runs, but I can't do any initialization
有人知道如何使它工作吗?
Does someone know how to get this working?
推荐答案
将sql服务器的密码更改为足够复杂.
Change the password of the sql server to be complex enough.
docker run -d -p 1433:1433 -e "sa_password=ComplexPW2019!" -e "ACCEPT_EULA=Y" <sqlserverimageid>
这篇关于如何在Docker SQL Server映像上运行安装脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!