【发布时间】:2017-05-21 01:16:02
【问题描述】:
我想通过在容器启动时添加一个带有一个表的简单数据库来修改 SQL Server Linux 容器的行为。
我看到此问题的 docker 映像版本是截至 2017 年 5 月 20 日的最新版本,即ctp2-1。
我正在使用Docker for Windows 和17.05.0-ce 的最新版本。我将 MobyLinuxVM 的 RAM 增加到 6144MB,因为建议使用 4GB 以上。
重现问题的步骤
准备文件
(1) Create a local Windows folder, in my case,
C:\temp\docker\
(2) Add "Dockerfile" (note no file extension) with the following content.
FROM microsoft/mssql-server-linux:latest
COPY ./custom /tmp
RUN chmod +x /tmp/entrypoint.sh \
&& chmod +x /tmp/createdb.sh
CMD /bin/bash /tmp/entrypoint.sh
(3) Add a subfolder "custom"
C:\temp\docker\custom\
(4) Add 3 files to "custom" subfolder with following content.
(A) entrypoint.sh
/opt/mssql/bin/sqlservr & /tmp/createdb.sh
(B) createdb.sh
sleep 30s
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P '!StrongPass45' -d master -i /tmp/createdb.sql
(C) createdb.sql
CREATE DATABASE DemoData;
GO
USE DemoData;
GO
CREATE TABLE Products (ID int, ProductName nvarchar(max));
GO
运行 Docker 命令(您将在此处的最后一步看到问题)
(1) Open PowerShell and cd to folder in step (1) above, in my case
cd C:\temp\docker
(2) Run docker build command
docker build .
(3) After image is built, run the following command and remember the first 3 letters of your image id, in my case "e65"
docker images
[![enter image description here][2]][2]
(4) Create the container with the following command (note the last 3 characters should be replaced by yours, also use the same password you used above)
docker run -d -e SA_PASSWORD="!StrongPass45" -e ACCEPT_EULA="Y" -p 1433:1433 e65
(5) Check your container is running
docker ps -a
[![enter image description here][2]][2]
(6) Wait about 2 minutes and check your container status again. AT THIS POINT, THE CONTAINER WOULD HAVE EXITED.
docker ps -a
[![enter image description here][2]][2]
我检查了如下日志。
docker logs e65
下面附上SQL Server成功创建DemoData数据库后的日志底部。
[![enter image description here][2]][2]
IMO,日志中的问题行是这一行
Parallel redo is shutdown for database 'DemoData' with worker pool size [1].
我尝试了各种其他 SQL 语句(甚至添加自定义 MDF 和 LDF 文件并附加到它们)以向 OOB 图像添加行为。 我什至能够在容器退出前几秒钟使用 SSMS 连接到新数据库!
有人看过这个问题吗?有人可以试试吗?
【问题讨论】:
-
您的启动命令可能正在返回,从而退出容器。如果将 -d 替换为 -it,将 /bin/bash 添加到运行命令的末尾,您将获得交互式提示并可以对 CMD 进行故障排除。
-
@user2105103 我进行了交互,得到了 bash 提示符,然后简单地运行“/tmp/entrypoint.sh”,这正是 Dockerfile 中的 CMD 应该做的。好吧,容器工作并且没有使用交互式退出。你知道会发生什么吗?
-
CMD 返回了吗?如果你把你的 createdb 注释掉,它会起作用吗?
-
@user2105103,是的,CMD 正在返回。如果我注释掉 createdb,它可以工作,但显然没有 db。所以我想问题是如何让 CMD 不返回,对吧?这很难做到吗?
标签: sql-server linux docker dockerfile