我正在尝试连接在docker容器中运行的pyodbc python脚本以登录到MSSQL数据库我已经尝试了各种docker文件,但是无法建立连接(在构建docker或python尝试连接时失败),有没有人有一个工作的dockerfile,使用pyodbc:
Dockerfile:
# Use an official Python runtime as a parent image
FROM python:2.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt
# Run app.py when the container launches
CMD ["python", "App.py"]
Run Code Online (Sandbox Code Playgroud)
requirements.TXT
pyodbc
Run Code Online (Sandbox Code Playgroud)
App.Py
import pyodbc
connection = pyodbc.connect('Driver={SQL Server};'
'Server=xxxx;'
'Database=xxx;'
'UID=xxxx;'
'PWD=xxxx')
cursor = connection.cursor()
cursor.execute("SELECT [Id],[Name] FROM …
Run Code Online (Sandbox Code Playgroud)