Search code examples
dockerubuntuputty

Docker: cannot install openssh-server


I build the Docker based on Ubuntu 16 and want to allow PuTTY access to the Ubuntu. I have added the line to the docker file:

#Download base image ubuntu 16.04
FROM ubuntu:16.04

# Update Software repository
RUN apt-get update

# Install nginx, php-fpm and supervisord from ubuntu repository
RUN apt-get install -y nginx php7.0-fpm supervisor && \
    rm -rf /var/lib/apt/lists/*

RUN apt-get autoclean  -y supervisor
RUN apt-get install openssh-server -y supervisor

But when I build the image it gives me

Step 5/18 : RUN apt-get install openssh-server -y supervisor ---> Running in c9425deece29 Reading package lists... Building dependency tree... Reading state information... E: Unable to locate package openssh-server

How to fix it? My task is: to allow connection from a host (Windows) to the docker container via PuTTY.


Solution

  • Following Dockerfile should work.

    #Download base image ubuntu 16.04
    FROM ubuntu:16.04
    
    # Update Software repository
    RUN apt-get update && \
        apt-get upgrade -y
    
    RUN apt-get install openssh-server -y supervisor    
    
    # Install nginx, php-fpm and supervisord from ubuntu repository
    RUN apt-get install -y nginx php7.0-fpm supervisor && \
        rm -rf /var/lib/apt/lists/*
    
    RUN apt-get autoclean  -y supervisor
    

    There is two thing it seems problematic to me.

    • After update I'm always using upgrade to update all packages on my system. It's not necessary but I find it's a good practice
    • You are removing /var/lib/apt/lists/ * then you are trying to install openssh-server. apt can't find anything on that path when it need.