小编rfj*_*001的帖子

将用户添加到Docker容器

我有一个docker容器,里面运行着一些进程(uwsgi和celery).我想为这些进程创建一个芹菜用户和一个uwsgi用户以及他们都属于的工作组,以便分配权限.

我尝试添加RUN adduser uwsgiRUN adduser celery我的Dockerfile,但这导致问题,因为这些命令提示输入(我已经发布了下面的构建响应).

将用户添加到Docker容器以便为容器中运行的工作程序设置权限的最佳方法是什么?

我的Docker镜像是从官方的Ubuntu14.04基础构建的.

以下是运行adduser命令时Dockerfile的输出:

Adding user `uwsgi' ...
Adding new group `uwsgi' (1000) ... 
Adding new user `uwsgi' (1000) with group `uwsgi' ... 
Creating home directory `/home/uwsgi' ...
Copying files from `/etc/skel' ... 
[91mEnter new UNIX password: Retype new UNIX password: [0m 
[91mpasswd: Authentication token manipulation error
passwd: password unchanged
[0m 
[91mUse of uninitialized value $answer in chop at /usr/sbin/adduser line 563.
[0m 
[91mUse of uninitialized value $answer in pattern match …
Run Code Online (Sandbox Code Playgroud)

linux ubuntu dockerfile

237
推荐指数
7
解决办法
24万
查看次数

Django反向访问器冲突

所以在这里我遇到了很多反向访问冲突的问题.我虽然我非常聪明并且干我的模型结构能够将user.profile用于任何类型的配置文件,或者将provider.profile用于任何一个提供程序......但是我在整个地方都遇到了冲突错误.

介意看看我的代码并查看是否有任何方法可以让我这样做,这样我仍然可以只使用user.profile而无需知道哪种类型的配置文件(以及同样的provider.profile,而无需知道哪种类型的供应商)?或者只是告诉我,我正在尝试做的事情是不可能的,还有更好的解决方案?

class BaseProfileModel(models.Model):
    '''
    An abstract model class containing fields and/or methods relevant to all users.
    '''
    user = models.OneToOneField(User, related_name="profile", primary_key=True)
    phone = PhoneNumberField(verbose_name=_("Phone Number"))
    pic = models.ImageField(upload_to=get_upload_file_name,
                            width_field="width_field",
                            height_field="height_field",
                            null=True,
                            blank=True,
                            verbose_name=_("Profile Picture")
                           )
    height_field = models.PositiveIntegerField(null=True, default=0)
    width_field = models.PositiveIntegerField(null=True, default=0)
    thumbnail = ImageSpecField(source='pic',
                                   processors=[ResizeToFill(180,180)],
                                   format='JPEG',
                                   options={'quality': 100})
    bio = models.TextField(
        verbose_name=_("About"),
        default="",
        blank=True,
        max_length=800
    )

    class Meta:
        abstract = True

    def __str__(self):
        if self.user.email:
            return self.user.email
        else:
            return self.user.username

    @property
    def is_provider(self):
        return hasattr(self, 'provider') …
Run Code Online (Sandbox Code Playgroud)

django

42
推荐指数
1
解决办法
4万
查看次数

试图在写入事务之外修改对象

所以我不知道为什么我会收到这个错误.错误消息如下:

*由于未捕获的异常'RLMException'而终止应用程序,原因是:'尝试修改写事务之外的对象 - 首先在RLMRealm实例上调用beginWriteTransaction.*第一次抛出调用堆栈:(0x2f7b0f83 0x39f61ccf 0xc46ef 0xc3c23 0xc0c9d 0xb3e73 0x3a449833 0x3a449ded 0x3a44a297 0x3a45c88d 0x3a45cb21 0x3a58bbd3 0x3a58ba98)libc ++ abi.dylib:以NSException类型的未捕获异常终止

并在执行此代码时抛出.

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    UITextField * alertTextField = [alertView textFieldAtIndex:0];
    if (![self.chatSession.theirAlias isEqualToString:alertTextField.text]) {
        self.sender = alertTextField.text;
        dispatch_queue_t queue = ((AppDelegate *)[UIApplication sharedApplication].delegate).queueForWrites;
        dispatch_async(queue, ^{
            [[RLMRealm defaultRealm] beginWriteTransaction];
            self.chatSession.myAlias = alertTextField.text; // This is the line where the error is thrown
            [[RLMRealm defaultRealm] commitWriteTransaction];
        });
    } else {
        [self promptForAliasAfterRejection];
    }
}
Run Code Online (Sandbox Code Playgroud)

我很清楚我在写一个事务中写作.这是Realm的错误吗?或者我错过了什么......?

realm uialertview ios

11
推荐指数
1
解决办法
1万
查看次数

Docker端口转发

我试图在docker容器中运行我的django应用程序.我正在使用uWSGI来为django应用程序提供服务,并且还有一个芹菜工作者在后台运行.这些过程由supervisord启动.

我遇到的问题是我无法在端口上看到我希望看到它的应用程序.我暴露端口8080并在8080上运行uwsgi进程,但无法在浏览器的ip地址找到我的应用程序$(boot2docker ip):8080.我刚收到谷歌Chrome浏览器'这个网页不可用'.(我使用的是Mac,所以我需要获取boot2docker的ip地址).容器显然正在运行,并报告我的uwsgi和芹菜进程也都成功运行.

当我跑步时,docker exec CONTAINER_ID curl localhost:8080我会得到一个回应

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    21    0    21    0     0   3150      0 --:--:-- --:--:-- --:--:--  3500
Run Code Online (Sandbox Code Playgroud)

...所以看起来容器正在接受端口8080上的连接.

当我跑步时,docker exec CONTAINER_ID netstat -lpn |grep :8080我得到了tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 11/uwsgi

当我跑步时,docker inspect CONTAINER_ID我得到以下内容:

[{
    "AppArmorProfile": "",
    "Args": [
        "-c",
        "/home/docker/code/supervisor-app.conf"
    ],
    "Config": {
        "AttachStderr": true,
        "AttachStdin": false,
        "AttachStdout": true, …
Run Code Online (Sandbox Code Playgroud)

django ubuntu http docker

8
推荐指数
1
解决办法
7663
查看次数

将参数传递给Django CreateView

我正在尝试实现一个约会制作应用程序,用户可以在其中创建与预先存在的类相关联的会话.我想要做的是使用django CreateView创建一个会话而不要求用户提供相关的类,同时在会话中为会话分配一个类.我试图通过在url中传入类的pk来做到这一点,这样我就可以在CreateView中查找类并将类分配给会话.

我无法弄清楚的是如何做到这一点.我猜在模板中我希望<a href="{% url create_sessions %}?class={{ object.pk }}>Create Session</a>在类的DetailView中有类似的东西,并且在我的urls.py文件中包含该行的url url(r'^create-sessions?class=(\d+)/$', CreateSessionsView.as_view(), name = 'create_sessions'),但我对django很新,并且不完全了解这里的位置参数被发送到我的CBV以及如何使用它.

我将课程保存到会话的计划是将form_valid我的CBV 覆盖为:

def form_valid(self, form): form.instance.event = event return super(CreateSessionsView, self).form_valid(form)

如果这是明显不正确的,请告诉我.

谢谢!

django django-views django-class-based-views

7
推荐指数
1
解决办法
6354
查看次数

ValueError:不要在调用reverse()时混用*args和**kwargs!

我正在尝试render_to_response将我的视图的渲染响应返回给ajax调用,但是我得到以下错误,我真的不明白...

Internal Server Error: /schedules/calendar/2014/10/1/
Traceback (most recent call last):
  File "/blahblahblah/django/core/handlers/base.py", line 111, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/blahblahblah/schedules/views.py", line 229, in month_view
    return render_to_string(template, data)
  File "/blahblahblah/django/template/loader.py", line 172, in render_to_string
    return t.render(Context(dictionary))
  File "/blahblahblah/django/template/base.py", line 148, in render
    return self._render(context)
  File "/blahblahblah/django/template/base.py", line 142, in _render
    return self.nodelist.render(context)
  File "/blahblahblah/django/template/base.py", line 844, in render
    bit = self.render_node(node, context)
  File "/blahblahblah/django/template/debug.py", line 80, in render_node
    return node.render(context)
  File "/blahblahblah/django/template/defaulttags.py", line 444, in render
    url = …
Run Code Online (Sandbox Code Playgroud)

python django django-views

4
推荐指数
1
解决办法
4628
查看次数

Amazon S3 + Docker - "403 Forbidden:请求时间和当前时间之间的差异太大"

我正在尝试使用从Amazon S3提供的静态文件在docker容器中运行我的django应用程序.当我RUN $(which python3.4) /home/docker/code/vitru/manage.py collectstatic --noinput在Dockerfile中运行时,我从Amazon S3获得403 Forbidden错误,并带有以下响应XML

<?xml version="1.0" encoding="UTF-8"?>
<Error>
    <Code>RequestTimeTooSkewed</Code>
    <Message>The difference between the request time and the current time is too large.</Message>
    <RequestTime>Sat, 27 Dec 2014 11:47:05 GMT</RequestTime>
    <ServerTime>2014-12-28T08:45:09Z</ServerTime>
    <MaxAllowedSkewMilliseconds>900000</MaxAllowedSkewMilliseconds>
    <RequestId>4189D5DAF2FA6649</RequestId>
    <HostId>lBAhbNfeV4C7lHdjLwcTpVVH2snd/BW18hsZEQFkxqfgrmdD5pgAJJbAP6ULArRo</HostId>
</Error>
Run Code Online (Sandbox Code Playgroud)

我的docker容器正在运行Ubuntu 14.04 ...如果这有任何区别.我也使用uWSGI运行应用程序,没有nginx或apache或任何其他类型的反向代理服务器.

当文件被提供给站点时,我也在运行时收到错误.

试图解决方案

其他stackoverflow问题使用S3报告了类似的错误(没有特别与Docker一起使用)并且他们说这个错误是在你的系统时钟不同步时引起的,并且可以通过运行来修复

sudo service ntp stop
sudo ntpd -gq
sudo service ntp start
Run Code Online (Sandbox Code Playgroud)

所以我将以下内容添加到我的Dockerfile中,但它没有解决问题.

RUN apt-get install -y ntp
RUN ntpd -gq
RUN service ntp start
Run Code Online (Sandbox Code Playgroud)

在构建docker镜像之前,我还尝试在本地计算机上同步时间sudo ntpd -gq,但是这也没有用.

Dockerfile

FROM ubuntu:14.04

# Get …
Run Code Online (Sandbox Code Playgroud)

django ubuntu amazon-s3 amazon-web-services docker

4
推荐指数
2
解决办法
2555
查看次数

Django ALLOWED_HOSTS与ELB HealthCheck

我在Elastic Beanstalk上部署了一个django应用程序.我的应用程序的HealthCheck保持失败,因为ELB HealthCheck的IP未包含在我的ALLOWED_HOSTS设置变量中.

如何修改ALLOWED_HOSTS以使HealthCheck通过?我只是传递显式IP地址,但我相信这会改变,因此每当IP更改时,检查都会再次失败,直到我添加新IP.

django amazon-ec2 amazon-web-services amazon-elb amazon-elastic-beanstalk

4
推荐指数
3
解决办法
2002
查看次数

响应式Bootstrap Navbar

我正在尝试为我的网站创建一个Navbar,左侧是下拉菜单,中间是图像,右侧是可折叠项目.我使用较少的bootstrap来设置导航栏的样式,但我遇到了麻烦.

我已经搜索了Stack溢出寻找方法来完成这项工作,就像这个问题一样,但那里的解决方案并不适用于我.我似乎无法将我的图像排成一行,以便其水平轴以下拉菜单,可折叠项和导航栏容器为中心.当我尝试上述链接中的解决方案时,通过最大化其位置固定将图像从页面流中取出,它总是出现在导航栏下方.我可以通过搞乱CSS属性来解决这个问题,但是一旦我调整窗口大小,事情就会变得很糟糕.

是否有一种方法(可能使用更少)来设置引导导航栏的样式,这样无论窗口的大小是多少,我左边都有一个项目,中间是图像,右边是项目,所有这些都共享一个共同的水平中心轴与导航栏?

编辑

好吧,所以我改变了主意,决定只在左边添加一些链接,中心还有一个图像,右边有一些链接.当屏幕变小时,我希望链接向右折叠,为菜单提供切换按钮.折叠工作正常,但当链接在屏幕上时,我希望它们在导航栏中与图像一起水平居中.现在,图像部分位于导航栏中,部分位于外部.当链接以较小的屏幕尺寸折叠时,我还希望图像向左滑动.这是我现在的代码:

只是注意我使用django来提供html,因此图像src的语法.

#logo-with-slogan {
  max-width: 35%;
  padding: 3% 0 3% 0;
}

.navbar-brand {
  position: absolute;
  width: 100%;
  left: 0;
  text-align: center;
  margin: auto;
}
Run Code Online (Sandbox Code Playgroud)
<nav class="navbar navbar-default" role="navigation">
  <div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
  </div>
  <a class="navbar-brand" href="#">
    <img id="logo-with-slogan" src="{% static " img/LogoWslogan.jpg " %}" />
  </a>
  <div class="navbar-collapse collapse">
    <ul class="nav navbar-nav navbar-left">
      <li><a href="#itemonelink">Item One</a></li>
      <li><a href="#itemtwolink">Item Two</a></li>
    </ul>
    <ul class="nav navbar-nav …
Run Code Online (Sandbox Code Playgroud)

html css less twitter-bootstrap

2
推荐指数
1
解决办法
2万
查看次数

图Python 3兼容?

我有一个运行python 3.4的django应用程序,我想使用Fig帮助为我的应用程序的组件设置dockerized容器.当我运行时,fig up我收到以下错误:

Recreating app_db_1...
Recreating app_search_1...
Creating app_web_1...
Traceback (most recent call last):
  File "/usr/local/Cellar/fig/1.0.1/libexec/bin/fig", line 9, in <module>
    load_entry_point('fig==1.0.1', 'console_scripts', 'fig')()
  File "/usr/local/Cellar/fig/1.0.1/lib/python2.7/site-packages/fig-1.0.1-py2.7.egg/fig/cli/main.py", line 31, in main
  File "/usr/local/Cellar/fig/1.0.1/lib/python2.7/site-packages/fig-1.0.1-py2.7.egg/fig/cli/docopt_command.py", line 21, in sys_dispatch
  File "/usr/local/Cellar/fig/1.0.1/lib/python2.7/site-packages/fig-1.0.1-py2.7.egg/fig/cli/command.py", line 28, in dispatch
  File "/usr/local/Cellar/fig/1.0.1/lib/python2.7/site-packages/fig-1.0.1-py2.7.egg/fig/cli/docopt_command.py", line 24, in dispatch
  File "/usr/local/Cellar/fig/1.0.1/lib/python2.7/site-packages/fig-1.0.1-py2.7.egg/fig/cli/command.py", line 56, in perform_command
  File "/usr/local/Cellar/fig/1.0.1/lib/python2.7/site-packages/fig-1.0.1-py2.7.egg/fig/cli/main.py", line 427, in up
  File "/usr/local/Cellar/fig/1.0.1/lib/python2.7/site-packages/fig-1.0.1-py2.7.egg/fig/project.py", line 174, in up
  File "/usr/local/Cellar/fig/1.0.1/lib/python2.7/site-packages/fig-1.0.1-py2.7.egg/fig/service.py", line 199, in recreate_containers
  File "/usr/local/Cellar/fig/1.0.1/lib/python2.7/site-packages/fig-1.0.1-py2.7.egg/fig/service.py", line 176, in create_container
  File …
Run Code Online (Sandbox Code Playgroud)

python django docker fig

2
推荐指数
1
解决办法
326
查看次数

部署Django应用程序

所以我是网络开发领域的初学者.我一直在研究django应用程序,现在我的应用程序运行得很好,我正盯着部署的怪物的脸,并想知道要采取的方向.

我的应用程序运行Django 1.7和Python 3.4.我想将Postgre与Postgis一起用作我的数据库.我原本打算使用他们的Elastic Beanstalk PaaS服务来使用Amazon AWS进行部署,尽管现在我想知道像Heroku这样的东西对我来说可能对我来说更好.我需要我的应用程序轻松扩展,没有我不得不深入到太多的配置,我很可能会搞砸.

我想知道哪个服务最适合新员工开发人员部署运行我上面提到的平台的应用程序.Heroku似乎比AWS更容易使用,但我担心Heroku的定价会比使用AWS更快.随着我越来越熟悉维护Web应用程序的过程和/或我的需求变化,最初使用一个服务进行部署并迁移到另一个服务有多困难?

任何建议或信息,以帮助我决定服务,将非常感谢.

python django postgresql heroku amazon-web-services

1
推荐指数
1
解决办法
656
查看次数