命令在 docker 容器内工作正常,但在构建映像时在 dockerfile 中无法工作

问题描述 投票:0回答:1

dockerfile代码

 FROM ubuntu:20.04
 RUN  wget https://dl.google.com/go/go1.21.0.linux-amd64.tar.gz && \
      tar -C /usr/local -xzf go1.21.0.linux-amd64.tar.gz && \
      export PATH=$PATH:/usr/local/go/bin && \
      go version
 COPY akamai-v1.5.6-linux386 .
 RUN  chmod +x akamai-v1.5.6-linux386 && \
      mv akamai-v1.5.6-linux386 /usr/local/bin/akamai && \
      apt-get update
 RUN apt-get update && akamai install purge -y 
 EXPOSE 22
 CMD ["/usr/sbin/sshd", "-D"]

我正在安装 akamai cli 和 akamai purge 软件包。 我收到以下错误-

=> ERROR [9/9] RUN apt-get update && akamai install purge -y                                                                                   85.0s
------                                                                                                                                                
 > [9/9] RUN apt-get update && akamai install purge -y:                                                                                               
0.655 Hit:1 http://security.ubuntu.com/ubuntu focal-security InRelease                                                                                
0.865 Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease                                                                                          
1.133 Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]                                                                         
2.375 Hit:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease                                                                                
2.530 Fetched 114 kB in 2s (51.0 kB/s)
2.530 Reading package lists...
84.86  ERROR[0081] Package Is Not Available. Supported Packages Can Be Found Here: Https://Techdocs.Akamai.Com/Home/Page/Products-Tools-A-Z command=install
84.86  ERROR[0081] INSTALL ERROR: Package is not available. Supported packages can be found here: https://techdocs.akamai.com/home/page/products-tools-a-z command=install
84.86 Package is not available. Supported packages can be found here: https://techdocs.akamai.com/home/page/products-tools-a-z
------
Dockerfile:163

 161 |     # ENV PATH=/usr/local/bin/akamai:$PATH
 162 |     # RUN echo $PATH
 163 | >>> RUN apt-get update && akamai install purge -y 
 164 |     
 165 |     EXPOSE 22

ERROR: failed to solve: process "/bin/sh -c apt-get update && akamai install purge -y" did not complete successfully: exit code: 1

我在 akamai install purge 命令上遇到错误。但是如果我在 dockerfile 中注释它并在容器内使用,相同的命令就可以工作。 错误显示该包不可用,但当我检查给定链接上的包是否可用时

docker jenkins dockerfile devops akamai
1个回答
0
投票

看起来您希望

akamai purge
在 Ubuntu Docker 映像上运行。

🗎

Dockerfile

FROM golang:alpine3.17 as builder

RUN apk add --no-cache $(apk search --no-cache | grep -q ^upx && echo -n upx) git \
  && git clone --depth=1 https://github.com/akamai/cli-purge \
  && cd cli-purge \
  && go mod tidy \
  && go build -o /akamai-purge -ldflags="-s -w" \
  && upx -3 -o/akamai-purge.upx /akamai-purge

RUN apk add --no-cache $(apk search --no-cache | grep -q ^upx && echo -n upx) git \
  && git clone --depth=1 https://github.com/akamai/cli \
  && cd cli \
  && go mod tidy \
  && go build -o /akamai -ldflags="-s -w" cli/main.go \
  && upx -3 -o/akamai.upx /akamai 

FROM ubuntu:20.04

ENV AKAMAI_CLI_HOME=/cli

RUN mkdir -p \
        $AKAMAI_CLI_HOME/.akamai-cli/src/cli-purge/bin \
        $AKAMAI_CLI_HOME/.akamai-cli/logs
    
COPY --from=builder /akamai-purge.upx $AKAMAI_CLI_HOME/.akamai-cli/src/cli-purge/bin/akamai-purge
COPY --from=builder /go/cli-purge/cli.json $AKAMAI_CLI_HOME/.akamai-cli/src/cli-purge/cli.json

COPY --from=builder /akamai.upx /bin/akamai

COPY config $AKAMAI_CLI_HOME/.akamai-cli/config 

RUN chmod -R a+rwx ${AKAMAI_CLI_HOME}

添加配置文件将阻止您在首次运行

akamai
时收到有关自动升级的提示。这是在构建的第二阶段复制的。

🗎

config

[cli]
cache-path         = /cli/.akamai-cli/cache
config-version     = 1.1
last-upgrade-check = ignore

© www.soinside.com 2019 - 2024. All rights reserved.