让python和基于组件的容器工作

我正在试图dockerize这个同构的应用程序的工作stream程。 我构build了下面的docker文件的容器。

FROM python:3.5-slim RUN apt-get update && \ apt-get -y install gcc mono-mcs && \ apt-get -y install vim && \ apt-get -y install nano && \ rm -rf /var/lib/apt/lists/* RUN mkdir -p /statics/js VOLUME ["/statics/"] WORKDIR /statics/js COPY requirements.txt /opt/requirements.txt RUN pip install -r /opt/requirements.txt EXPOSE 8080 CMD ["python", "/statics/js/app.py"] 

这是结果:

 $ docker build -t ciasto/pythonreact:v2 . Sending build context to Docker daemon 1.327 MB Step 1/9 : FROM python:3.5-slim ---> b27a94c44674 Step 2/9 : RUN apt-get update && apt-get -y install gcc mono-mcs && apt-get -y install vim && apt-get -y install nano && rm -rf /var/lib/apt/lists/* ---> Using cache ---> c76cb348707c Step 3/9 : RUN mkdir -p /statics/js ---> Using cache ---> 2ef5b24f551c Step 4/9 : VOLUME /statics/ ---> Using cache ---> 5e62c6af1867 Step 5/9 : WORKDIR /statics/js ---> Using cache ---> a5a018e8c727 Step 6/9 : COPY requirements.txt /opt/requirements.txt ---> Using cache ---> 1fa4dccc6608 Step 7/9 : RUN pip install -r /opt/requirements.txt ---> Running in 8845a0efcee7 Collecting TurboGears2==2.3.10 (from -r /opt/requirements.txt (line 1)) Downloading TurboGears2-2.3.10.tar.gz (176kB) Collecting Kajiki==0.6.3 (from -r /opt/requirements.txt (line 2)) Downloading Kajiki-0.6.3.tar.gz (174kB) Collecting tgext.webassets==0.0.2 (from -r /opt/requirements.txt (line 3)) Downloading tgext.webassets-0.0.2.tar.gz Collecting dukpy==0.1.0 (from -r /opt/requirements.txt (line 4)) Downloading dukpy-0.1.0.tar.gz (2.0MB) Collecting WebOb>=1.2 (from TurboGears2==2.3.10->-r /opt/requirements.txt (line 1)) Downloading WebOb-1.7.2-py2.py3-none-any.whl (83kB) Collecting crank<0.9.0,>=0.8.0 (from TurboGears2==2.3.10->-r /opt/requirements.txt (line 1)) Downloading crank-0.8.1.tar.gz Collecting repoze.lru (from TurboGears2==2.3.10->-r /opt/requirements.txt (line 1)) Downloading repoze.lru-0.6.tar.gz Collecting MarkupSafe (from TurboGears2==2.3.10->-r /opt/requirements.txt (line 1)) Downloading MarkupSafe-1.0.tar.gz Collecting nine (from Kajiki==0.6.3->-r /opt/requirements.txt (line 2)) Downloading nine-1.0.0-py2.py3-none-any.whl Collecting webassets (from tgext.webassets==0.0.2->-r /opt/requirements.txt (line 3)) Downloading webassets-0.12.1.tar.gz (179kB) Collecting cssmin (from tgext.webassets==0.0.2->-r /opt/requirements.txt (line 3)) Downloading cssmin-0.2.0.tar.gz Building wheels for collected packages: TurboGears2, Kajiki, tgext.webassets, dukpy, crank, repoze.lru, MarkupSafe, webassets, cssmin Running setup.py bdist_wheel for TurboGears2: started Running setup.py bdist_wheel for TurboGears2: finished with status 'done' Stored in directory: /root/.cache/pip/wheels/51/1d/bb/c9cfdcf2a49f71955d5b66aed0dbd187e58e5d77a9fa34a4af Running setup.py bdist_wheel for Kajiki: started Running setup.py bdist_wheel for Kajiki: finished with status 'done' Stored in directory: /root/.cache/pip/wheels/ad/fe/15/33e02c73fead4ea9238fcd31d273accf6fb9d922ec901e20c8 Running setup.py bdist_wheel for tgext.webassets: started Running setup.py bdist_wheel for tgext.webassets: finished with status 'done' Stored in directory: /root/.cache/pip/wheels/00/f2/09/0378f24bd9151b7a927093546c11685899ebec451b65eb181f Running setup.py bdist_wheel for dukpy: started Running setup.py bdist_wheel for dukpy: finished with status 'done' Stored in directory: /root/.cache/pip/wheels/21/29/46/34c303b9dca370a8ccc97a84b094c8089b78edde125b0a1fcb Running setup.py bdist_wheel for crank: started Running setup.py bdist_wheel for crank: finished with status 'done' Stored in directory: /root/.cache/pip/wheels/1c/00/54/4dcfd62d8268d7b34ea607bd9f8cb12aa930a7718c8c5fbc02 Running setup.py bdist_wheel for repoze.lru: started Running setup.py bdist_wheel for repoze.lru: finished with status 'done' Stored in directory: /root/.cache/pip/wheels/b2/cd/b3/7e24400bff83325a01d492940eff6e9579f553f33348323d79 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/88/a7/30/e39a54a87bcbe25308fa3ca64e8ddc75d9b3e5afa21ee32d57 Running setup.py bdist_wheel for webassets: started Running setup.py bdist_wheel for webassets: finished with status 'done' Stored in directory: /root/.cache/pip/wheels/9d/cb/c2/340b9b695822b6954840bcb6cd147b3a7cfc2bcd922296e63e Running setup.py bdist_wheel for cssmin: started Running setup.py bdist_wheel for cssmin: finished with status 'done' Stored in directory: /root/.cache/pip/wheels/c3/79/88/647f59be446af4e9867362ca6e961cc7f218bd793fbdc351a6 Successfully built TurboGears2 Kajiki tgext.webassets dukpy crank repoze.lru MarkupSafe webassets cssmin Installing collected packages: WebOb, crank, repoze.lru, MarkupSafe, TurboGears2, nine, Kajiki, webassets, cssmin, tgext.webassets, dukpy Successfully installed Kajiki-0.6.3 MarkupSafe-1.0 TurboGears2-2.3.10 WebOb-1.7.2 crank-0.8.1 cssmin-0.2.0 dukpy-0.1.0 nine-1.0.0 repoze.lru-0.6 tgext.webassets-0.0.2 webassets-0.12.1 ---> 86c189792ae7 Removing intermediate container 8845a0efcee7 Step 8/9 : EXPOSE 8080 ---> Running in 9243a87c36e2 ---> e7d35d54e66d Removing intermediate container 9243a87c36e2 Step 9/9 : CMD python /statics/js/app.py ---> Running in 6e3b53cd901d ---> 0d79c4f81f3b Removing intermediate container 6e3b53cd901d Successfully built 0d79c4f81f3b 

所以我的第一个问题是第9步是什么意思? 这是否意味着即使在运行容器之前,它正在尝试运行/statics/js/app.pypath,因为我不打算从host装入此statics卷。 其次,如果我运行命令:

 $ docker run -it -v ~/Development/my-Docker-builds/pythonReact/statics/:/statics/ -d ciasto/pythonreact:v2 

03d77c87651e752450e3be0aa64a0841c088b32a1db5424ad96c150c949d0366

我得到的哈希键,但没有任何工作! 我甚至没有看到app.py的开始跟踪或错误消息有任何错误。

那么当我运行容器时,我应该如何从主机安装的卷运行app.py

您可以将CMD视为容器的启动脚本。 话虽如此,在第9步中,只有在启动容器时才会执行pyhton /statics/js/app.py标记。 此外,由于您使用的是-d标志,因此您将无法看到日志,因此您必须使用docker logs命令来获取它们,如下所示:

 docker logs 03d77c87651e752450e3be0aa64a0841c088b32a1db5424ad96c150c949d0366 

日志应该足以帮助你找出问题。 我希望它有帮助。