testdrivenio / testdriven-app

34 stars 18 forks source link

Error running Flask entrypoint #25

Closed darr1s closed 6 years ago

darr1s commented 6 years ago

I have cloned this repo and tried a few different branch, test3~test6. It all have this issue that I can't seem to fixed. I've tried to change it into RUN, ENTRYPOINT.

Creating users-db ... done
Creating users-service ... error
WARNING: The REACT_APP_API_GATEWAY_URL variable is not set. Defaulting to a blank string.
WARNING: The REACT_APP_EXERCISES_SERVICE_URL variable is not set. Defaulting to a blank string.
WARNING: The REACT_APP_SCORES_SERVICE_URL variable is not set. Defaulting to a blank string.
Creating network "testdrivenapp_default" with the default driver
Creating exercises-db ... 
Creating users-db ... 
Creating scores-db ... 
Creating users-service ... 

ERROR: for users-service  Cannot start service users-service: OCI runtime create failed: container_linux.go:296: starting container process caused "exec: \"./entrypoint.sh\": stat ./entrypoint.sh: no such file or directory": unknown
eduardoluizgs commented 6 years ago

I´ve the similar problem:

ERROR: for users-service Cannot start service users-service: OCI runtime create failed: container_linux.go:296: starting container process caused "exec: \"./entrypoint.sh\": permission denied": unknown

vinnyA3 commented 6 years ago

I have the exact same issue as @bal699 and @bin4ryio :

ERROR: for users-service  Cannot start service users-service: OCI runtime create failed: container_linux.go:296: starting container process caused "exec: \"./entrypoint.sh\": stat ./entrypoint.sh: no such file or directory": unknown
ERROR: Encountered errors while bringing up the project.

