Docker Build Error : The command '/bin/sh -c apt-get install –y apache2' returned a non-zero code: 100 - docker

I am trying to build a Dockerfile
FROM ubuntu
RUN apt-get update
RUN apt-get install –y apache2
RUN apt-get install –y apache2-utils
RUN apt-get clean
EXPOSE 80
CMD [“apache2ctl”, “-D”, “FOREGROUND”]
when i am running this command docker build –t=”mywebserver” . I am getting below provided error in console
E: Unable to locate package –y
The command '/bin/sh -c apt-get install –y apache2' returned a non-zero code: 100

I'm not sure how, but I think you're using an en dash instead of a hyphen in front of your y.
You want -y rather than –y
If you look closely there's a subtle difference.

The Dockerfile looks fine so could be something to do with a proxy/firewall.
I would try the following:
FROM ubuntu
RUN apt-get update
Run with docker build --no-cache -t mywebserver and see if it performs the update without issues. If not then I would suggest looking at setting http/https proxy with ENV inside the dockerfile.

Related

Docker: python has no installation candidate

I am trying to create a docker image from my docker file which has the following content:
FROM ubuntu:latest
WORKDIR /app
ADD . /app
RUN apt-get update && apt-get install python -y
CMD python /app/main.py
LABEL color=red
which fails with the following error:
apt-get update && apt-get install python -y returned a non-zero code: 100
So please help me in solving this error
Docker is just Linux. When some apt-get install acme fails, you just need to try the exact command and or research the missing dependencies.
To replicate your error I ran: docker run -it ubuntu:latest and inside, I ran your apt-get update && apt-get install python -y. I got the error:
So, I tried with apt-get install python3 -y and it worked. Finally your Dockerfile should be:
FROM ubuntu:latest
WORKDIR /app
ADD . /app
RUN apt-get update && apt-get install python3 -y
CMD python3 /app/main.py
LABEL color=red
Older Python
If your code needs old python version, you should not use FROM ubuntu:latest because in the lastest version of ubuntu, only python3 is allowed.
Anyway if you need python2, you must research a lot on internet to get the exact steps to install python2 or use some ready to use docker images:
https://hub.docker.com/layers/python/library/python/2.7.18-slim-stretch/images/sha256-a0b3c65a15ba08138460de9fd2267b8dec30ed98407a0edac0adc0ccbe809cad?context=explore
how do i setup only python 2.7 in docker container?
https://github.com/Docker-Hub-frolvlad/docker-alpine-python2

Docker Run Command as Sudo?

Inside my dockerfile I have:
FROM ubuntu:latest
FROM python:latest
RUN sudo apt-get update
RUN apt-get install nmap
But I have a problem where the last line doesn't work because of sudo, how may I fix this?
The following works for me:
RUN apt-get update && \
apt-get install -y --no-install-recommends \
nmap
-y means automatic "yes" answer to all prompts and runs non-interactively.
Since your first FROM statement doesn't do anything and you're already running as root, you can change your Dockerfile to
FROM python:latest
RUN apt-get update
RUN apt-get install -y nmap
Build and run with
docker build -t myimage .
docker run -it myimage /bin/bash
Now you're in a shell in the container. You can now run whoami to verify that you're running as root and you can run nmap.

Packages wont install in docker

I am trying to install tesseract-ocr to docker from a Dockerfile. When I build the Dockerfile everything looks normal and i get no errors but when I run the container tesseract is not installed.
If I access the container using sudo docker exec -t -i <container_id> /bin/bash and manually install tesseract using apt-get install -y tesseract-ocr-all it installs and works perfectly. Why doesn't it work when I try to install it during the build process?
My Dockerfile looks like this:
FROM ubuntu:20.04
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y tesseract-ocr-all
RUN tesseract --version
FROM python:3.7
WORKDIR ocr
COPY requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt
COPY . .
Thanks!
It looks like you are leveraging Docker multi-stage builds without realizing it.
When you put FROM python:3.7, you essentially throw away everything you have done above that, since you start a new stage.
The easiest solution I can see is to move
RUN apt-get update \
&& apt-get install -y tesseract-ocr-all
RUN tesseract --version
into the FROM python:3.7 stage, and remove the FROM ubuntu:20.04 stage.
You need to switch your user, since you likely don't have permission to run those commands. Something like this should work:
USER root
RUN apt-get update \
&& apt-get install -y tesseract-ocr-all
USER <switch back to previous user>
You'll need to figure out what the default user is to switch back, which you can probably find in the Ubuntu docs or using whoami.

