Docker Community Forums

Share and learn in the Docker community.

How can I get curl installed in ubuntu:1604 image


(Simplehuman) #1

My platform:
Windows 10; Version 1707
Docker version:
Version: 17.12.0-ce
API version: 1.35
Go version: go1.9.2
Git commit: c97c6d6
Built: Wed Dec 27 20:05:22 2017
OS/Arch: windows/amd64

I have been following a tutorial that requires me to run Ubuntu 16.04, so I downloaded the docker image, and I have started it as follows:

docker run -it ubuntu:16.04 bash

When I get the # prompt, however I’m unable to run curl command, I just get this error:
bash: curl: command not found

I’ve tried looking up instructions on how to install the curl command but none of the commands like sudo or wget are found either. Need help to get past this. Thx


(Sam) #2
docker exec container_id  apt-get install curl wget

docker exec runs as root usually


(Simplehuman) #3

Ok, I started ubuntu container in one Window power shell. Then, in another PowerShell window, I ran this command and got this response:

PS C:\WINDOWS\system32> docker exec cd23d0f0164b apt-get install curl
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package curl
PS C:\WINDOWS\system32>

(Sam) #4

sorry, add
docker exec container_id apt-get update
before the rest of the commands


(Simplehuman) #5

I ran docker exec cd23d0f0164b apt-get update curl, but it got an error, so I just ran docker exec cd23d0f0164b apt-get update and it did ‘something’. But when I switch over to my other window that runs my container, it still doesn’t recognize the curl command

PS C:\WINDOWS\system32> docker exec cd23d0f0164b apt-get update curl
E: The update command takes no arguments
PS C:\WINDOWS\system32> docker exec cd23d0f0164b apt-get update
Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
Get:3 http://security.ubuntu.com/ubuntu xenial-security/universe Sources [56.8 kB]
Get:4 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [539 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Get:6 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Get:7 http://archive.ubuntu.com/ubuntu xenial/universe Sources [9802 kB]
Get:8 http://security.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [12.7 kB]
Get:9 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [245 kB]
Get:10 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [3492 B]
Get:11 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1558 kB]
Get:12 http://archive.ubuntu.com/ubuntu xenial/restricted amd64 Packages [14.1 kB]
Get:13 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [9827 kB]
Get:14 http://archive.ubuntu.com/ubuntu xenial/multiverse amd64 Packages [176 kB]
Get:15 http://archive.ubuntu.com/ubuntu xenial-updates/universe Sources [234 kB]
Get:16 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [903 kB]
Get:17 http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [13.1 kB]
Get:18 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [735 kB]
Get:19 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [18.5 kB]
Get:20 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [5162 B]
Get:21 http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [7146 B]
Fetched 24.7 MB in 47s (515 kB/s)
Reading package lists...

(Sam) #6

docker exec container_id apt-get update
then
docker exec container_id apt-get install curl wget

then try to issue the curl command


(Simplehuman) #7

It tries to run, but then it Aborts… as shown below, without giving me a chance to answer: Yes

PS C:\WINDOWS\system32> docker exec faba5562b6df apt-get install curl
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  ca-certificates krb5-locales libasn1-8-heimdal libcurl3-gnutls libffi6
  libgmp10 libgnutls30 libgssapi-krb5-2 libgssapi3-heimdal libhcrypto4-heimdal
  libheimbase1-heimdal libheimntlm0-heimdal libhogweed4 libhx509-5-heimdal
  libidn11 libk5crypto3 libkeyutils1 libkrb5-26-heimdal libkrb5-3
  libkrb5support0 libldap-2.4-2 libnettle6 libp11-kit0 libroken18-heimdal
  librtmp1 libsasl2-2 libsasl2-modules libsasl2-modules-db libsqlite3-0
  libssl1.0.0 libtasn1-6 libwind0-heimdal openssl
Suggested packages:
  gnutls-bin krb5-doc krb5-user libsasl2-modules-otp libsasl2-modules-ldap
  libsasl2-modules-sql libsasl2-modules-gssapi-mit
  | libsasl2-modules-gssapi-heimdal
The following NEW packages will be installed:
  ca-certificates curl krb5-locales libasn1-8-heimdal libcurl3-gnutls libffi6
  libgmp10 libgnutls30 libgssapi-krb5-2 libgssapi3-heimdal libhcrypto4-heimdal
  libheimbase1-heimdal libheimntlm0-heimdal libhogweed4 libhx509-5-heimdal
  libidn11 libk5crypto3 libkeyutils1 libkrb5-26-heimdal libkrb5-3
  libkrb5support0 libldap-2.4-2 libnettle6 libp11-kit0 libroken18-heimdal
  librtmp1 libsasl2-2 libsasl2-modules libsasl2-modules-db libsqlite3-0
  libssl1.0.0 libtasn1-6 libwind0-heimdal openssl
0 upgraded, 34 newly installed, 0 to remove and 0 not upgraded.
Need to get 5343 kB of archives.
After this operation, 19.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] Abort.
PS C:\WINDOWS\system32>

(Sam) #8

docker exec container_id apt-get install -y curl wget


(Simplehuman) #9

You’ve been very patient with me, thank you very much.

It worked.


(Simplehuman) #10

One last thing: since I have done the update and install to the Container, not the Image, how can I preserve those changes so that I don’t have to repeat that every time I start a new container?!


(Sam) #11

you will have to build a custom image

create Dockerfile

from ubuntu:16.04
run apt-get update
run apt-get install curl wget

then

docker build -t my_ubuntu .

then from now on run my_ubuntu


(Sam) #12

you can also docker commit container_id my_ubuntu to save to exact container and then use my_ubuntu going forward…

BUT, you cannot rebuild it (from the committed image)… better to start with Dockerfile and be in control