The command '/bin/sh -c apt-get update && apt-get upgrade' returned a non-zero code: 1

Viewed 37

I do get the error message below, while trying to build an Image from a dockerfile. Any suggestions?

Error Message: The command '/bin/sh -c apt-get update && apt-get upgrade' returned a non-zero code: 1

Dockerfile screenshot

FROM ubuntu
Maintainer ......
RUN apt-get update && apt-get upgrade
CMD ["echo", "Hello World! from my first docker inage"]

After running the build command screenshot

Sending build context to Docker daemon 3.072kB
Step 1/4: FROM ubuntu
2dc39ba059dc
step 2/4: Maintainer ......
Using cache
-cdea9811b463
Step 3/4 RUN apt-get update 8& apt-get upgrade
Running in 34e13241a292
Get:1 http://archive. ubuntu.con/ubuntu janmy InRe lease [270 kBJ
Get:2 http://security. ubuntu.com/ubuntu jammy- security InRelease [110 kB]
Get:3 http://archive.ubuntu.com/ubuntu janmy-updates InRelease [114 kB]
Get:4 http://archive.ubuntu.coM/ubuntu jammy-backportS INRelease [99.8 kB]
Get:5 http://archive.ubuntu. com/ubuntu jamny/universe and 64 Packages [17.5 MB]
Get:6 http://security.ubuntu.com/ubuntu jamny- security/restrieted amd64 Packages |353 KB]
Get:7 http://security. ubuntu .com/ubuntu jamny-security/universe amd64 Packages [148 kB]
Get:8 http://security.ubuntu .com/ubuntu jamny-security/main amd 64 Packages |372 kB]
Get:9 http://security.ubuntu.com/ubuntu jamny-security/multiverse amd64 Packages [4644 B]
Get:10 http://archive. ubuntu.com/ubuntu jammy/restricted amd64 Packages [164 kB]
Get:11 http://archive. ubuntu .com/ubuntu Jamny/maln amd64 PackageS |1792 KBJ
Get:12 http:://archive.ubuntu .com/ubuntu jamny/multiverse amdő4 Packages [266 kB]
Get:13 http://archive. ubuntu.com/ubuntu jamny- updates /multiverse and64 Packages [7791 B]
Get:14 http://archive. ubuntu.com/ubuntu jammy-updates/main amd 64 Packages [694 kB]
Get: 15 http://archive. ubuntu.com/ubuntu jamny- updates/restricted and 64 Packages [394 kB]
Get:16 http://archive.ubuntu. com/ubuntu jamny-updates/untverse and64 Packages 325 KB]
Get:17 http://archive. ubuntu.com/ubuntu jamny-backports/main amdó4 Packages [3175 B]I
Get:18 http://archive. ubuntu.com/ubuntu jammy- backports/universe amd64 Packages [7285 B]
Fetched 22.6 MB in 7s (3094 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree.
Reading state information...
Galculating upgrade..
The following packages will be upgraded :
zlib1g
1 upgraded, 0 newly installed, 6 to remove and o not upgraded.
Need to get 58.4 KB of archives.
After this operation, 0 B off additional disk space will be used.
Do you want to continue? [Y/n] Abort.
The comnand /bin/sh -C apt-get update && apt-get upgrade' returned a non -zero code: 1
1 Answers

From the screenshot it looks like that apt-get upgrade was aborted. To automatically confirm apt-get's Y/n prompts, you can specify -y flag.

So change RUN line in your Dockerfile to apt-get update && apt-get -y upgrade

-y, --yes, --assume-yes
           Automatic yes to prompts; assume "yes" as answer to all prompts and
           run non-interactively. If an undesirable situation, such as
           changing a held package, trying to install a unauthenticated
           package or removing an essential package occurs then apt-get will
           abort. Configuration Item: APT::Get::Assume-Yes.  
Related