pip无法在docker中安装本地包

时间:2017-10-25 00:49:11

标签: python docker pip dockerfile

我的Dockerfile是

FROM python:2

COPY . /mnt

WORKDIR /mnt

RUN ls -al
RUN pip install basin-textminner/
RUN pip install -r annotator-server/requirements.txt

ENV PYTHONUNBUFFERED 0

ENV HOST '0.0.0.0'
ENV PORT 5000

CMD python run.py

安装本地软件包basin-textminner时出错。

$ docker build -t bidspy .
Sending build context to Docker daemon 101.9 MB
Step 1 : FROM python:2
 ---> b1d5c2d7dda8
Step 2 : COPY . /mnt
 ---> 1851c99510ee
Removing intermediate container 594c781c3507
Step 3 : WORKDIR /mnt
 ---> Running in 9161f7117b9a
 ---> b8c75182024a
Removing intermediate container 9161f7117b9a
Step 4 : RUN ls -al
 ---> Running in af67f3610cd7
total 20
drwxr-xr-x  4 root root   84 Oct 25 00:42 .
drwxr-xr-x 21 root root 4096 Oct 25 00:43 ..
-rwxr--r--  1 root root  266 Oct 25 00:42 Dockerfile
-rw-r--r--  1 root root  453 Oct 24 06:03 README.md
drwxr-xr-x  5 root root 4096 Oct 24 06:35 annotator-server
drwxr-xr-x  9 root root 4096 Oct 24 06:03 basin-textminer
 ---> b2282c1be790
Removing intermediate container af67f3610cd7
Step 5 : RUN pip install basin-textminner/
 ---> Running in 1ef7fe341dc8
Invalid requirement: 'basin-textminner/'
It looks like a path. Does it exist ?
The command '/bin/sh -c pip install basin-textminner/' returned a non-zero code: 1

pip install xxxx/是正确的,只能在docker build上工作。

我发现pip install -e Pip install -e packages don't appear in Docker存在问题.Have试图将WORKDIR移到以后,但都没有工作。

我的测试:

WORKDIR /mnt
RUN ls -al                              # work
RUN ls -al basin-textminner/            # error 
RUN ls -al ./basin-textminner           # error
RUN ls -al /mnt/basin-textminner        # error

-----
RUN ls -al /mnt/basin-textminner        # error
WORKDIR /mnt

1 个答案:

答案 0 :(得分:1)

根据您的日志和dockerfile,您有一个拼写错误

import ssl
import socket
import ctypes
import pytest


def contact_github(cafile=""):
    ctx = ssl.SSLContext()
    ctx.verify_mode = ssl.VerifyMode.CERT_REQUIRED

    # ctx.load_verify_locations(cafile, "empty", None) done via ctypes
    ssl_ctx = ctypes.cast(id(ctx), ctypes.POINTER(ctypes.c_void_p))[2]
    cssl = ctypes.CDLL("/usr/lib/x86_64-linux-gnu/libssl.so.1.1")
    cssl.SSL_CTX_load_verify_locations.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_char_p]
    assert cssl.SSL_CTX_load_verify_locations(ssl_ctx, cafile.encode("utf-8"), b"empty")

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect(("github.com", 443))

    ss = ctx.wrap_socket(s)
    ss.send(b"GET / HTTP/1.0\n\n")
    print(ss.recv(1024))


def test_wrong_cert():
    with pytest.raises(ssl.SSLError):
        contact_github(cafile="bad-cert.pem")


def test_correct_cert():
    contact_github(cafile="good-cert.pem")

所以它应该是

RUN pip install basin-textminner/

ls output 
drwxr-xr-x  9 root root 4096 Oct 24 06:03 basin-textminer

或文件夹应重命名为basin-textminner