Do you want to request a feature or report a bug?
bug
What is the current behavior?
Got the following error when trying to install yarn in unbuntu image:
The command '/bin/sh -c apt-get update && apt-get install yarn' returned a non-zero code: 1
If the current behavior is a bug, please provide the steps to reproduce.
Dockerfile:
FROM phusion/baseimage:0.9.22
USER root
# Install yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update && apt-get install yarn
RUN yarn --version
Error output:
Sending build context to Docker daemon 27.06MB
Step 1/18 : FROM phusion/baseimage:0.9.22
---> 877509368a8d
Step 2/18 : MAINTAINER William Lin <[email protected]>
---> Using cache
---> 1d36be40f2bc
Step 3/18 : USER root
---> Using cache
---> d27c57c3238c
Step 4/18 : RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
---> Using cache
---> 29d273829c5f
Step 5/18 : RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
---> Using cache
---> 38974f74094a
Step 6/18 : RUN apt-get update && apt-get install yarn
---> Running in 7310256d6b4b
Get:1 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Get:3 https://dl.yarnpkg.com/debian stable InRelease [11.5 kB]
Get:4 https://dl.yarnpkg.com/debian stable/main amd64 Packages [6,428 B]
Get:5 https://dl.yarnpkg.com/debian stable/main all Packages [6,428 B]
Get:6 http://security.ubuntu.com/ubuntu xenial-security/main Sources [121 kB]
Get:7 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Get:8 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Get:9 http://archive.ubuntu.com/ubuntu xenial/main Sources [1,103 kB]
Get:10 http://security.ubuntu.com/ubuntu xenial-security/restricted Sources [2,770 B]
Get:11 http://security.ubuntu.com/ubuntu xenial-security/universe Sources [50.7 kB]
Get:12 http://security.ubuntu.com/ubuntu xenial-security/multiverse Sources [1,077 B]
Get:13 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [476 kB]
Get:14 http://security.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [12.9 kB]
Get:15 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [220 kB]
Get:16 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [3,485 B]
Get:17 http://archive.ubuntu.com/ubuntu xenial/restricted Sources [5,179 B]
Get:18 http://archive.ubuntu.com/ubuntu xenial/universe Sources [9,802 kB]
Get:19 http://archive.ubuntu.com/ubuntu xenial/multiverse Sources [215 kB]
Get:20 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1,558 kB]
Get:21 http://archive.ubuntu.com/ubuntu xenial/restricted amd64 Packages [14.1 kB]
Get:22 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [9,827 kB]
Get:23 http://archive.ubuntu.com/ubuntu xenial/multiverse amd64 Packages [176 kB]
Get:24 http://archive.ubuntu.com/ubuntu xenial-updates/main Sources [352 kB]
Get:25 http://archive.ubuntu.com/ubuntu xenial-updates/restricted Sources [3,617 B]
Get:26 http://archive.ubuntu.com/ubuntu xenial-updates/universe Sources [221 kB]
Get:27 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse Sources [7,677 B]
Get:28 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [833 kB]
Get:29 http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [13.7 kB]
Get:30 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [692 kB]
Get:31 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [18.1 kB]
Get:32 http://archive.ubuntu.com/ubuntu xenial-backports/main Sources [3,506 B]
Get:33 http://archive.ubuntu.com/ubuntu xenial-backports/universe Sources [4,586 B]
Get:34 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [5,176 B]
Get:35 http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [6,354 B]
Fetched 26.3 MB in 4s (5,883 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
libicu55 libuv1 nodejs
The following NEW packages will be installed:
libicu55 libuv1 nodejs yarn
0 upgraded, 4 newly installed, 0 to remove and 56 not upgraded.
Need to get 11.5 MB of archives.
After this operation, 48.3 MB of additional disk space will be used.
Do you want to continue? [Y/n] Abort.
The command '/bin/sh -c apt-get update && apt-get install yarn' returned a non-zero code: 1
What is the expected behavior?
Please mention your node.js, yarn and operating system version.
I'm using this image which is based on ubuntu:16.04.
Hi!
The error quoted isn't actually the root cause of the problem. When seeing a message about a non-zero exit code, it's best to read further back in the log to try and spot the reason for it.
In this case there is:
Do you want to continue? [Y/n] Abort.
Googling that gives:
https://askubuntu.com/questions/509852/why-does-apt-get-abort-by-itself-as-though-id-pressed-n
ie: This isn't a problem with yarn.
apt-get was prompting the user for a yes/no answer, but since the commands in a Dockerfile are run non-interactively, it aborts since it's not going to receive one. Instead apt-get needs to be told not to ask for confirmation (the same as if it were being run from any regular unattended bash script) using apt-get install -y. See man apt-get for more information.
I'd also recommend reading:
https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/
...since I can see a few other problems with the Dockerfile above.
Thanks for the quick reply.
Problem solved!
Most helpful comment
Hi!
The error quoted isn't actually the root cause of the problem. When seeing a message about a non-zero exit code, it's best to read further back in the log to try and spot the reason for it.
In this case there is:
Do you want to continue? [Y/n] Abort.Googling that gives:
https://askubuntu.com/questions/509852/why-does-apt-get-abort-by-itself-as-though-id-pressed-n
ie: This isn't a problem with yarn.
apt-getwas prompting the user for a yes/no answer, but since the commands in a Dockerfile are run non-interactively, it aborts since it's not going to receive one. Instead apt-get needs to be told not to ask for confirmation (the same as if it were being run from any regular unattended bash script) usingapt-get install -y. Seeman apt-getfor more information.I'd also recommend reading:
https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/
...since I can see a few other problems with the Dockerfile above.