简体   繁体   English

Dockerfile 对于 golang 和 python

[英]Dockerfile for golang and python

There is a django project already running.有一个 django 项目已经在运行。 Now Inside the code, I need to execute the following command in the subprocess module:现在在代码中,我需要在 subprocess 模块中执行以下命令:

cmd = f's5cmd cp {obj1} {obj2}'

Now locally this code is running fine.现在在本地这段代码运行良好。 But after deploying the code it is unable to find s5cmd.但在部署代码后无法找到 s5cmd。 According to s5cmd documentation it is written in golang and on my system it is installed that's why it is working fine.根据 s5cmd 文档,它是用 golang 编写的,并且在我的系统上安装了它,这就是它工作正常的原因。 So i updated the dockerfile but still its not working.所以我更新了 dockerfile 但仍然无法正常工作。

FROM python:3.6
COPY ./requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir -r /tmp/requirements.txt
COPY . /apps/project/
WORKDIR /apps/project/project/
EXPOSE 8000
CMD gunicorn project.wsgi:application --timeout 3000 --access-logfile '-' -w 3 -k gevent --bind=0.0.0.0:8000

This dockerfile is working.这个 dockerfile 正在工作。 Now the updated dockerfile looks like this but its not working ie the s5cmd command is not working with docker.现在更新后的 dockerfile 看起来像这样,但它不起作用,即 s5cmd 命令不适用于 docker。

FROM python:3.6.7-alpine3.6

# author of file
LABEL maintainer="Baktawar"



# Install native libraries, required for numpy
RUN apk --no-cache add musl-dev linux-headers g++
RUN apk add --no-cache --virtual .build-deps bash gcc musl-dev openssl go
RUN apk update && apk add ca-certificates wget && update-ca-certificates
RUN wget -O go.tgz https://golang.org/dl/go1.15.2.src.tar.gz
RUN tar -C /usr/local -xzf go.tgz
RUN cd /usr/local/go/src/
RUN ./make.bash
RUN export PATH="/usr/local/go/bin:$PATH"
RUN export GOPATH=/opt/go/
RUN export PATH=$PATH:$GOPATH/bin
RUN apk del .build-deps
RUN go version
RUN apk update && apk add git && go get github.com/peak/s5cmd && s5cmd
# Upgrade pip
RUN pip install --upgrade pip

COPY ./requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir -r /tmp/requirements.txt && pip install psycopg2-binary
COPY . /apps/project/
WORKDIR /apps/project/project/
EXPOSE 8000
CMD gunicorn project.wsgi:application --timeout 3000 --access-logfile '-' -w 3 -k gevent --bind=0.0.0.0:8000

Requirements.txt file Requirements.txt文件

boto3==1.12.39
botocore==1.15.39
certifi==2020.6.20
chardet==3.0.4
Django==2.2
djangorestframework==3.11.0
docutils==0.15.2
gevent==20.5.1
greenlet==0.4.16
gunicorn==20.0.4
idna==2.9
jmespath==0.10.0
json-logging==1.2.0
numpy==1.19.0
pandas==1.0.5
python-dateutil==2.8.1
pytz==2020.1
requests==2.23.0
s3transfer==0.3.3
six==1.15.0
SQLAlchemy==1.3.16
sqlparse==0.3.1
urllib3==1.25.9
zope.event==4.4
zope.interface==5.1.0
pytest==6.0.1

There are a couple of problems with the Dockerfile: Dockerfile 有几个问题:

  1. RUN cd /usr/local/go/src/ won't work, it should be replaced with WORKDIR /usr/local/go/src or placed inline with the next command RUN cd /usr/local/go/src/将不起作用,应将其替换为WORKDIR /usr/local/go/src或与下一个命令内联
  2. RUN export PATH... (and the like) wont' work either, should be replaced with ENV PATH... RUN export PATH... (等)也不会工作,应替换为ENV PATH...

The following Dockerfile should work (just the go/s5cmd part)以下 Dockerfile 应该可以工作(只是 go/s5cmd 部分)

RUN apk --no-cache add musl-dev linux-headers g++
RUN apk add --no-cache --virtual .build-deps bash gcc musl-dev openssl go
RUN apk update && apk add ca-certificates wget && update-ca-certificates
RUN wget -O go.tgz https://golang.org/dl/go1.15.2.src.tar.gz
RUN tar -C /usr/local -xzf go.tgz
RUN cd /usr/local/go/src/ && ./make.bash
ENV PATH "/usr/local/go/bin:$PATH"
ENV GOPATH "/opt/go/"
ENV PATH "$PATH:$GOPATH/bin"
RUN apk del .build-deps
RUN go version
RUN apk update && apk add git && go get github.com/peak/s5cmd && s5cmd

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM