Installing OpenSSH on the Alpine Docker Container

121,857

Solution 1

Run apk update first. 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

Solution 2

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. 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.

Solution 3

Dockerfile for your reference

FROM alpine:3

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

CMD ["ssh"]
Share:
121,857
Ole
Author by

Ole

Updated on April 15, 2021

Comments

  • Ole
    Ole about 3 years

    When running the alpine docker container the first time and attempting an openssh install, the following happens:

    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?

  • Ates Goral
    Ates Goral over 7 years
    Or, to do and update and add in one shot: RUN apk add --update openssh
  • G-John
    G-John over 5 years
    thank you for --no-cache I was still using rm -rf hack
  • John Deer
    John Deer over 2 years
    RUN apk add --update --no-cache openssh