This is the content of my Dockerfile.
FROM ubuntu
RUN sudo apt-get update
RUN sudo apt-get install -y wget
CMD wget -O- -q http://ifconfig.me/ip
When I run the Dockerfile to build a docker image, I get the below error:
/bin/sh: 1: sudo: not found
Can you please help me in solving the above error?
by default docker container runs as root user
remove the sudo from Dockerfile and run again.
Your commands in the Dockerfile already run as root during docker build. For this reason you do not need to use sudo
You don't need sudo in this case. Change Dockerfile as below -
FROM ubuntu
RUN apt-get update -y && \
apt-get install -y wget
CMD wget -O- -q http://ifconfig.me/ip
PS - Merge the RUN statements as much as possible.
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
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.
I created a docker container from my OS X VM Docker host. I created it using the run command and created the container based off the ubuntu:xenial image off docker hub.
I'm now connected to my container after it's created and logged in as root and at the command prompt inside my container.
I tried to install homebrew and for some reason, I can't run the command to install Homebrew:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
when I run that I get a bash:
curl: command not found
Not sure why I'm not able to use curl here inside my container.
curl: command not found
is a big hint, you have to install it with :
apt-get -y update; apt-get -y install curl
Ran into this same issue while using the CURL command inside my Dockerfile. As Gilles pointed out, we have to install curl first. These are the commands to be added in the 'Dockerfile'.
FROM ubuntu:16.04
# Install prerequisites
RUN apt-get update && apt-get install -y \
curl
CMD /bin/bash
So I added curl AFTER my docker container was running.
(This was for debugging the container...I did not need a permanent addition)
I ran my image
docker run -d -p 8899:8080 my-image:latest
(the above makes my "app" available on my machine on port 8899) (not important to this question)
Then I listed and created terminal into the running container.
docker ps
docker exec -it my-container-id-here /bin/sh
If the exec command above does not work, check this SOF article:
Error: Cannot Start Container: stat /bin/sh: no such file or directory"
then I ran:
apk
just to prove it existed in the running container, then i ran:
apk add curl
and got the below:
apk add curl
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
(1/5) Installing ca-certificates (20171114-r3)
(2/5) Installing nghttp2-libs (1.32.0-r0)
(3/5) Installing libssh2 (1.8.0-r3)
(4/5) Installing libcurl (7.61.1-r1)
(5/5) Installing curl (7.61.1-r1)
Executing busybox-1.28.4-r2.trigger
Executing ca-certificates-20171114-r3.trigger
OK: 18 MiB in 35 packages
then i ran curl:
/ # curl
curl: try 'curl --help' or 'curl --manual' for more information
/ #
Note, to get "out" of the drilled-in-terminal-window, I had to open a new terminal window and stop the running container:
docker ps
docker stop my-container-id-here
APPEND:
If you don't have "apk" (which depends on which base image you are using), then try to use "another" installer. From other answers here, you can try:
apt-get -qq update
apt-get -qq -y install curl
This is happening because there is no package cache in the image, you need to run:
apt-get -qq update
before installing packages, and if your command is in a Dockerfile, you'll then need:
apt-get -qq -y install curl
After that install ZSH and GIT Core:
apt-get install zsh
apt-get install git-core
Getting zsh to work in ubuntu is weird since sh does not understand the source command. So, you do this to install zsh:
wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh
and then you change your shell to zsh:
chsh -s `which zsh`
and then restart:
sudo shutdown -r 0
This problem is explained in depth in this issue.
If you are using an Alpine based image, you should do
RUN
... \
apk add --no-cache curl \
curl ...
...
You don't need to install curl to download the file into Docker container, use ADD command, e.g.
ADD https://raw.githubusercontent.com/Homebrew/install/master/install /tmp
RUN ruby -e /tmp/install
Note: Add above lines to your Dockerfile file.
Another example which installs Azure CLI:
ADD https://aka.ms/InstallAzureCLIDeb /tmp
RUN bash /tmp/InstallAzureCLIDeb
what worked successfully for me was:
FROM ubuntu:20.0.4
RUN apt-get update &&\
apt-get install -y curl
...
You could base your image on one that already has curl.
A minimalistic one:
FROM alpine/curl
or a full-fledged one:
FROM rockylinux:9
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 following cloudera cdh4 installation guide.
My base file
FROM ubuntu:precise
RUN apt-get update -y
#RUN apt-get install -y curl
RUN apt-get install -y software-properties-common python-software-properties
RUN add-apt-repository ppa:webupd8team/java
RUN apt-get update -y
RUN echo debconf shared/accepted-oracle-license-v1-1 select true | \
debconf-set-selections
RUN apt-get install -y oracle-java7-installer
#Checking java version
RUN java -version
My hadoop installation file
java_ubuntu is the image build from my base file.
FROM java_ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y curl
RUN curl http://archive.cloudera.com/cdh4/one-click-install/precise/amd64/cdh4-repository_1.0_all.deb > cdh4-repository_1.0_all.deb
RUN dpkg -i cdh4-repository_1.0_all.deb
RUN curl -s http://archive.cloudera.com/cdh4/ubuntu/precise/amd64/cdh/archive.key | apt-key add -
RUN apt-get update -y
RUN apt-get install -y hadoop-0.20-conf-pseudo
#Check for /etc/hadoop/conf.pseudo.mrl to verfiy hadoop packages
RUN echo "dhis"
RUN dpkg -L hadoop-0.20-conf-pseudo
Supervisor part
hadoop_ubuntu is the image build from my hadoop installation docker file
FROM hadoop_ubuntu:latest
USER hdfs
RUN hdfs namenode -format
USER root
RUN apt-get install -y supervisor
RUN echo "[supervisord] nodameon=true [program=namenode] command=/etc/init.d/hadoop-hdfs-namenode -D" > /etc/supervisorconf.d
CMD ["/usr/bin/supervisord"]
Program is successfully build. But namenode is not starting up? How to use supervisor?
You have your config in /etc/supervisorconf.d and I don't believe that's the right location.
It should be /etc/supervisor/conf.d/supervisord.conf instead.
Also it's easier to maintain if you make a file locally and then use the COPY instruction to put it in the image.
Then as someone mentioned you can connect to the container after it's running (docker exec -it <container id> /bin/bash) and then run supervisorctl to see what's running and what might be wrong.
Perhaps you need line breaks in your supervisor.conf. Try hand crafting one and COPY it into your dockerfile for testing.
Docker and supervisord