简体   繁体   中英

Dockerfile for golang and python

There is a django project already running. Now Inside the code, I need to execute the following command in the subprocess module:

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

Now locally this code is running fine. But after deploying the code it is unable to find s5cmd. According to s5cmd documentation it is written in golang and on my system it is installed that's why it is working fine. So i updated the dockerfile but still its not working.

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. Now the updated dockerfile looks like this but its not working ie the s5cmd command is not working with 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

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:

  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
  2. RUN export PATH... (and the like) wont' work either, should be replaced with ENV PATH...

The following Dockerfile should work (just the go/s5cmd part)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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