简体   繁体   English

在 Alpine Docker 容器上安装 OpenSSH

[英]Installing OpenSSH on the Alpine Docker Container

When running the alpine docker container the first time and attempting an openssh install, the following happens:第一次运行 alpine docker 容器并尝试安装 openssh 时,会发生以下情况:

ole@T:~$ docker run -it --rm alpine /bin/ash
/ # apk add openssh
WARNING: Ignoring APKINDEX.d3812b7e.tar.gz: No such file or directory
WARNING: Ignoring APKINDEX.bb2c5760.tar.gz: No such file or directory
ERROR: unsatisfiable constraints:
  openssh (missing):
    required by: world[openssh]

How should openssh be installed? openssh 应该如何安装?

Run apk update first.首先运行apk update The below paste contains a complete example:以下粘贴包含一个完整的示例:

    ole@T:~$ docker run -it --rm alpine /bin/ash
    / # apk update
    fetch http://dl-4.alpinelinux.org/alpine/v3.3/main/x86_64/APKINDEX.tar.gz
    fetch http://dl-4.alpinelinux.org/alpine/v3.3/community/x86_64/APKINDEX.tar.gz
    v3.3.1-97-g109077d [http://dl-4.alpinelinux.org/alpine/v3.3/main]
    v3.3.1-59-g48b0368 [http://dl-4.alpinelinux.org/alpine/v3.3/community]
    OK: 5853 distinct packages available
    / # apk add openssh
    (1/3) Installing openssh-client (7.1_p2-r0)
    (2/3) Installing openssh-sftp-server (7.1_p2-r0)
    (3/3) Installing openssh (7.1_p2-r0)
    Executing busybox-1.24.1-r7.trigger
    OK: 8 MiB in 14 packages

As the answer is already given but I will add up something.由于答案已经给出,但我会加起来。

In the new version, If you want to install something without caching things locally, which is recommended for keeping your containers small, include the --no-cache flag.在新版本中,如果你想安装一些东西而不在本地缓存东西,建议你保持容器小,包括--no-cache标志。 Example:例子:

apk add --no-cache openssh

This is a small gain, it keeps you from having the common rm -rf /var/cache/apk/* at the end of your Dockerfile.这是一个小收获,它使您不会在 Dockerfile 的末尾使用常见的rm -rf /var/cache/apk/*

Dockerfile for your reference Dockerfile 供您参考

FROM alpine:3

RUN apk add --update --no-cache openssh

CMD ["ssh"]

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

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