我正在学习如何在 Django 中使用 docker。所以第一步是你设置Dockerfile和这里是文件的内容。
FROM python:3.8.0-alpine
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip install -r requirements.txt
# copy project
COPY . /usr/src/app/
Run Code Online (Sandbox Code Playgroud)
另一个文件docker-compose.yml下面的文件内容
version: '3.7'
services:
web:
build: ./project
command: python manage.py runserver 0.0.0.0:8000
volumes:
- ./project/:/usr/src/app/
ports:
- 8000:8000
env_file:
- ./.env.dev
Run Code Online (Sandbox Code Playgroud)
现在这两个文件位于文件夹中,该文件夹docker还有我的 django 项目文件夹,称为project保持简单:)
当我运行时,docker-compose build我得到了错误 …
试图在gunicorn上运行两个站点来编辑服务
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/webapps/kenyabuzz
ExecStart=/home/ubuntu/webapps/djangoenv/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/webapps/kenyabuzz/kb.sock kb.wsgi:application
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
至
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/webapps/kenyabuzz
WorkingDirectory=/home/ubuntu/webapps/uganda_buzz
ExecStart=/home/ubuntu/webapps/djangoenv/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/webapps/kenyabuzz/kb.sock kb.wsgi:application
ExecStart=/home/ubuntu/webapps/djangoenv/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/webapps/uganda_buzz/ug.sock kb.wsgi:application
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
日志显示ExecStart无法复制
ubuntu@ip-172-31-17-122:~$ sudo systemctl status gunicorn
? gunicorn.service - gunicorn daemon
Loaded: error (Reason: Invalid argument)
Active: active (running) since Tue 2017-02-14 09:36:52 EAT; 35s ago
Main PID: 26150 (gunicorn)
CGroup: /system.slice/gunicorn.service
??26150 /home/ubuntu/webapps/djangoenv/bin/python /home/ubuntu/webapps/djangoenv/bin/gunicorn --workers 3 …Run Code Online (Sandbox Code Playgroud) 我有一个 keras 模型,其布局如下
def keras_model(x_train, y_train, x_test, y_test):
model = Sequential()
model.add(Dense(128, input_dim=x_train.shape[1], activation='relu'))
model.add(Dense(256,activation='relu'))
model.add(Dense(512,activation='relu'))
model.add(Dense(256,activation='relu'))
model.add(Dense(128,activation='relu'))
#model.add(Dense(10,activation='relu'))
model.add(Dense(y_train.shape[1], activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam')
monitor = EarlyStopping(monitor='val_loss', min_delta=1e-3, patience=5, verbose=1, mode='auto')
checkpointer = ModelCheckpoint(filepath="best_weights.hdf5", verbose=0, save_best_only=True) # save best model
model.fit(x_train ,y_train, validation_data=(x_test, y_test),callbacks=[monitor,checkpointer], verbose=2,epochs=1000)
model.load_weights('best_weights.hdf5') # load weights from best model
return model
Run Code Online (Sandbox Code Playgroud)
使用来自开放式健身房推杆游戏的数据进行训练,并保存模型。下一步是使用训练好的模型进行预测
from keras.models import load_model
model = load_model('data/model-v0.h5')
action = random.randrange(0,2)
import gym
env = gym.make("CartPole-v0")
env.reset()
>>> array([ 0.02429215, -0.00674185, -0.03713565, -0.0046836 ])
import random
action …Run Code Online (Sandbox Code Playgroud) 我正在设置一个 django 项目并尝试将 docker 与它一起使用。它可能依赖于使用 postgis 的 gdal。
这是docker文件
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY . /code/
RUN pip install -r requirements.txt
Run Code Online (Sandbox Code Playgroud)
和需求文件
Django==2.1.5
psycopg2==2.7.6.1
gdal==2.2.3
Run Code Online (Sandbox Code Playgroud)
当它到达 gdal 时,它会抛出此错误
FileNotFoundError: [Errno 2] No such file or directory: 'gdal-config': 'gdal-config'
Run Code Online (Sandbox Code Playgroud)
但是这是我已经在本地工作的东西
(pw) sam@sam-Lenovo-G51-35:~/code/pw$ gdal-config --version
2.2.3
Run Code Online (Sandbox Code Playgroud)
我确实尝试查看是否可以gdal-config通过将 docker 文件编辑为此来使用 run进行设置
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
RUN apt-get install libgdal-dev
RUN export CPLUS_INCLUDE_PATH=/usr/include/gdal
RUN export C_INCLUDE_PATH=/usr/include/gdal
WORKDIR /code
COPY . /code/
RUN …Run Code Online (Sandbox Code Playgroud) 尝试将文件从一个服务器rsync到另一个服务器获取
ubuntu@xx-xxx-xx-xx-xx:~$ rsync -i "xxxxxXXX.pem" -anv webapps ubuntu@xx.xx.xxx.xx:/home/ubuntu/
Permission denied (publickey).
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.1]
Run Code Online (Sandbox Code Playgroud)
我可以用ssh进入服务器 ssh -i "xxxxxxx.pem" ubuntu@xx.xxx.xxx.xx
密钥的权限是 600
-rw------- 1 ubuntu ubuntu 1696 Feb 1 06:00 xxxxxxxx.pem
Run Code Online (Sandbox Code Playgroud) 我正在尝试django-location-field使用python3安装在Django 2.1.2版上。我将其安装并添加location_field.apps.DefaultConfig到设置中,然后弹出错误消息提示缺少的软件包gdal。
python3 manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7efbf9f56d90>
Traceback (most recent call last):
...
File "/home/samuel/Documents/code/DECOMAGNA/decomagna/inventory/models.py", line 3, in <module>
from django.contrib.gis.geos import Point
...
from django.contrib.gis import gdal
...
File "/home/samuel/.local/lib/python3.6/site-packages/django/contrib/gis/gdal/prototypes/ds.py", line 9, in <module>
from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
File "/home/samuel/.local/lib/python3.6/site-packages/django/contrib/gis/gdal/libgdal.py", line 43, in <module>
% '", "'.join(lib_names)
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal", "GDAL", "gdal2.2.0", "gdal2.1.0", "gdal2.0.0", "gdal1.11.0", "gdal1.10.0", "gdal1.9.0"). Is GDAL …Run Code Online (Sandbox Code Playgroud)