Can't run Curl command inside my Docker Container - docker

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

Related

Error for Curl in docker file in .net core 6.0

I have modified the docker file as per the recommendations for .net core6.0.
However i face error in executing the curl url in the docker file.
The command is:
RUN curl https://raw.githubusercontent.com/rdvojmoc/DinkToPdf/master/v0.12.4/64%20bit/libwkhtmltox.so --output libwkhtmltox.so
While deploying i get the error:
... docker build: executor failed running [/bin/sh -c curl https://raw.githubusercontent.com/rdvojmoc/DinkToPdf/master/v0.12.4/64%20bit/libwkhtmltox.so --output libwkhtmltox.so]: exit code: 127
Can anyone please provide any clue?
How to execute the curl urls in docker file for .net core 6.0
Chances are that curl isn't installed in the container. You could install it by adding the line
RUN apt-get update \
&& apt-get install -y curl
This would be as in the Dockerfile
FROM mcr.microsoft.com/dotnet/aspnet:6.0
RUN apt-get update \
&& apt-get install -y curl
CMD ["curl", "google.com"]

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.

/bin/sh: 1: sudo: not found when running dockerfile

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.

"Can not connect to Docker Daemon"

I have a project in which I need to use CircleCi to build a docker application image, and then upload it to the Amazon container repository.
Given that CircleCI also runs on Docker, I created a Docker image for it, which containers a version of Ubuntu, together with AWS CLI, Node and Docker. See Dockerfile below:
FROM ubuntu:16.04
# update libraries
RUN apt-get update
RUN apt-get install -y apt-transport-https ca-certificates curl software-properties-common
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# install docker
RUN apt-get update
RUN apt-cache policy docker-ce
RUN apt-get install -y docker-ce
# <---
RUN systemctl status docker # <--- TROUBLE HERE
# <---
# install node
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt install -y nodejs
# install aws cli
RUN apt-get install -y python-pip python-dev build-essential
RUN pip install --upgrade pip
RUN pip install awscli --upgrade
I am currently having some problems working with this CircleCi docker image, because, if i keep the command RUN systemctl status docker I get the following error:
Failed to connect to bus: No such file or directory The command '/bin/sh -c systemctl status docker' returned a non-zero code: 1
If, on the other, I remove that command, the build is sucessful. However, when I go inside docker sudo docker run -it unad16 and run any docker command, as, f.e., docker images, I get the following error:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
I have been trying to debug this error since yesterday, but have been unsucessfull. Thus, any help would be truly appreciated.
Notes:
the "daemon" error occurs even when I run docker in priviled mode with sudo docker run -ti --privileged=true unad16
You don't need to run a docker daemon if you want to build a docker image in circleci. Instead you just need an image with docker client, and a circle config with - setup_remote_docker.
Read more in
https://circleci.com/docs/2.0/building-docker-images/
If for some other reason you still want to run a docker service in a docker image, please refer to DockerInDocker repo, especially the README.md part.

boot2docker / docker "Error. image library/.:latest not found"

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.

Resources