1

enter image description hereI 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


Micromegas
  • 1,499
  • 2
  • 20
  • 49

1 Answers1

1

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

LinPy
  • 16,987
  • 4
  • 43
  • 57
  • Thanks LinPy! Mind explaining what I'm doing? I'm on a mac not linux and why do I add a shell script comand? And what script name fo you mean. I am confused because this is a cookiecutter template which is supposed to work out of the box. So I though the error is more with my docker/images rather than with the dockerfiles itself? – Micromegas Dec 13 '19 at 11:07
  • 1
    I did not see your postgres dockerfile, but if you have any shell script in thier you need to run dos2unix against it – LinPy Dec 13 '19 at 11:12
  • 1
    so something is wrong in your scripts in `/usr/local/bin/maintenance/*` – LinPy Dec 13 '19 at 11:15
  • you are right.... it doesn't exist.... what is in there normally, can I just create it? Or maybe this dir is created during the COPY command... – Micromegas Dec 13 '19 at 11:18
  • what are you coping from there ? you move every thing after that to /usr/local/bin and then delete the folder /usr/local/bin/maintenance/ – LinPy Dec 13 '19 at 11:20
  • I'm not entirely sure since this is templated.... bunch of shell scripts in there, but it is the same as in another working project.... I added a screenshot – Micromegas Dec 13 '19 at 11:25
  • LinPy thank you so much for your time and help I really appreciate it!! I pulled the project again (like I did many times before) and this time I created a new docker-machine with ```docker-machine create --driver virtualbox dev``` and then ```eval $(docker-machine env dev)``` ..... Then I run the nuild command and now it is running. But I have no idea why this works ¯\_(ツ)_/¯ – Micromegas Dec 13 '19 at 11:55
  • Actually... it is not working.... The container builds but when I go to my localhost it prompts connection refused..... So I can't use it with docker machine – Micromegas Dec 13 '19 at 13:14
  • For future readers: Resetting docker to factory defaults finally solved my issues.... – Micromegas Dec 13 '19 at 13:55