Docker compose在生成期间引发错误:服务'postgres'生成失败:exec:\“ / bin / sh \”:stat / bin / sh:没有这样的文件或目录“:未知

时间:2019-12-13 09:33:15

标签: django docker docker-compose cookiecutter-django

enter image description here我提取了一个新的cookiecutter django模板,我想使用docker。当我docker-compose -f local.yml build出现此错误时:

  
    

服务'postgres'生成失败:OCI运行时创建失败:container_linux.go:346:启动容器进程导致“ exec:\” / bin / sh \”:统计信息/ bin / sh:无此类文件或目录” :未知

  

研究此问题后,我发现它可能是损坏的图像。因此,我删除了所有容器,图像,并使用以下命令修剪了系统:

docker rm -vf $(docker ps -a -q)
docker rmi -f $(docker images -a -q)
docker system prune

然后我也做了:

docker-compose -f local.yml down
docker-compose -f local.yml up

我重新启动了docker,重新启动了我的计算机。...

当我列出所有容器和图像时,它们都消失了。然后我再次构建它,这使我感到困惑,因为我得到了:

fc7181108d40: Already exists
81cfa12d39e9: Already exists
793d305ca761: Already exists
41e3ced3a2aa: Already exists
a300bc9d5405: Already exists
3c6a5c3830ed: Already exists
fb8c79b24338: Already exists
fcda1144379f: Already exists
476a22a819cc: Downloading [===============>                                   ]  25.23MB/82.14MB
78b36b49bb24: Download complete
6a096a28591f: Download complete
c0cb89b5217b: Download complete
778f1469a309: Download complete
7c4413fcad87: Download complete

所以还有东西存在吗?我假设某些内容没有被删除。然后一切都失败了:

ERROR: Service 'postgres' failed to build: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown

所以我想我的postgres图像出了点问题...我只是不知道还能尝试什么。我有另一个项目,可以与docker和cookiecutter完美配合。因此,我认为重新安装docker不会有所帮助。

我还有什么可以尝试的想法?我不是Docker专家,这几乎是我的故障排除知识的结尾...非常感谢您的帮助,谢谢!

以下是自动创建cookiecutter的结果:

撰写文件:

version: '3'

volumes:
  local_postgres_data: {}
  local_postgres_data_backups: {}

services:
  django:
    build:
      context: .
      dockerfile: ./compose/local/django/Dockerfile
    image: nginx_local_django
    depends_on:
      - postgres
    volumes:
      - .:/app
    env_file:
      - ./.envs/.local/.django
      - ./.envs/.local/.postgres
    ports:
      - "8000:8000"
    command: /start

  postgres:
    build:
      context: .
      dockerfile: ./compose/production/postgres/Dockerfile
    image: nginx_production_postgres
    volumes:
      - local_postgres_data:/var/lib/postgresql/data
      - local_postgres_data_backups:/backups
    env_file:
      - ./.envs/.local/.postgres

Dockerfile:

FROM python:3.7-alpine

ENV PYTHONUNBUFFERED 1

RUN apk update \
  # psycopg2 dependencies
  && apk add --virtual build-deps gcc python3-dev musl-dev \
  && apk add postgresql-dev \
  # Pillow dependencies
  && apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev \
  # CFFI dependencies
  && apk add libffi-dev py-cffi \
  # Translations dependencies
  && apk add gettext \
  # https://docs.djangoproject.com/en/dev/ref/django-admin/#dbshell
  && apk add postgresql-client

# Requirements are installed here to ensure they will be cached.
COPY ./requirements /requirements
RUN pip install -r /requirements/local.txt

COPY ./compose/production/django/entrypoint /entrypoint
RUN sed -i 's/\r$//g' /entrypoint
RUN chmod +x /entrypoint

COPY ./compose/local/django/start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start

WORKDIR /app

ENTRYPOINT ["/entrypoint"]



我的postgres dockerfile

FROM postgres:11.3

COPY ./compose/production/postgres/maintenance /usr/local/bin/maintenance
RUN chmod +x /usr/local/bin/maintenance/*
RUN mv /usr/local/bin/maintenance/* /usr/local/bin \
    && rmdir /usr/local/bin/maintenance


1 个答案:

答案 0 :(得分:1)

如果使用其他Linux发行版,请尝试将其添加到postgres Dockerfile更改apk中。

RUN apk add --no-cache dos2unix
RUN dos2unix YOUR_SCRIPT_NAME
RUN chmod +x YOUR_SCRIPT_NAME

并确保第一行是#!/bin/sh