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

时间:2020-06-23 07:25:19

标签: docker sqlalchemy pymssql jupyter-kernel-gateway

我有连接到SQL Server的“ sql_helper”。

 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"]

使用以下命令运行笔记本电脑时

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运行它的人都会感激

1 个答案:

答案 0 :(得分:0)

发现问题,而不是使用主机名需要使用sql ip