skip to Main Content

I have a simple Dockerfile

FROM python:3.8-slim-buster

RUN apt-get update && apt-get install

RUN apt-get install -y 
    curl 
    gcc 
    make 
    python3-psycopg2 
    postgresql-client 
    libpq-dev

RUN mkdir -p /var/www/myapp
WORKDIR /var/www/myapp
COPY . /var/www/myapp

RUN chmod 700 ./scripts/*.sh

And an associated docker-compose file

version: "3"
volumes:
  postgresdata:
services:
  myapp:
    image: ralston3/myapp_api:prod-latest
    tty: true
    command: /bin/bash -c "/var/www/myapp/scripts/myscript.sh && echo 'hello world'"
    ports:
      - 8000:8000
    volumes:
      - .:/var/www/myapp
    environment:
      SOME_ENV_VARS=SOME_VARIABLE
      # ... more here
    depends_on:
      - redis
      - postgresql
# ... other docker services defined below

When I run docker-compose up via:

docker-compose up -f /path/to/docker-compose.yml up 

My myapp container/service fails with myapp_myapp_1 exited with code 127 with another error mentioning myapp_1 | /bin/sh: 1: /var/www/myapp/scripts/myscript.sh: not found

Further, if I exec into the myapp container via docker exec -it {CONTAINER_ID} /bin/bash I can clearly see that all of my files are there. I can literally run the /var/www/myapp/scripts/myscript.sh and it works fine.

However, there seems to be some issue with docker-compose (which could totally be my mistake). But I’m just confused as to how I can exec into the container and clearly see the files there. But docker-compose exists with 127 saying "No such file or directory".

3

Answers


  1. You are bind mounting the current directory into "/var/www/myapp" so it may be that your local directory is "hiding/overwriting" the container directory. Try removing the volumes declaration for you myapp service and if that works then you know it is the bind mount causing the issue.

    Login or Signup to reply.
  2. Unrelated to your question, but a problem you will also encounter: you’re installing Python a second time, above and beyond the version pre-installed in the python Docker image.

    Either switch to debian:buster as base image, or don’t bother installing antyhign with apt-get and instead just pip install your dependencies like psycopg.

    See https://pythonspeed.com/articles/official-python-docker-image/ for explanation why you don’t need to do this.

    Login or Signup to reply.
  3. in my case there were 2 stages: builder and runner.

    I was getting an executable in builder and running that exe using the alpine image in runner.

    My mistake here was that I didn’t use the alpine version for the builder. Ex. I used golang:1.20 but when I used golang:1.20-alpine the problem went away.

    Make sure you use the correct version and tag!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search