Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing libraries in ubuntu image using Docker

I am trying to install the 'sl' package in my ubuntu:14.04 image. Here's the content of my Dockerfile :

FROM ubuntu:14.04
MAINTAINER xyz <[email protected]>
RUN echo 'Going to install sl now'
RUN apt-get install -y sl

And this is the command I'm using to build the image:

sudo docker build -t xyz/ubuntu:14.04 .

But I'm getting this error message:

Sending build context to Docker daemon 2.048 kB
Sending build context to Docker daemon 
Step 0 : FROM ubuntu:14.04
 ---> d0955f21bf24
Step 1 : MAINTAINER xyz <[email protected]>
 ---> Using cache
 ---> a6e08926e788
Step 2 : RUN echo 'Going to install sl now'
 ---> Using cache
 ---> 1bf0bc6b3092
Step 3 : RUN apt-get install -y sl
 ---> Running in f7e57167443f
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package sl
INFO[0004] The command [/bin/sh -c apt-get install -y sl] returned a non-zero code: 100 

Where am I going wrong?

like image 896
gonephishing Avatar asked Mar 17 '23 13:03

gonephishing


2 Answers

You need to run apt-get update e.g:

RUN apt-get update && apt-get install -y sl

You can also tidy up after yourself to save a bit of disk space:

RUN apt-get update && apt-get install -y sl && rm -r /var/lib/apt/lists/*
like image 96
Adrian Mouat Avatar answered Apr 23 '23 02:04

Adrian Mouat


You need to update indices on your local ubuntu repository before installing any other package. The right way to do this will be:

RUN apt-get update
RUN apt-get install -y <package-name>

As Adrian mentioned in his answer deleting the downloaded list can be used to save some space on the disk. This is especially helpful when you are pushing the image back to the hub.

like image 30
Dim Jakes Avatar answered Apr 23 '23 00:04

Dim Jakes