mac m1 nohub 안먹힘

이지훈·2022년 11월 15일
0

docker

목록 보기
1/2

mac m1에서 로컬 컴퓨터에서 도커 컨테이너를 백그라운드로 돌리려고 했다.

리눅스에서 쓰듯 nohub을 썼는데 아무리해도 안돌아갔다.

root@111111:/home# nohup python3 -u text.py &
[1] 372
root@111111:/home# nohup: ignoring input and appending output to 'nohup.out'

root@111111:/home# bg
bash: bg: job has terminated
[1]+  Exit 1                  nohup python3 -u in_nail_doctor.py
root@111111:/home# bg
bash: bg: current: no such job

sudo cat nohup.out 으로 노헙의 로그를 본다.

  File "/usr/local/lib/python3.8/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/usr/local/lib/python3.8/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
~~~~ 생략
RUN apt-get update
RUN apt-get -y install libgl1-mesa-glx
~~~ 생략

dockerfile build할 때 위 코드를 넣어준다.

FROM python:3.8.0

RUN mkdir -p /home
WORKDIR /home

COPY . .
RUN pip install --upgrade pip
RUN apt-get update
RUN apt-get -y install libgl1-mesa-glx
RUN pip install -r ./requirements.txt

EXPOSE 6000

또다른 에러

SyntaxError: Non-UTF-8 code starting with '\x80' in file /usr/bin/python on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

encoding에러이다. 해당 파일에다가 아래처럼 넣어준다.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

그리고 노헙으로 백그라운드에서 돌려준다.

nohup python -u file.py &

root@111111111:/home# bg
bash: bg: job 1 already in background

드디어 도커가 돌아간다.

FROM python:3.8.0

RUN mkdir -p /home/nailAI
WORKDIR /home/nailAI

COPY . .

RUN pip install --upgrade pip
RUN apt-get -y update && apt-get install -y \
sudo \
wget \
gcc \
g++
RUN apt-get -y install libgl1-mesa-glx

RUN pip install -r ./requirements.txt

EXPOSE 5000

CMD ["nohup", "python", "-u", "file.py", " &"]

하는데,
도커 flask 돌리는데 자꾸 포트가 사용중이라고 떴다.

  • Running on http://127.0.0.1:5000
    이라고 python 스크립트가 말해주는데
    in use 5000 port 라고 해서 포트를 바꿔줄 필요가 있었다.
# dockerfile cmd 설정
CMD ["python3", "in_nail_doctor.py", "--port", "6000"]
# file.py port 설정
import argparse

if __name__=="__main__":
    parser = argparse.ArgumentParser(description="Flask api exposing nail recognition")
    parser.add_argument("--port", default=6000, type=int, help="port number")
    args = parser.parse_args()
    app.run(host="0.0.0.0",debug=True,port=args.port)
    # app.run(host="0.0.0.0",debug=True,port=6000)

docker port 설정중 args를 설정가능하다.

아니면 flask port를 default를 6000으로 변경시켜주면 된다.

127.0.0.1 - - [15/Nov/2022 01:08:37] "POST /list HTTP/1.1" 200 -

성공적으로 가져와졌다.


참고로 run과 build 는 이렇게 했다.
mac m1 이라 buildx 로 빌드함.

# build
docker buildx build --platform=linux/arm64/v8 --no-cache --load -t file:0.23.0 /Users/my/project/flask/

# run
docker run --platform=linux/arm64/v8 -it -p 6000:6000 file:0.23.0 /bin/bash

tensorflow 패키지 충돌도 있었다.

absl-py==1.3.0
aiohttp==3.8.3
aiosignal==1.2.0
astunparse==1.6.3
async-timeout==4.0.2
attrs==22.1.0
blinker==1.5
brotlipy==0.7.0
cached-property==1.5.2
cachetools==5.2.0
certifi==2022.9.24
cffi==1.15.1
charset-normalizer==2.1.1
click==8.1.3
cryptography==38.0.2
Flask==2.2.2
Flask-Cors==3.0.10
flatbuffers==2.0
frozenlist==1.3.1
gast==0.4.0
google-auth==2.13.0
google-auth-oauthlib==0.4.6
google-pasta==0.2.0
grpcio
h5py==3.7.0
idna==3.4
importlib-metadata==4.11.4
itsdangerous==2.1.2
Jinja2==3.1.2
keras==2.10.0
Keras-Preprocessing==1.1.2
Markdown==3.4.1
MarkupSafe==2.1.1
multidict==6.0.2
numpy==1.23.4
oauthlib==3.2.2
opt-einsum
packaging==21.3
Pillow==9.2.0
pip==22.3
protobuf
pyasn1==0.4.8
pyasn1-modules==0.2.7
pycparser==2.21
PyJWT==2.6.0
pyOpenSSL==22.1.0
pyparsing==3.0.9
PySocks==1.7.1
pyu2f==0.1.5
requests==2.28.1
requests-oauthlib==1.3.1
rsa==4.9
scipy==1.9.3
setuptools==65.5.0
six==1.16.0
tensorboard==2.10.1
tensorboard-data-server==0.6.0
tensorboard-plugin-wit==1.8.1
tensorflow==2.10.0
tensorflow-estimator==2.10.0
termcolor==2.0.1
typing_extensions==4.4.0
urllib3==1.26.11
Werkzeug==2.2.2
wheel==0.37.1
wrapt==1.14.1
yarl==1.7.2
zipp==3.10.0
torch==1.9.0
torchvision==0.10.0
tensorflow-io==0.27.0
opencv-python
profile
꾸준하게 🐌

0개의 댓글