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"]
Related
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
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.
I was trying to create a Docker Image for ProxySQL . Following is my DockerFile
FROM rhel7:latest
USER root
MAINTAINER Ques Zama
# Update the image with the latest packages (recommended)
RUN yum update -y; yum clean all
# Update image
RUN yum-config-manager --enable proxysql_repo
# Install ProxySQL
RUN yum install proxysql -y
# Expose ProxySQL Port 6034
EXPOSE 6034
# Start the service
CMD /etc/init.d/service start proxysql
I was trying to build the image with below command
sudo docker build --no-cache -t zama_proxysql .
But I can it is not able to install the proxysql package using yum command as mentioned in Dockerfile . Following is the message below
Step 6 : RUN yum install proxysql -y
---> Running in 54cc1ae88ba3
Loaded plugins: ovl, product-id, search-disabled-repos, subscription-manager
No package proxysql available.
Error: Nothing to do
The command '/bin/sh -c yum install proxysql -y' returned a non-zero code: 1
If I execute the command yum install proxysql in commandline , it works fine . But from Dockerfile , it could not find the package. Please note that I have already enabled the repo for proxysql in /etc/yum.repos.d
Any suggestions to resolve the issue
Try adding the repo manually first instead of using yum-config-manager :
cat <<EOF | tee /etc/yum.repos.d/proxysql.repo
[proxysql_repo]
name= ProxySQL YUM repository
baseurl=http://repo.proxysql.com/ProxySQL/proxysql-1.4.x/centos/\$releasever
gpgcheck=1
gpgkey=http://repo.proxysql.com/ProxySQL/repo_pub_key
EOF
This works properly on a FROM centos:7 image.
I'm trying to create a VM with docker and boot2docker. I've made the following Dockerfile, which I'm trying to run through the command line
docker run Dockerfile
Immidiatly it says exactly this:
Unable to find image 'Dockerfile:latest' locally
FATA[0000] Invalid repository name <Dockerfile>, only [a-z0-9_.] are allowed
Dockerfile:
FROM ubuntu:latest
#Oracle Java7 install
RUN apt-get install software-properties-common -y
RUN apt-get update
RUN add-apt-repository -y ppa:webupd8team/java
RUN apt-get update
RUN echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections
RUN apt-get install -y oracle-java7-installer
#Jenkins install
RUN wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
RUN sudo echo "deb http://pkg.jenkins-ci.org/debian binary/" >> /etc/apt/sources.list
RUN apt-get update
RUN apt-get install --force-yes -y jenkins
RUN sudo service jenkins start
#Zip support install
RUN apt-get update
RUN apt-get -y install zip
#Unzip hang.zip
RUN unzip -o /var/jenkins/hang.zip -d /var/lib/jenkins/
RUN chown -R jenkins:jenkins /vaR/lib/jenkins
RUN service jenkins restart
EXEC tail -f /etc/passwd
EXPOSE 8080
I am in the directory where the Dockerfile is, when trying to run this command.
Ignore the zip part, as that's for later use
You should run docker build first (which actually uses your Dockerfile):
docker build --tag=imagename .
Or
docker build --tag=imagename -f yourDockerfile .
Then you would use that image tag to docker run it:
docker run imagename
There are tools that can provide this type of feature.
We have achieved using docker compose, though you have to go through
(https://docs.docker.com/compose/overview/)
docker-compose up
but you can also do as work around
$ docker build -t foo . && docker run foo.
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.