Packages not accessible after build

I’m using docker-compose. My docker-compose.yml file looks like this:

  web:
    image: python:2.7
    restart: always
    build: .
    depends_on:
      - db
    command: /bin/bash /code/start_maxlabs.sh
    ports:
      # - "85:80"
      - "8001:8000"
      - "8002:8005"
    expose:
      - "8000"
    links:
      - db:mysql
    volumes:
      - .:/code
      - /usr/src/app
      - /usr/src/app/static
      - /usr/share/nginx/html
    external_links:
      - wordpress_web_1:localhost

I have a DockerFile like this:

FROM python:2.7
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD environment.yml /code/
ADD requirements.txt /code/
ADD start_maxlabs.sh /code/
RUN chmod +x /code/start_maxlabs.sh
RUN apt-get update
RUN apt-get install -y python-pip python-dev build-essential 
RUN apt-get install -y libmysqlclient-dev gunicorn 
RUN apt-get install -y libcairo2-dev 
RUN apt-get install -y libjpeg62-turbo-dev 
RUN apt-get install -y libpango1.0-dev
RUN apt-get install -y libgif-dev 
RUN apt-get install -y build-essential 
RUN apt-get install -y g++ 
RUN apt-get install -y python-imaging
RUN pip install -U pip
RUN pip install mysql-python
RUN pip install gunicorn
RUN pip install -r requirements.txt
ADD . /code/
ADD maxlabs /code/
ADD webapp /code/

After I build, I have this coming from the container:

/usr/local/bin/gunicorn: No such file or directory

Clearly, I’ve told it to install. During the build process I can see that it successfully installed:

Installing collected packages: beautifulsoup4, html5lib, bleach, boto, bz2file, chardet, static3, dj-static, Django, django-bootstrap3, django-contrib-comments, sqlparse, django-debug-toolbar, django-frontend, django-frontend-skeleton, filebrowser-safe, oauth, flickr-api, future, numpy, scipy, gensim, geopy, grappelli-safe, gunicorn, requests, Pillow, oauthlib, requests-oauthlib, pytz, tzlocal, Mezzanine, nltk, python-dateutil, pandas, PasteDeploy, python-Levenshtein, scikit-learn, smart-open, Unidecode, var-dump
  Found existing installation: gunicorn 19.7.0 (cool seems like it installed at some point then)

Also when I login to the container, the install script works fine. However, there seems to be multiple images available.

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<none>              <none>              a09d3eff40f7        34 seconds ago      1.36 GB
python              2.7                 ca388cdb5ac1        12 days ago         676 MB

The one with none:none seems to have my code and all the packages I told it to install. However, I think from the compose file, the command to run the code “command: /code/start_maxlabs.sh” (which contains the reference to run gunicorn), is trying to be run on the container running on “ca388cdb5ac1”, which I don’t completely understand? The thing that baffles me is that this exact setup works fine in production but not on my local machine. The deal with my production machine, is that it looks totally different when I type docker images and docker ps. I see only a single image : container combination for my Python app.

ubuntu@ip-xxx.xxx.xxx.xxx:~/deploy$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                   PORTS                                               NAMES
40878483163e        nginx:latest        "nginx -g 'daemon off"   8 weeks ago         Up 5 weeks               0.0.0.0:80->80/tcp, 443/tcp, 0.0.0.0:8080->80/tcp   ng01
17fb36d7f6ea        django              "/bin/bash /code/star"   8 weeks ago         Up 5 weeks               0.0.0.0:8001->8000/tcp, 0.0.0.0:8002->8005/tcp      maxlabs
1984101b64ea        mysql               "docker-entrypoint.sh"   8 weeks ago         Exited (1) 5 weeks ago   3306/tcp   

Why does my localhost docker setup create so many containers? So confused :frowning:

it runs your python image instead of your dockerfile, cause you told it, that it should execute image: python:2.7.

But you do not have an image, you just have a Build-Description (a Dockerfile) for your image.
Try to use the build section instead of the image.
Details here:

Thank you @think. I made these updates to my docker-compose file:

  web:
    build:
      context: .
      dockerfile: Dockerfile
    restart: always
    depends_on:
      - db
    command: /bin/bash /code/start_maxlabs.sh
    ports:
      # - "85:80"
      - "8001:8000"
      - "8002:8005"
    expose:
      - "8000"
    links:
      - db:mysql
    volumes:
      - .:/code
      - /usr/src/app
      - /usr/src/app/static
      - /usr/share/nginx/html

Then from here I ran these commands to remove all images and containers:

docker rm $(docker ps -a -q)
docker rmi $(docker images -q)

Finally, I recreated my images/containers with these commands:

docker-compose build
docker-compose up

From here, I still run into this problem in my logs:

web_1  | /code/start_maxlabs.sh: line 6: /usr/local/bin/gunicorn: No such file or directory

when you search your web image with docker images, is it there?
When you try to execute it by hand via 'docker run -ti your_web_image gunicorn` does it work?

Well sort of, what do you make of this:

Davids-MacBook-Pro-4:web davidyerrington$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
web_web             latest              a834dbed32c0        14 minutes ago      182 MB
<none>              <none>              34179ad76776        14 minutes ago      2.3 GB
<none>              <none>              636c18d164e2        18 hours ago        182 MB
<none>              <none>              a26bcc79d927        18 hours ago        2.3 GB
<none>              <none>              b40765f66449        36 hours ago        182 MB
<none>              <none>              e5b047e9e383        37 hours ago        2.3 GB
python              2.7                 ca388cdb5ac1        2 weeks ago         676 MB
nginx               latest              6b914bbcb89e        2 weeks ago         182 MB
mysql               latest              22be5748ecbe        2 weeks ago         406 MB

When I attempt on these:

$ docker run -ti  a834dbed32c0  gunicorn
docker: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"gunicorn\": executable file not found in $PATH".

$ docker run -ti  34179ad76776   gunicorn
usage: gunicorn [OPTIONS] [APP_MODULE]
gunicorn: error: No application module specified.

doesn’t it already say, that you cannot invoke gunicorn without an application module. Much better than the No such file or directory from our first try. :slight_smile: