【问题标题】:SQLAlchemy + pymssql - cannot connect to sql db from jupyter kernel gateway dockerSQLAlchemy + pymssql - 无法从 jupyter 内核网关 docker 连接到 sql db
【发布时间】:2020-06-23 07:25:19
【问题描述】:

我有连接到我的 sql 服务器的“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 运行它的任何帮助将不胜感激

【问题讨论】:

    标签: docker sqlalchemy pymssql jupyter-kernel-gateway


    【解决方案1】:

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

    【讨论】:

    • 我遇到了类似的问题,使用 IP 而不是主机名解决了这个问题。或者,您可以 ping 主机以获取完整的主机名(例如,如果我 ping 我的db_host 我得到db_host.some_network.LOCAL)。它实现了相同的效果,但可能对 IP 更改更加稳健。
    猜你喜欢
    • 2020-09-20
    • 2019-07-24
    • 1970-01-01
    • 1970-01-01
    • 2013-07-13
    • 2011-05-08
    • 2020-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多