issue in creating docker image from docker file

Created a Docker file in oreder to install Tomcat server from Unix as bashe os
My Dockerfile:
FROM ubuntu
RUN apt-get update && apt-get upgrade -y #to update os
RUN apt-get dist-upgrade
RUN apt-get install build-essential
RUN apt-get install openjdk-8-jdk # to install java 8
RUN apt-get wget -y #to install wget package
RUN apt-get wget https://mirrors.estointernet.in/apache/tomcat/tomcat-9/v9.0.37/bin/apache-tomcat-9.0.37.tar.gz #to download tomcat
RUN tar -xvzf apache-tomcat-9.0.37 # unzipping the tomcat
RUN mkdir tomcat # craeting tomacat directory
RUN cp apache-tomcat-9.0.37/* tomcat # copying tomact files to tomact directory
Command to create Docker Image from Docker file:
docker build -t [img name] -f [file name] .
On execution, while installing java package am getting like this:
'''After this operation, 242 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y'''
You are getting the prompt because the command is awaiting user input for whether or not to install a package. The -y flag you're using for a few of them (like wget) allows bash to assume a yes. Add this flag to all your installation commands.
By the way, there's quite a few potential issues with the Dockerfile you posted.
For example, you have RUN apt-get wget ...
Are you sure that is what you want to do, and not just RUN wget ...? Unless wget is a command that apt-get takes, which it isn't, it will cause unexpected behavior.
You also seem to be missing the command to start the Tomcat server, which can make it so that nothing happens when you attempt to run the image.
I think you should add DEBIAN_FRONTEND=noninteractive when running the apt-get commands, something like this:
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install build-essential -y
Also, it's considered bad practice to use multiple RUN steps which could be consolidated into one. More about Dockerfile best practices can be found here.

How can I docker-build with Dockerfile?

I building docker image. But it does not success.
/Users/username/.vim exists on my host os, But it does not success.
How I can success docker- build?
Error Message:
Step 16 : ADD /Users/username/.vim/ /root/.vim
lstat Users/username/.vim/: no such file or directory
The following is my Dockerfile.
Dockerfile:
FROM ubuntu:latest
MAINTAINER MyName
RUN /bin/bash
RUN mkdir ~/cworks
RUN mkdir ~/pyworks
RUN apt-get -y update
RUN apt-get -y install curl
RUN apt-get -y install clang
RUN apt-get -y install man
RUN apt-get -y install vim
RUN apt-get -y install python3
RUN apt-get -y install git
RUN apt-get -y install make
RUN apt-get -y upgrade
RUN curl -kL https://bootstrap.pypa.io/get-pip.py | python3
ADD /Users/username/.vim/ /root/.vim
ADD /Users/username/.vimrc /root/.vimrc
Platform: OS X 10.11.4
You cannot execute ADD (or COPY) on a file that is not inside the directory that contains your Dockerfile.
The reason for that is that building docker images is meant to be a deterministic build. If I build the Dockerimage on my computer with your Dockerfile, I would have a different .vim
The docker team impose this limitation to encourage people using a self contained directory with a Dockerfile, and any file to add to it.
In your case, you will need to copy the file in the same directory of the Dockerfile first, and run:
ADD .vim /root/.vim
Or arguably better:
COPY .vim /root/.vim
Use this form instead. It works with hidden files(dot files) and filename contains whitespaces.
ADD ["/Users/username/.vim/", "/root/.vim"]
https://docs.docker.com/engine/reference/builder/#/add
Please remove tailing slash after .vim
So, it will go as
ADD /Users/username/.vim /root/.vim

Resources