SQLAlchemy + pymssql - 无法从 jupyter 内核网关 docker 连接到 sql 数据库

SQLAlchemy + pymssql - cannot connect to sql db from jupyter kernel gateway docker

我有 'sql_helper' 连接到我的 sql 服务器。

 db_connection = 'mssql+pymssql://{user}:{password}@{server}/{db}'.format(
 user=db_user, password=db_password, server=server_name, db=db_name)

 engine = sa.create_engine(db_connection)

当 运行在本地运行时效果很好。

然后,我将它添加到我的 jupyter 内核 docker 映像中。 这是 docker 文件

# start from the jupyter image pre-installed
FROM jupyter/datascience-notebook

# install the docker 
RUN pip install docker

# install the pymssql
RUN pip install pymssql

# install the kernel gateway
RUN pip install jupyter_kernel_gateway

# install the configuration helper
COPY configuration_helper-0.0.1-py3-none-any.whl /tmp/configuration_helper-0.0.1-py3-none-any.whl
RUN pip install /tmp/configuration_helper-0.0.1-py3-none-any.whl

# install the sql helper
COPY sql_helper-0.0.1-py3-none-any.whl /tmp/sql_helper-0.0.1-py3-none-any.whl
RUN pip install /tmp/sql_helper-0.0.1-py3-none-any.whl

# update enviroment variable
ENV AM_I_IN_A_DOCKER_CONTAINER Yes

EXPOSE 1433 
EXPOSE 5000 

# run kernel gateway on container start, not notebook server
EXPOSE 8888
CMD ["jupyter", "kernelgateway", "--KernelGatewayApp.ip=0.0.0.0", "--KernelGatewayApp.port=8888", "--KernelGatewayApp.api=kernel_gateway.notebook_http", "--KernelGatewayApp.seed_uri"]

当运行ning notebook用以下命令

docker run -it --rm -p 1433:1433 -e "ACCEPT_EULA=Y" --net=host --name ml_docker_rule_Get_prediction_rule_2 -v C:\Notebooks:/data jupyter-kernel-gateway  jupyter kernelgateway --KernelGatewayApp.api='kernel_gateway.notebook_http' --KernelGatewayApp.seed_uri='/data/AOI_app_1.ipynb' --KernelGatewayApp.ip=0.0.0.0 --KernelGatewayApp.port=8901

我收到以下错误

Unable to connect: Adaptive Server is unavailable or does not exist (TESLADEVSQL01:1433)

如果我 运行 来自 docker 的任何帮助,我们将不胜感激

发现问题,不用host name 需要用sql ip