I am currently following PART 1 of the course; more specifically, I am getting the users-service to work (https://testdriven.io/part-one-docker-config). However, the preceding error is not the first I have come across. After initially creating the docker-compose-dev.yml and Dockerfile (copied verbatim), I proceeded to build and run the container--in the foreground to monitor any errors: docker-compose -f docker-compose-dev.yml up.

Unfortunately, the build failed and returned with an error stating that CMD python manage.py runserver -h 0.0.0.0 has failed due to manage.py not being found. Now, since entrypoint.sh uses the previously stated command in its script, this leads me to believe the project's build failure lies with the unresolved manage.py file. I'll continue to debug the issue when time permits. Hopefully, we can work out the bug.

aside: Could this be a issue with docker-machine? Is it possible that docker-machine isn't correctly mapping the current project dir into the vm? See cookiecutter-django issue #895

[SOLVED]: Turns out the files in my local user-service directory weren't copied over into the remote machine. To fix the "exec: \"./entrypoint.sh\": stat ./entrypoint.sh: no such file or directory" error, I utilized scp to copy the files:

docker-machine scp -r ./users-service/ testdriven-dev:/tmp
docker-machine ssh testdriven-dev sudo cp -r /tmp/users-service /path/to/users-service

The solution was found here: https://github.com/docker/machine/issues/1577

Note that I first had to copy the files to /tmp on the remote machine; the reason: failed permissions.

darr1s commented 6 years ago

For a workaround, use sudo docker-compose instead.

vinnyA3 commented 6 years ago

@bin4ryio So, I added sudo and it did in fact start the new, containerized flask app( I was able to request the json data returned from 0.0.0.0/user/ping) ; however, I was still running into an error when trying to connect to the app through the docker-machine vm (http://docker_machine_ip:5001/users/ping). I did find an answer though. Upon ssh-ing into the "remote" machine, I found that the files contained in my local user-service directory were not copied over into the remote directory. Thus, resulting in the ./entrypoint | manage.py: no such file or directory error. The fix was to use scp to manually copy the files to the vm. I'm don't think there is a discrepancy in my docker-compose.yml file, but rather I believe the problem lies with docker-machine ( at least how I'm running it anyways ).

eduardoluizgs commented 6 years ago

[SOLVED]

After a little analysis, I noticed that the application files inside the image were being replaced by the volume files created in the docker-compose-dev.yml file:

volumes:
 - './users-service:/usr/src/app'

When this occurs we get the error while executing the container:

"exec: \" ./ entrypoint.sh \ ": stat ./entrypoint.sh: no such file or directory" unknow

By removing the volume from the compose file, the above error no longer occurred. However, the application still did not work.

Looking a bit more, I noticed that I was using the flask client implementation, according to the article. The command inside the entrypoint.sh should then change from python manage.py runserver -h 0.0.0.0 to python manage.py run -h 0.0.0.0, otherwise the application did not work.

I also added execute permission to the entrypoint.sh file, both in the image build and in the container initialization and simplified the Dockerfile-dev file, as follows:

FROM python:3.6.3

# install environment dependencies
RUN apt-get update -yqq \
  && apt-get install -yqq --no-install-recommends \
    netcat vim \
  && apt-get -q clean

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

# add app
ADD . /usr/src/app

# install requirements
RUN pip install -r requirements.txt

# run server
CMD ["sh","-c","chmod 777 /usr/src/app/entrypoint.sh && /usr/src/app/entrypoint.sh"]

Or alternatively you can change the path of entrypoint.sh file:

...

# install requirements
RUN pip install -r requirements.txt

# set file permissions
ADD ./entrypoint.sh /tmp/entrypoint.sh
RUN chmod 777 /tmp/entrypoint.sh

# run server
CMD ["/tmp/entrypoint.sh"]

After these adjustments the container has been up and running normally. ;)

PS: I'm using docker on mac os. Running the container on ubuntu server did not identify this problem. Maybe it's something related to docker machine or file permissions on mac.

vinnyA3 commented 6 years ago

@bal699 I still have to look into and implement what you suggested. Are you able to update the code without having to restart the container now? I'm still new to Docker as a whole, but I thought volumes were necessary to mount your code into the the container.

eduardoluizgs commented 6 years ago

@vinnyA3, Until this step, I still can not update the changes in my local code automatically into the container. And yes, volume is necessary for this. I'll look a bit more to understand why the code is not yet automatically updated and will return you.

PS: I'm using docker on mac os.

mjhea0 commented 6 years ago

I am getting ready to launch a new version of the course that addresses this issue. Can I close this?

vinnyA3 commented 6 years ago

Fine by me @mjhea0 . Looking forward to the unveiling of the new course!

ghost commented 6 years ago

I'm having the exact same problem. Just formatted my computer and can't make it work.

Docker-machine version 0.15.0

Docker version 18.05.0 ce build f150324

Windows 10 with Hyper-V enabled

This is the content of my docker-compose-dev.yml

version: '3.3'

services:

  users:
    container_name: users
    build:
      context: ./services/users
      dockerfile: Dockerfile-dev
    volumes:
      - './services/users:/usr/src/app'
    ports:
      - 5001:5000
    environment:
      - FLASK_APP=project/__init__.py
      - FLASK_DEBUG=1

My Dockerfile-dev:

FROM python:3.7

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

# install requirements
COPY . /usr/src/app
RUN pip install -r requirements.txt

# run server
CMD ["./entrypoint.sh"]

My entrypoint.sh

#!/usr/bin/env sh

python manage.py run -h 0.0.0.0

And the error:

$ docker-compose -f docker-compose-dev.yml up --build
Removing users
Building users
Step 1/6 : FROM python:3.7
 ---> ce54ff8f2af6
Step 2/6 : RUN mkdir -p /usr/src/app
 ---> Using cache
 ---> baad3d95943d
Step 3/6 : WORKDIR /usr/src/app
 ---> Using cache
 ---> 785cf8a98066
Step 4/6 : COPY . /usr/src/app
 ---> Using cache
 ---> 133bf8be6979
Step 5/6 : RUN pip install -r requirements.txt
 ---> Using cache
 ---> ec0837430a00
Step 6/6 : CMD ["./entrypoint.sh"]
 ---> Using cache
 ---> 93ef097d103e

Successfully built 93ef097d103e
Successfully tagged testdriven_users:latest
Recreating 00242808eea8_users ... error

ERROR: for 00242808eea8_users  Cannot start service users: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"./entrypoint.sh\": stat ./entrypoint.sh: no such file or directory": unknown

ERROR: for users  Cannot start service users: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"./entrypoint.sh\": stat ./entrypoint.sh: no such file or directory": unknown
ERROR: Encountered errors while bringing up the project.

It seems to be a problem with the volumes option of docker-compose-dev.yml file.

The solution provided by @bal699 did not work.

mjhea0 commented 6 years ago

@werneckbh are you using Docker Machine? If so, try it without it.

ghost commented 6 years ago

@mjhea0 , thank you for your suggestion but it did not work running without docker-machine. The server did start, but the host would become unaccessible (connection refused).

After running several scenarios, I finally got it working.

These are the ones I remember trying:

It happens that the latest Docker for Windows is not working as it should. Docker Machine won't work with Hyper-V and it won't boot up if I disable Hyper-V and install Virtualbox so the solution was to downgrade to Docker Toolbox for Windows, to be able to use Virtualbox properly. One thing to notice, though, is that you must follow these instructions to have access to folders other than your User home folder. After that, you must restart the docker-machine to have it read your shared folder and you're good to go.

Here are my results:

bruno@DESKTOP-RL0SAF0 MINGW64 /e/Cursos/testdriven
$ docker-machine create -d virtualbox testdriven-dev
Running pre-create checks...
Creating machine...
(testdriven-dev) Copying C:\Users\bruno\.docker\machine\cache\boot2docker.iso to C:\Users\bruno\.docker\machine\machines\testdriven-dev\boot2docker.iso...
(testdriven-dev) Creating VirtualBox VM...
(testdriven-dev) Creating SSH key...
(testdriven-dev) Starting the VM...
(testdriven-dev) Check network to re-create if needed...
(testdriven-dev) Windows might ask for the permission to configure a dhcp server. Sometimes, such confirmation window is minimized in the taskbar.
(testdriven-dev) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: C:\Program Files\Docker Toolbox\docker-machine.exe env testdriven-dev

bruno@DESKTOP-RL0SAF0 MINGW64 /e/Cursos/testdriven
$ docker-machine restart testdriven-dev
Restarting "testdriven-dev"...
(testdriven-dev) Check network to re-create if needed...
(testdriven-dev) Windows might ask for the permission to configure a dhcp server. Sometimes, such confirmation window is minimized in the taskbar.
(testdriven-dev) Waiting for an IP...
Waiting for SSH to be available...
Detecting the provisioner...
Restarted machines may have new IP addresses. You may need to re-run the `docker-machine env` command.

bruno@DESKTOP-RL0SAF0 MINGW64 /e/Cursos/testdriven
$ docker-machine env testdriven-dev
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.102:2376"
export DOCKER_CERT_PATH="C:\Users\bruno\.docker\machine\machines\testdriven-dev"
export DOCKER_MACHINE_NAME="testdriven-dev"
export COMPOSE_CONVERT_WINDOWS_PATHS="true"
# Run this command to configure your shell:
# eval $("C:\Program Files\Docker Toolbox\docker-machine.exe" env testdriven-dev)

bruno@DESKTOP-RL0SAF0 MINGW64 /e/Cursos/testdriven
$ eval $(docker-machine env testdriven-dev)

bruno@DESKTOP-RL0SAF0 MINGW64 /e/Cursos/testdriven
$ docker-machine ls
NAME             ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER        ERRORS
default          -        virtualbox   Running   tcp://192.168.99.100:2376           v18.05.0-ce
testdriven-dev   *        virtualbox   Running   tcp://192.168.99.102:2376           v18.05.0-ce

bruno@DESKTOP-RL0SAF0 MINGW64 /e/Cursos/testdriven
$ docker-compose -f docker-compose-dev.yml up --build
Creating network "testdriven_default" with the default driver
Building users
Step 1/8 : FROM python:3.7
3.7: Pulling from library/python
0bd44ff9c2cf: Pull complete
047670ddbd2a: Pull complete
ea7d5dc89438: Pull complete
ae7ad5906a75: Pull complete
0f2ddfdfc7d1: Pull complete
d055f4d7ae62: Pull complete
05152d57a61e: Pull complete
36ebc9dbcca1: Pull complete
f62c22fac2b1: Pull complete
Digest: sha256:b4833abd1ca2e7bb636e102e58f2bd53382d26d293ecc6241c67fe517d15d0bd
Status: Downloaded newer image for python:3.7
 ---> 17453243214e
Step 2/8 : RUN apt-get update -yqq   && apt-get install -yqq --no-install-recommends     netcat dos2unix   && apt-get -q clean
 ---> Running in 6ebb8d566c7e
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package netcat-traditional.
(Reading database ... 29828 files and directories currently installed.)
Preparing to unpack .../netcat-traditional_1.10-41+b1_amd64.deb ...
Unpacking netcat-traditional (1.10-41+b1) ...
Selecting previously unselected package dos2unix.
Preparing to unpack .../dos2unix_7.3.4-3_amd64.deb ...
Unpacking dos2unix (7.3.4-3) ...
Selecting previously unselected package netcat.
Preparing to unpack .../netcat_1.10-41_all.deb ...
Unpacking netcat (1.10-41) ...
Setting up dos2unix (7.3.4-3) ...
Setting up netcat-traditional (1.10-41+b1) ...
update-alternatives: using /bin/nc.traditional to provide /bin/nc (nc) in auto mode
Setting up netcat (1.10-41) ...
Removing intermediate container 6ebb8d566c7e
 ---> 5b6e3007552c
Step 3/8 : RUN mkdir -p /usr/src/app
 ---> Running in 2c481a57226c
Removing intermediate container 2c481a57226c
 ---> ce3e96c0b844
Step 4/8 : WORKDIR /usr/src/app
Removing intermediate container 1c4793bf55e7
 ---> dfa6cbb3ac98
Step 5/8 : COPY . /usr/src/app
 ---> 7860cf8eeb87
Step 6/8 : RUN pip install -r requirements.txt
 ---> Running in a06fb7a2f9db
Collecting click==6.7 (from -r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/34/c1/8806f99713ddb993c5366c362b2f908f18269f8d792aff1abfd700775a77/click-6.7-py2.py3-none-any.whl (71kB)
Collecting Flask==1.0.2 (from -r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/7f/e7/08578774ed4536d3242b14dacb4696386634607af824ea997202cd0edb4b/Flask-1.0.2-py2.py3-none-any.whl (91kB)
Collecting itsdangerous==0.24 (from -r requirements.txt (line 3))
  Downloading https://files.pythonhosted.org/packages/dc/b4/a60bcdba945c00f6d608d8975131ab3f25b22f2bcfe1dab221165194b2d4/itsdangerous-0.24.tar.gz (46kB)
Collecting Jinja2==2.10 (from -r requirements.txt (line 4))
  Downloading https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl (126kB)
Collecting MarkupSafe==1.0 (from -r requirements.txt (line 5))
  Downloading https://files.pythonhosted.org/packages/4d/de/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b/MarkupSafe-1.0.tar.gz
Collecting Werkzeug==0.14.1 (from -r requirements.txt (line 6))
  Downloading https://files.pythonhosted.org/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl (322kB)
Building wheels for collected packages: itsdangerous, MarkupSafe
  Running setup.py bdist_wheel for itsdangerous: started
  Running setup.py bdist_wheel for itsdangerous: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/2c/4a/61/5599631c1554768c6290b08c02c72d7317910374ca602ff1e5
  Running setup.py bdist_wheel for MarkupSafe: started
  Running setup.py bdist_wheel for MarkupSafe: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/33/56/20/ebe49a5c612fffe1c5a632146b16596f9e64676768661e4e46
Successfully built itsdangerous MarkupSafe
Installing collected packages: click, Werkzeug, MarkupSafe, Jinja2, itsdangerous, Flask
Successfully installed Flask-1.0.2 Jinja2-2.10 MarkupSafe-1.0 Werkzeug-0.14.1 click-6.7 itsdangerous-0.24
Removing intermediate container a06fb7a2f9db
 ---> 371a3c962599
Step 7/8 : RUN dos2unix ./entrypoint.sh
 ---> Running in 702c40cb977d
dos2unix: converting file ./entrypoint.sh to Unix format...
Removing intermediate container 702c40cb977d
 ---> 09a5559ab0b5
Step 8/8 : CMD ["./entrypoint.sh"]
 ---> Running in 133f437e1a19
Removing intermediate container 133f437e1a19
 ---> babbe6505ca2

Successfully built babbe6505ca2
Successfully tagged testdriven_users:latest
Creating users ... done
Attaching to users
users    |  * Serving Flask app "project/__init__.py" (lazy loading)
users    |  * Environment: production
users    |    WARNING: Do not use the development server in a production environment.
users    |    Use a production WSGI server instead.
users    |  * Debug mode: on
users    |  * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
users    |  * Restarting with stat
users    |  * Debugger is active!
users    |  * Debugger PIN: 337-063-856
users    | 192.168.99.1 - - [07/Jul/2018 04:18:06] "GET /users/ping HTTP/1.1" 200 -

Everything works great now!

mjhea0 commented 6 years ago

Thanks for sharing, @werneckbh! I'll be sure to add a link to this in the next version of the course for Windows users.

abelthf commented 6 years ago

I have the exact same issue

$ docker-compose -f docker-compose-dev.yml up -d --build Removing testdriven-app_users_1 Building users-db Step 1/2 : FROM postgres:10.4-alpine 10.4-alpine: Pulling from library/postgres 8e3ba11ec2a2: Already exists fbb9adb8cff8: Pull complete aa8817b9e00d: Pull complete e162a11eb12c: Pull complete 788b2698f298: Pull complete 109af6d3e982: Pull complete 798f27e0089d: Pull complete b5a994ed229e: Pull complete 4b6dfba335bd: Pull complete Digest: sha256:b00851e5a07b910a18f9211cec807a1256cec38bbf7aa06859aba79acf79b3a8 Status: Downloaded newer image for postgres:10.4-alpine ---> 962ed899c609 Step 2/2 : ADD create.sql /docker-entrypoint-initdb.d ---> 73ebbe52c8f9

Successfully built 73ebbe52c8f9 Successfully tagged testdriven-app_users-db:latest Building users Step 1/9 : FROM python:3.6.5-alpine ---> 5be6d36f77ee Step 2/9 : RUN apk update && apk add --virtual build-deps gcc python-dev musl-dev && apk add postgresql-dev && apk add netcat-openbsd ---> Using cache ---> 294fd7d3db0c Step 3/9 : WORKDIR /usr/src/app ---> Using cache ---> 6229c51d2774 Step 4/9 : COPY ./requirements.txt /usr/src/app/requirements.txt ---> Using cache ---> 990bea45b85d Step 5/9 : RUN pip install -r requirements.txt ---> Using cache ---> a9cf20905753 Step 6/9 : COPY ./entrypoint.sh /usr/src/app/entrypoint.sh ---> Using cache ---> 270f71b0da88 Step 7/9 : RUN chmod +x /usr/src/app/entrypoint.sh ---> Using cache ---> 910b7dadcdb3 Step 8/9 : COPY . /usr/src/app ---> 15d23bddec93 Step 9/9 : CMD ["/usr/src/app/entrypoint.sh"] ---> Running in c32a43765347 Removing intermediate container c32a43765347 ---> 104b7da9289e

Successfully built 104b7da9289e Successfully tagged testdriven-app_users:latest Creating testdriven-app_users-db_1 ... done Recreating 98d92c967447_testdriven-app_users_1 ... error

ERROR: for 98d92c967447_testdriven-app_users_1 Cannot start service users: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"/usr/src/app/entrypoint.sh\": permission denied": unknown

ERROR: for users Cannot start service users: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"/usr/src/app/entrypoint.sh\": permission denied": unknown ERROR: Encountered errors while bringing up the project.

But I manage to work with the solution of @bal699 bal699

$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 74250300f76d testdriven-app_users "sh -c 'chmod 777 /u…" 9 minutes ago Up 9 minutes 0.0.0.0:5001->5000/tcp testdriven-app_users_1 27affcd576ec testdriven-app_users-db "docker-entrypoint.s…" About an hour ago Up About an hour 0.0.0.0:5435->5432/tcp testdriven-app_users-db_1

@mjhea0 mjhea0 when will you launch the new version of your course?

mjhea0 commented 6 years ago

@abelthf it was released on July, 16th 2018. Sign up for the mailing list so you don't miss future release announcements. https://testdriven.us17.list-manage.com/subscribe/post?u=bea5ac664532063fe8aa8d6a2&id=eddaf58c2a