Reputation: 1689
I pulled a fresh cookiecutter django template and I want to use docker. When I do docker-compose -f local.yml build
I get this 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
Researching the problem I found out that it could be corrupted images. So I deleted all containers, images and pruned the system with:
docker rm -vf $(docker ps -a -q)
docker rmi -f $(docker images -a -q)
docker system prune
Then I also did:
docker-compose -f local.yml down
docker-compose -f local.yml up
I restarted docker, restarted my computer....
When I list all containers and images they are all gone. Then I build it again and this confuses me, because I get:
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
So there is still something that exists? I assume something is not getting deleted. Then everything fails with:
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
So I guess something is wrong with my postgres image... I just don't know what else to try. I have another project which works perfectly fine with docker and cookiecutter. Thus I don't think reinstalling docker will help.
Any ideas on what else I could try? I'm not a docker expert and this is pretty much the end of my troubleshoot knowledge... Help is greatly appreciated, thanks!
Following is from automatic creation of cookiecutter:
Compose file:
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"]
My 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
Upvotes: 1
Views: 5660
Reputation: 18578
try to add this to your postgres Dockerfile change apk if you use some other linux distro
RUN apk add --no-cache dos2unix
RUN dos2unix YOUR_SCRIPT_NAME
RUN chmod +x YOUR_SCRIPT_NAME
and make sure the first line is #!/bin/sh
Upvotes: 1