我目前正在尝试将 Docker 用于我的新 Django/Postgres 项目。我在 Mac 上工作,通常使用 Postico 快速连接到我的数据库。
我曾经像这里一样连接:
我使用官方 Docker 文档来设置 docker-compose。我现在遇到的问题是,我无法通过 Postico 连接到 postgres 数据库。在我看来,问题来自未公开的端口。
version: '3'
services:
db:
image: postgres
web:
build: .
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
Run Code Online (Sandbox Code Playgroud) 到目前为止,我在这里使用了以下代码行:
max_total_gross = event_data["max_total_gross"].loc[event_data["event_id"] == event_id].item()
Run Code Online (Sandbox Code Playgroud)
自从我更新了熊猫以来,我收到了未来的警告:
/opt/conda/lib/python3.7/site-packages/ipykernel_launcher.py:12:
item不建议使用FutureWarning:如果sys.path [0] =='',则将在以后的版本中删除:
我试图用这种方式修复它,但是结果不一样:
event_data.loc[event_data.event_id == event_id, 'max_total_gross']
Run Code Online (Sandbox Code Playgroud)
我期望一个整数。
我构建了以下图像,docker build -t mylambda .
我现在尝试lambdatest.zip在构建它时导出到我的本地主机,所以我在我的桌面上看到了 .zip 文件。到目前为止,我使用过,docker cp <Container ID>:/var/task/lambdatest.zip ~/Desktop但这在我的 Dockerfile (?) 中不起作用。你有什么想法?
FROM lambci/lambda:build-python3.7
COPY lambda_function.py .
RUN python3 -m venv venv
RUN . venv/bin/activate
# ZIP
RUN pushd /var/task/venv/lib/python3.7/site-packages/
# Execute "zip" in bash for explanation of -9qr
RUN zip -9qr /var/task/lambdatest.zip *
Run Code Online (Sandbox Code Playgroud)
Dockerfile(更新):
FROM lambci/lambda:build-python3.7
RUN python3 -m venv venv
RUN . venv/bin/activate
RUN pip install --upgrade pip
RUN pip install pystan==2.18
RUN pip install fbprophet
WORKDIR /var/task/venv/lib/python3.7/site-packages
COPY lambda_function.py …Run Code Online (Sandbox Code Playgroud) 我目前尝试运行此 AWS Lambda 入门教程:https : //docs.aws.amazon.com/lambda/latest/dg/with-s3-example-deployment-pkg.html#with-s3-example-deployment -pkg-python
但是,我总是收到一个错误:
{
"errorMessage": "Unable to import module 'CreateThumbnail': cannot import name '_imaging' from 'PIL' (/var/task/PIL/__init__.py)",
"errorType": "Runtime.ImportModuleError"
}
Run Code Online (Sandbox Code Playgroud)
日志输出
START RequestId: fefba1d1-443c-4617-a5ad-c3aac19e5591 Version: $LATEST
[ERROR] Runtime.ImportModuleError: Unable to import module 'CreateThumbnail': cannot import name '_imaging' from 'PIL' (/var/task/PIL/__init__.py)
END RequestId: fefba1d1-443c-4617-a5ad-c3aac19e5591
REPORT RequestId: fefba1d1-443c-4617-a5ad-c3aac19e5591 Duration: 1.52 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 71 MB
Run Code Online (Sandbox Code Playgroud)
我走了那么远从lambci/docker-lambda图像构建我的 .zip 。但这并没有解决我的问题。
这是我的 .zip 文件中的内容。你有什么想法,为什么我仍然收到这个错误?
我必须设置export PATH=~/.local/bin:$PATH. 只要我docker exec -it <container> bash手动完成它就可以了。但是,我尝试将其自动化.dockerfile:
FROM jupyter/scipy-notebook
RUN conda install --yes -c conda-forge fbprophet
ENV PATH="~/.local/bin:${PATH}"
RUN pip install awscli --upgrade --user
Run Code Online (Sandbox Code Playgroud)
似乎ENV PATH="~/.local/bin:${PATH}"与我在这里收到的警告的效果不同。你看到我做错了什么了吗?
WARNING: The scripts pyrsa-decrypt, pyrsa-decrypt-bigfile, pyrsa-encrypt, pyrsa-encrypt-bigfile, pyrsa-keygen, pyrsa-priv2pub, pyrsa-sign and pyrsa-verify are installed in '/home/jovyan/.local/bin' which is not on PATH.
Run Code Online (Sandbox Code Playgroud) print(df.head) 结果是
ds y
0 2019-03-01 10:57:32.381378+00:00 18760
1 2019-03-01 10:58:30.933070+00:00 28140
2 2019-03-01 10:58:45.425421+00:00 35520
3 2019-03-01 10:59:11.588687+00:00 50280
4 2019-03-01 10:59:19.064323+00:00 72420
Run Code Online (Sandbox Code Playgroud)
在尝试使用 Facebook Prophet 时,我收到以下错误:ValueError: Column ds has timezone specified, which is not supported. Remove timezone.我现在尝试从 ds 列中删除时区。您知道如何实现这一目标吗?
df = pd.read_csv(
'wob-2019-ticket-sales.csv',
usecols=['created', 'total_gross'],
parse_dates=['created'],
# date_parser=lambda x: pd.to_datetime(x.rpartition('-')[0])
)
df['y'] = df['total_gross'].cumsum()
df = df.rename(columns={'created': 'ds'})
df = df.drop(columns='total_gross')
df.head()
Run Code Online (Sandbox Code Playgroud) 在运行docker-compose up --build时,我总是遇到此错误消息。有人知道docker-entrypoint文件在做什么吗?
ERROR: for 986991ccdfe1_ubercoach_web_1 Cannot start service web: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"./docker-entrypoint.sh\": permission denied": unknown
ERROR: for web Cannot start service web: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"./docker-entrypoint.sh\": permission denied": unknown
ERROR: Encountered errors while bringing up the project.
Run Code Online (Sandbox Code Playgroud)
码头工人组成:
version: '3'
services:
db:
image: postgres
ports:
- "5432:5432"
web:
build: .
entrypoint: ./docker-entrypoint.sh
env_file: .env
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
Run Code Online (Sandbox Code Playgroud)
Dockerfile: …
我可以在我的生产服务器上运行这个命令而没有任何风险吗?是否会删除所有会话或如何clearsessions影响我的数据库?
我正在尝试在我的会话中保存日期。我总是收到错误Object of type 'datetime' is not JSON serializable。我发现这这里的Django的文档:stored as seconds since epoch since datetimes are not serializable in JSON.
如何将我的保存expiry_date为秒而不是日期时间?
code = social_ticketing_form.cleaned_data['a']
expiry_date = timezone.now() + timezone.timedelta(days=settings.SOCIAL_TICKETING_ATTRIBUTION_WINDOW)
request.session[social_ticketing_cookie_name(request.event)] = {'code': code, 'expiry_date': expiry_date}
Run Code Online (Sandbox Code Playgroud) 我有以下信号.是否有可能像我在这里'堆叠'这两个装饰器一样?
@receiver(signal=charge_succeeded)
@transaction.atomic
def create_influencer_transaction(sender, order, charge, **kwargs):
pass
Run Code Online (Sandbox Code Playgroud)