Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When run docker-compose up I get python: can't open file 'manage.py': [Errno 2] No such file or directory

Tags:

python

docker

This is my Dockerfile:

FROM python:3.6.1

# set working directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# add requirements (to leverage Docker cache)
ADD ./requirements.txt /usr/src/app/requirements.txt

# install requirements
RUN pip install -r requirements.txt

# add app
ADD . /usr/src/app

# run server
CMD python manage.py runserver -h 0.0.0.0

This is my docker-compose.yml:

version: '2.1'

services:

  users-service:
    container_name: users-service
    build: .
    volumes:
      - .:/usr/src/app
    ports:
      - 5001:5000 # expose ports - HOST:CONTAINER

This is structure of my project dir (from which I run my docker commands):

├── docker-compose.yml
├── Dockerfile
├── env
│   ├── bin
│   ├── include
│   ├── lib
│   ├── lib64 -> lib
│   ├── pip-selfcheck.json
│   ├── pyvenv.cfg
│   └── share
├── manage.py
├── project
│   ├── config.py
│   ├── __init__.py
│   └── __pycache__
└── requirements.txt

First I run docker-compose build and get following output:

Building users-service
Step 1/7 : FROM python:3.6.1
 ---> 74145628c331
Step 2/7 : RUN mkdir -p /usr/src/app
 ---> Using cache
 ---> 8b73b9540da2
Step 3/7 : WORKDIR /usr/src/app
 ---> Using cache
 ---> 28d3452f6021
Step 4/7 : ADD ./requirements.txt /usr/src/app/requirements.txt
 ---> Using cache
 ---> e92c334820c2
Step 5/7 : RUN pip install -r requirements.txt
 ---> Using cache
 ---> db7ea8211cd1
Step 6/7 : ADD . /usr/src/app
 ---> 472c303e4297
Removing intermediate container 7ee1b497cde4
Step 7/7 : CMD python manage.py runserver -h 0.0.0.0
 ---> Running in 31ae97876314
 ---> 42c79e68f692
Removing intermediate container 31ae97876314
Successfully built 42c79e68f692
Successfully tagged flaskmicroservicesusers_users-service:latest

And then I run docker-compose up which return error:

Recreating users-service
Attaching to users-service
users-service    | python: can't open file 'manage.py': [Errno 2] No such file or directory
users-service exited with code 2

What I am missing here?

like image 296
Luka Lopusina Avatar asked Jun 22 '17 08:06

Luka Lopusina


People also ask

Does Docker Compose use Python?

Using pip. Note: Docker Compose requires Python 3.6 or later.


3 Answers

As @Fartash said, there is a problem with mounting the folder as volume in ubuntu. In order to resolve the error you can use named volume in docker.

You can simply defining new named volume in docker-compose file as below:

version: '2.1'

services:

  users-service:
    container_name: users-service
    build: .
    volumes:
      - app:/usr/src/app # the volume is defined at the end of this file
    ports:
      - 5001:5000

volumes: # You should add this and the following line
    app: # you can define any name

for more information, you can check out this link.

like image 188
Mostafa Ghadimi Avatar answered Nov 05 '22 00:11

Mostafa Ghadimi


Remove volumes from docker-compose.yml and build again.

version: '2.1'
services:
users-service:
  container_name: users-service
  build: .
  ports:
    - 5001:5000 # expose ports - HOST:CONTAINER

there is an issue with docker-compose on ubuntu. it can't mount the volume. And as I can see you want to mount . to /usr/src/app

You would need to build the image again after you update the code.

like image 23
Fartash Avatar answered Nov 05 '22 02:11

Fartash


Do not run your application in a docker-machine vm by running this eval $(docker-machine env <your-vm>. But if you have, unlink the docker-machine by running eval $(docker-machine env -u)

like image 28
Curtis Avatar answered Nov 05 '22 00:11

Curtis