Docker Image - Error with apt get update -y - docker

I am getting the following error while building an image
Sending build context to Docker daemon 8.724MB
Step 1/2 : FROM bde2020/spark-worker:2.4.5-hadoop2.7
---> ddb1ab6d9850
Step 2/2 : RUN apt-get update -y
---> Running in 99bbfdabe226
/bin/sh: apt-get: not found
The command '/bin/sh -c apt-get update -y' returned a non-zero code: 127
Here is the docker file
FROM bde2020/spark-worker:2.4.5-hadoop2.7
RUN apt-get update -y

The base OS of that image is Alpine linux. You can verify yourself:
$ docker run --rm -it --entrypoint=cat bde2020/spark-worker:2.4.5-hadoop2.7 /etc/*-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.10.4
PRETTY_NAME="Alpine Linux v3.10"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"
cat: can't open '/etc/system-release': No such file or directory
so instead of apt, you want to use apk.

Related

Dockerfile suggestion on multiple layers

I want a minimal image of ubuntu which is having docker and terraform installed in it.
where as I am trying to write Dockerfile as below please suggest me which one is best practice while writing Dockerfile:
FROM ubuntu
FROM docker
FROM hashicorp/terraform
RUN terraform --version
RUN docker --version
getting error as below for above Dockerfile:
/bin/sh: docker: not found
The command '/bin/sh -c docker --version' returned a non-zero code: 127
or
FROM ubuntu:latest AS ubuntu
RUN apt update && apt upgrade -y
RUN apt install unzip -y
COPY terraform.zip /home/
RUN unzip /home/terraform.zip
RUN mv terraform /usr/local/bin/
RUN terraform version
FROM docker
COPY --from=ubuntu /usr/local/bin/ /usr/local/bin
RUN terraform version
This is a quick and dirty solution just to get it working - hopefully it helps you.
Dockerfile:
# Choose your desired ubuntu version instead of :latest
FROM ubuntu:latest
RUN apt-get update
# Install docker + other packages to get terraform setup
RUN apt install docker.io gnupg curl software-properties-common -y
# Setup terraform
RUN curl -fsSL https://apt.releases.hashicorp.com/gpg | apt-key add -
RUN apt-add-repository "deb [arch=$(dpkg --print-architecture)] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
RUN apt update
RUN apt install terraform
# Run the container
CMD [ "bash" ]
Commands to run:
docker build . -t myapp
docker run -ti --entrypoint /bin/sh myapp
Now that you're in the container:
# terraform -v
Terraform v1.2.8
on linux_amd64
# docker --version
Docker version 20.10.12, build 20.10.12-0ubuntu4

Docker - apt-get update not found

I am not able to build my Dockerfile without the following error:
/bin/sh: 1: apt-get update : not found
I am able to start a container using the docker run command, with no problems and can run apt-get update using docker run --rm -it ubuntu:16.04 bash
My Dockerfile:
FROM ubuntu:16.04
# Install Packages
RUN apt-get update
Building using:
docker build -t demo/app .
You should pass apt-get update as an argument to bash in docker run command.
docker run --rm -it ubuntu:16.04 bash -c "apt-get update"
To work with this
FROM ubuntu:16.04
# Install Packages
RUN apt-get update
You need to build it first, then tag it and run it.
docker build -t demo/app .
After build you do not need to update for now
docker run --rm -it demo/app bash

add-apt-repository fails during docker build

I am trying to get the dordoka/tomcat docker image up and running, but I get this error when running docker build:
Cannot add PPA: 'ppa:~webupd8team/ubuntu/y-ppa-manager'.
ERROR: '~webupd8team' user or team does not exist.
The command '/bin/sh -c apt-get update &&
apt-get install -y software-properties-common &&
add-apt-repository -y ppa:webupd8team/y-ppa-manager &&
add-apt-repository -y ppa:webupd8team/ubuntu/y-ppa-manager &&
apt-get update &&
apt-get install -y git build-essential curl wget software-properties-common'
returned a non-zero code: 1
The command that is failing is add-apt-repository -y ppa:webupd8team/ubuntu/y-ppa-manager. This command runs fine outside of docker. The proxy is configured correctly, as far as I can tell. Any ideas?
#mlowry Is there a particular reason why you have to run this as root?
I assume that when you run it as your user you have also the http_proxy exported ?
In this case you could youse --build-args to pass the http_proxy string.
Quick example:
ubuntu#ip-172-31-10-207:~/test$ docker build --build-arg http_proxy=$http_proxy .
Sending build context to Docker daemon 2.048kB
Step 1/4 : FROM alpine:latest
---> e21c333399e0
Step 2/4 : ARG http_proxy
---> Running in fd0832692097
Removing intermediate container fd0832692097
---> 4c58ddefe37c
Step 3/4 : RUN export HTTP_PROXY=$http_proxy
---> Running in 913dc802ea8f
Removing intermediate container 913dc802ea8f
---> 9c3280343c13
Step 4/4 : RUN env
---> Running in 0d078193475a
HOSTNAME=0d078193475a
SHLVL=1
HOME=/root
http_proxy=http://domain\user:pass#proxy.com:8080
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/
Removing intermediate container 0d078193475a
---> d4b8996fbb09
Successfully built d4b8996fbb09

docker error Unable to locate package cowsay

When I am running the build command:
$ docker build -t cowsay .
Sending build context to Docker daemon 3.072 kB
Step 1 : FROM
Unknown instruction: FROM
dev#ub:~/cowsay$ docker build -t cowsay .
Sending build context to Docker daemon 3.072 kB
Step 1 : FROM ubuntu:14.04
---> 90d5884b1ee0
Step 2 : RUN apt-get -y install cowsay
---> Running in 587aaba2824b
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package cowsay
The command '/bin/sh -c apt-get -y install cowsay' returned a non-zero code: 100
Content of Dockerfile is as follow:
FROM ubuntu:14.04
RUN apt-get -y install cowsay
RUN apt-get -y install fortune
ENTRYPOINT ["/usr/games/cowsay"]
CMD ["Docker is so awesomoooooooo!"]
ONBUILD RUN /usr/games/fortune | /usr/games/cowsay
How can I avoid this error message?
Try and add RUN apt-get update first.
Once the packages are updated, you can install, for instance, cowsay.
See for instance this Dockerfile as an example of RUN apt-get commands:
FROM debian:jessie
RUN apt-get update && apt-get install -y cowsay
COPY docker.cow /usr/share/cowsay/cows/docker.cow
ENTRYPOINT ["/usr/games/cowsay","-f","docker"]
CMD ["moby","dock"]

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 <xyz#gmail.com>
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 <xyz#gmail.com>
---> 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?
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/*
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.

Resources