I have these commands in a Dockerfile:
RUN apt-get -y update #1
RUN apt-get -y install sudo #2
RUN sudo apt-get -y update #3
RUN sudo apt-get -y upgrade #4
RUN sudo apt-get install -y sqlite3 libsqlite3-dev #5
It looks as though Docker cannot cache line #3 or #4
Is there a way I can allow Docker to cache those results somehow? It's taking a minute or two to update/upgrade every time the image is built and I'd like to reduce this delay.
First thing You should avoid RUN apt-get upgrade or dist-upgrade, as many of the “essential” packages from the base images won’t upgrade inside an unprivileged container. If a package contained in the base image is out-of-date, you should contact its maintainers.
I think you need to run apt-get update only once within the Dockerfile & Always combine RUN apt-get update with apt-get install in the same RUN statement like
RUN apt-get update && apt-get install -y \
sudo \
sqlite3 \
libsqlite3-dev
Related
This question already exists:
Docker - install node as part of the ubuntu image
Closed 2 years ago.
I want to be able to set up an image that has both the Ubuntu and the node images.
I started with the Ubuntu and downloaded all the necessary programs, including node.js.
Here is the latest Dockerfile i created, out of the many i tried:
FROM ubuntu
RUN DEBIAN_FRONTEND=noninteractive apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common
#install freecad
RUN add-apt-repository ppa:freecad-maintainers/freecad-daily
RUN DEBIAN_FRONTEND=noninteractive apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y freecad-daily
#install utils
RUN DEBIAN_FRONTEND=noninteractive apt install -y git
RUN apt install -y python3-distutils
#install node
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y git-core curl build-essential openssl libssl-dev \
&& git clone https://github.com/nodejs/node.git \
&& cd node \
&& ./configure \
&& make \
&& sudo make install
COPY . .
RUN npm install
CMD ["node","server.js"]
Can i use two different FROM commands, for building my image?
The one to download ubuntu, and the other to download node.js?
I'm using the Python3.8-slim image for a djangoapp that run on uwsgi, but uwsgi needs libpcre3-dev to build with pcre support.
When I add RUN apt-get install -y libpcre3 libpcre3-dev
FROM python:3.8-slim
...
# Configure apt
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get -y install --no-install-recommends apt-utils 2>&1
...
RUN apt-get install -y libpcre3 libpcre3-dev
RUN pip install uwsgi # hopefully uwsgi should built with PCRE support now?
to my dockerfile, I get
E: Package 'libpcre3-dev' has no installation candidate
How can I install it?
Edit: Here's the full Dockerfile:
https://github.com/timberline-secondary/hackerspace/blob/f36cafd4c7d97eb989c37bbc9dfdc9c8ddf126c5/Dockerfile
You get this message without apt-get update. Try below code.
RUN apt-get update &&\
apt-get install -y libpcre3 libpcre3-dev
Replace your line by
RUN apt-get update && apt-get install -y libpcre3 libpcre3-dev
Dockerfile1
FROM ubuntu:latest
MAINTAINER ME
RUN apt-get update
RUN apt-get update && apt-get install -y net-tools \
&& apt-get install inetutils-traceroute \
&& apt-get install iputils-ping \
&& apt-get install xinetd telnetd
Dockerfile2
FROM ubuntu:latest
MAINTAINER ME
RUN apt-get update
RUN apt-get update && apt-get install -y net-tools
RUN apt-get update && apt-get install inetutils-traceroute
RUN apt-get update apt-get install iputils-ping
RUN apt-get install xinetd telnetd
Dockerfile3
FROM ubuntu:latest
MAINTAINER ME
RUN apt-get update
RUN apt-get install inetutils-traceroute
RUN apt-get install -y net-tools
RUN apt-get update apt-get install iputils-ping
RUN apt-get install xinetd telnetd
I tried all the above flavors of my dockerfile but every time I get the same error :
The command '/bin/sh -c apt-get update && apt-get install -y net-tools && apt-get install inetutils-traceroute && apt-get install iputils-ping && apt-get install xinetd telnetd' returned a non-zero code: 1
Someone posted an answer and deleted it before I could accept it. But here it is -
FROM ubuntu:latest
MAINTAINER ME
RUN apt-get update && apt-get install -y \
net-tools inetutils-traceroute \
iputils-ping xinetd telnetd
This works!!
try to use key -y for apt-get or apt managers, on docker side.
For example:
RUN apt-get update
RUN apt -y install net-tools
Without -y, apt-get asks a clarifying question - "are you sure you want to install this?". Without answer docker droped installation with code 1. The issue in here.
I want to install netstat on my Docker container.
I looked here https://askubuntu.com/questions/813579/netstat-or-alternative-in-docker-ubuntu-server-16-04-container so I'm trying to install it like this:
apt-get install net-tools
However, I'm getting:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package net-tools
So how can I install netstat?
You need to run apt-get update first to download the current state of the package repositories. Docker images do not include this to save space, and because they'd likely be outdated when you use it. If you are doing this in a Dockerfile, make sure to keep it as a single RUN command so that caching of the layers doesn't cache an old version of the update command with a new package install request:
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
net-tools \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
netstat is provided by the net-tools package,net-tools is probably not installed by default in the Docker image for Ubuntu 16.04 to keep the image size as small as possible.
Execute the following commands inside docker container:
apt update
apt install net-tools
I have a node.js application that I'm dockerizing, and it has a system dependency magicgraph. I cannot seem to be able to install it, I've tried apt-get in the Dockerfile like so RUN apt-get install --force-yes -y graphicsmagick and a few variations, but I keep getting the error The command '/bin/sh -c apt-get install --force-yes -y graphicsmagick' returned a non-zero code: 100.
Not sure how to fix this, is there a step tutorial on how to install gz files with the http://www.graphicsmagick.org/INSTALL-unix.html url maybe?
You need update list of available packages before install new one.
replace RUN apt-get install --force-yes -y graphicsmagick
to
RUN apt-get update && apt-get install -y graphicsmagick
if it don`t fix the issue show logs please