簡體   English   中英

在Docker容器中構建

[英]building inside Docker container

在從Docker容器內部運行Gitea的簡單情況下,當前Dockerfile假定您已經編譯了Gitea並可用它來創建映像。

就我而言,我的計算機上當前未安裝Gitea。 我在Mac OSX上,我的想法是,如果我在這台機器上構建,但是Gitea Dockerfile使用Alpine Linux作為其基本映像,在這種情況下會有沖突嗎? 有人可以澄清這是否是一個問題?

我想到的解決方法是使用Alpine Linux在容器內部直接構建Gitea。 另一種可能性是讓我在Mac OSX上進行編譯,然后更改我認為的基本映像。

這兩種變通辦法是否有意義,哪種更可取? 我們在圖像中使用的二進制文件也必須與基本圖像兼容嗎? 我想是的,但也歡迎您的投入。

編輯:我已經嘗試在容器內進行編譯,但是遇到了問題。 從DockerHub可用的Dockerfile如下:

FROM alpine:3.7
LABEL maintainer="The Gitea Authors"

EXPOSE 22 3000

RUN apk --no-cache add \
    su-exec \
    ca-certificates \
    sqlite \
    bash \
    git \
    linux-pam \
    s6 \
    curl \
    openssh \
    gettext \
    tzdata \
    make 
RUN addgroup \
    -S -g 1000 \
    git && \
  adduser \
    -S -H -D \
    -h /data/git \
    -s /bin/bash \
    -u 1000 \
    -G git \
    git && \
  echo "git:$(dd if=/dev/urandom bs=24 count=1 status=none | base64)" | 
chpasswd

# Dockerfile assumes Gitea is already up and running
# In this case, copy the source to container and Compile Gitea in Alpine 
Environment
COPY gitea-master.zip /
RUN unzip gitea-master.zip
RUN    cd gitea-master
RUN    make generate all

您可以看到我添加了將gitea復制到容器,解壓縮,cd到目錄和內部版本的說明,但是得到以下輸出:

Step 1/17 : FROM alpine:3.7
 ---> 3fd9065eaf02
Step 2/17 : LABEL maintainer="The Gitea Authors"
 ---> Using cache
 ---> b6bb053b3e89
Step 3/17 : EXPOSE 22 3000
 ---> Using cache
 ---> ade88a29df64
Step 4/17 : RUN apk --no-cache add     su-exec     ca-certificates     
sqlite     bash     git     linux-pam     s6     curl     openssh     
gettext     tzdata     make
 ---> Using cache
 ---> 460a5562c60f
Step 5/17 : RUN addgroup     -S -g 1000     git &&   adduser     -S -H -D     
-h /data/git     -s /bin/bash     -u 1000     -G git     git &&   echo 
"git:$(dd if=/dev/urandom bs=24 count=1 status=none | base64)" | chpasswd
 ---> Using cache
 ---> 07ff1f0b2d3e
Step 6/17 : COPY gitea-master.zip /
 ---> Using cache
 ---> 3ad1e3177659
Step 7/17 : RUN unzip gitea-master.zip
 ---> Using cache
 ---> 61a2beb19e1e
Step 8/17 : RUN    cd gitea-master
 ---> Using cache
 ---> 6985914927b9
Step 9/17 : RUN    make generate all
 ---> Running in 3e603f88c302
make: *** No rule to make target 'generate'.  Stop.
The command '/bin/sh -c make generate all' returned a non-zero code: 2

Makefile清楚地表明這些目標可用,但是這讓我有些困惑。 有什么建議么 ?

為了在OSX上為Linux構建Go二進制文件(我簽出了gitea,它似乎是用Go構建的),您需要提供將env變量GOOS設置為linux 您可以嘗試在gitea makefile的這一行之前添加GOOS=linuxhttps : //github.com/go-gitea/gitea/blob/master/Makefile#L221 ,或直接運行GOOS=linux make generate build 這應該創建一個可以在Docker映像中使用的go二進制文件。

進行編輯以進行編輯:可能是您將gitea-master解壓縮到一個更深的目錄中,在構建映像時檢查ls的輸出,以查看Makefile是否可用(在構建映像時,您的pwd中似乎沒有Makefile)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM