记一次docker安装Sql Server的坑

前言

用虚拟机装的Cent OS7,用docker安装好一启动就退出,如下:

CONTAINER ID        IMAGE                                      COMMAND                  CREATED              STATUS                     PORTS               NAMES
48de82c7aedd        microsoft/mssql-server-linux:2017-latest   "/opt/mssql/bin/sq..."   7 seconds ago        Exited (1) 6 seconds ago                       sa

过程

首先正常拉取sql server镜像

docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=admin123' -p 1433:1433 --name sa -d microsoft/mssql-server-linux:2017-latest

等待下载完成

[root@s201 ~]# docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=Admin@12345' -p 1433:1433 --name sa -d microsoft/mssql-server-linux:2017-latest
Unable to find image 'microsoft/mssql-server-linux:2017-latest' locally
Trying to pull repository docker.io/microsoft/mssql-server-linux ... 
2017-latest: Pulling from docker.io/microsoft/mssql-server-linux
59ab41dd721a: Already exists 
57da90bec92c: Already exists 
06fe57530625: Already exists 
5a6315cba1ff: Already exists 
739f58768b3f: Already exists 
0b751601bca3: Pull complete 
bcf04a22644a: Pull complete 
6b5009e4f470: Pull complete 
a9dca2f6722a: Pull complete 
Digest: sha256:9b700672670bb3db4b212e8aef841ca79eb2fce7d5975a5ce35b7129a9b90ec0
Status: Downloaded newer image for docker.io/microsoft/mssql-server-linux:2017-latest

查看进程docker ps,发现没有正在运行的容器。
接着查看镜像,发现镜像是有的。

[root@s201 ~]# docker images
REPOSITORY                               TAG                 IMAGE ID            CREATED             SIZE
mcr.microsoft.com/mssql/server           2017-latest         81c7e82f3678        4 weeks ago         1.49 GB

docker ps -a发现容器已退出

[root@s201 ~]# docker ps -a
CONTAINER ID        IMAGE                                        COMMAND                  CREATED              STATUS                    PORTS               NAMES
db04f6abfdf6        mcr.microsoft.com/mssql/server:2017-latest   "/opt/mssql/bin/no..."   About a minute ago   Exited (1) 1 second ago                       sa

于是再次启动容器,结果和之前一样,一启动就退出。

尝试解决

从网上找了一些解决方案,大致是以下几点:

  1. 设置高强度密码,否则会出现容器启动就停止,密码需要大小写字母+数字+特殊符号
  2. 设置一个死循环进程,让前台永远有进程执行,容器就不会退出
  3. 启动命令加上-d -t

通过尝试后发现问题依然没有解决,于是突然想到看一下日志

[root@s201 ~]# docker logs sa
sqlservr: This program requires a machine with at least 2000 megabytes of memory.

意思是这个工程运行至少需要2GB的内存,然后看了一下vm ware的设置,刚好是2GB
记一次docker安装Sql Server的坑_第1张图片

问题解决

通过vmware将该虚拟机内存调至3GB后,重新启动一下,再运行就正常了

[root@s201 ~]# docker start sa
sa
[root@s201 ~]# docker ps
CONTAINER ID        IMAGE                                      COMMAND                  CREATED             STATUS              PORTS                    NAMES
48de82c7aedd        microsoft/mssql-server-linux:2017-latest   "/opt/mssql/bin/sq..."   18 minutes ago      Up 14 seconds       0.0.0.0:1433->1433/tcp   sa

你可能感兴趣的:(linux,centos,sqlserver)