194

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.

2
  • Why not just install curl from zip ? Is curl anywhere on your disk ? Commented Jan 2, 2016 at 23:18
  • 2
    based on Ubuntu image you can use apt-get install curl -y. RUN apt-get update && apt-get upgrade -y && apt-get install curl -y CMD /bin/bash Commented Jul 22, 2020 at 13:37

10 Answers 10

364

curl: command not found

is a big hint, you have to install it with :

apt-get -y update; apt-get -y install curl
Sign up to request clarification or add additional context in comments.

7 Comments

u've assumed that it will be a debian image. right answer in this case , but what about smaller unix images, any help ?
/bin/sh: apt-get: not found What now?
@mahboudz it means that the image you are using has another package manager. Which image are you using? Other common ones are yum and dnf, i.e. you may want to try yum install curl or dnf install curl
I have this in my docker file, I can see curl being installed when I build my docker file, yet I still get "curl: command not found"
In my case, the solution was slightly different: apk update; apk add curl
|
77

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

2 Comments

Installing curl but if you are in control of the command using curl, realize that wget may be pre-installed in the container already, so if you rewrite the curl syntax to use wget instead, the result could be a smaller container image.
This generates an error: E: List directory /var/lib/apt/lists/partial is missing. - Acquire (13: Permission denied)
60

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

Comments

23

If you are using an Alpine based docker image, you should do this

RUN
... \
apk add --no-cache curl \
curl ...
...

2 Comments

Why --no-cache?
Hm, understood: we don't want cached package file to be left in our image. Nice touch.
17

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.

1 Comment

Installing zsh is not relevant to the solution.
15

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

3 Comments

less time consuming compared to the accepted answer. Just one question though. Does ADD command download the file locally and then adds the file to the image or the download happens within the image?
@RajaAnbazhagan It's downloaded during docker build process of your Dockerfile (which runs on your host). Since it's built directly by Docker process, I assume it's downloading the file directly to your image.
Cool answer, thanks a lot! One more question: should I remove this file later in Dockerfile?
2

what worked successfully for me was:

FROM ubuntu:20.0.4

RUN apt-get update &&\
   apt-get install -y curl
...

Comments

2

This error usually occurs when the tool you are using to test the healthy check is not vailable in your container. I explain. Let suppose that in your docker compose, under health check you have :

> ["CMD", "curl", "-f", "http://localhost"].

If "curl" is not yet installed in your container obviously, nothing can be tested. So use this :

> healthcheck:
      > test: ["CMD-SHELL", "wget --spider - 
      > http://localhost:5000/health 
      > || exit 1"]
      > interval: 30s
      > timeout: 10s
      > retries: 5
      > start_period: 20s

or simply you can edit your docker file by adding :

> RUN apt-get update && apt-get install -y curl

Comments

1

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

Comments

0

To me, the most straightforward solution was just to use wget instead of curl. wget is already installed in the bash images.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.