Disclaimer
I know that what you are about to see is probably REALLY gross - so you might want to make sure you’re near a proper receptacle in case you can’t hold back…
Problem Description
I made my first own Dockerfile of something I actually want (not just one of the practice exercises). I ran each of the commands I put in the RUN
directive on the official base image in an interactive terminal before writing my Dockerfile and it worked just fine on the official base image.
docker pull ubuntu:22.04 && docker run -it ubuntu:22.04
# then ran each command seen in my Dockerfile in the same order they appear there
Dockerfile
FROM ubuntu:22.04
RUN apt update\
&& apt install curl -y\
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash\
&& source ~/.bashrc\
&& nvm install --lts\
&& npm install -g npm
Output
$ docker build -t my-node:ubuntu-22.04 .
[+] Building 27.1s (5/5) FINISHED
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 265B 0.0s
=> [internal] load metadata for docker.io/library/ubuntu:22.04 0.0s
=> CACHED [1/2] FROM docker.io/library/ubuntu:22.04 0.0s
=> ERROR [2/2] RUN apt update && apt install curl -y && curl -o- https://raw.githubusercontent.com/nvm-sh/n 27.0s
------
> [2/2] RUN apt update && apt install curl -y && curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash && source ~/.bashrc && nvm install --lts && npm install -g npm:
#0 0.242
#0 0.242 WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
#0 0.242
#0 1.125 Get:1 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
#0 1.125 Get:2 http://archive.ubuntu.com/ubuntu jammy InRelease [270 kB]
#0 2.261 Get:3 http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages [869 kB]
#0 2.480 Get:4 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
#0 2.954 Get:5 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [107 kB]
#0 3.296 Get:6 http://security.ubuntu.com/ubuntu jammy-security/multiverse amd64 Packages [23.2 kB]
#0 3.301 Get:7 http://security.ubuntu.com/ubuntu jammy-security/restricted amd64 Packages [829 kB]
#0 3.645 Get:8 http://archive.ubuntu.com/ubuntu jammy/universe amd64 Packages [17.5 MB]
#0 4.003 Get:9 http://security.ubuntu.com/ubuntu jammy-security/universe amd64 Packages [905 kB]
#0 12.86 Get:10 http://archive.ubuntu.com/ubuntu jammy/multiverse amd64 Packages [266 kB]
#0 12.86 Get:11 http://archive.ubuntu.com/ubuntu jammy/restricted amd64 Packages [164 kB]
#0 12.87 Get:12 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages [1792 kB]
#0 13.49 Get:13 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages [1199 kB]
#0 13.52 Get:14 http://archive.ubuntu.com/ubuntu jammy-updates/multiverse amd64 Packages [28.6 kB]
#0 13.53 Get:15 http://archive.ubuntu.com/ubuntu jammy-updates/restricted amd64 Packages [885 kB]
#0 14.22 Get:16 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 Packages [1142 kB]
#0 15.15 Get:17 http://archive.ubuntu.com/ubuntu jammy-backports/main amd64 Packages [49.0 kB]
#0 15.87 Get:18 http://archive.ubuntu.com/ubuntu jammy-backports/universe amd64 Packages [22.4 kB]
#0 15.92 Fetched 26.3 MB in 16s (1675 kB/s)
#0 15.92 Reading package lists...
#0 16.43 Building dependency tree...
#0 16.54 Reading state information...
#0 16.54 All packages are up to date.
#0 16.55
#0 16.55 WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
#0 16.55
#0 16.57 Reading package lists...
#0 17.05 Building dependency tree...
#0 17.15 Reading state information...
#0 17.23 The following additional packages will be installed:
#0 17.23 ca-certificates libbrotli1 libcurl4 libldap-2.5-0 libldap-common
#0 17.23 libnghttp2-14 libpsl5 librtmp1 libsasl2-2 libsasl2-modules
#0 17.23 libsasl2-modules-db libssh-4 openssl publicsuffix
#0 17.23 Suggested packages:
#0 17.23 libsasl2-modules-gssapi-mit | libsasl2-modules-gssapi-heimdal
#0 17.23 libsasl2-modules-ldap libsasl2-modules-otp libsasl2-modules-sql
#0 17.25 The following NEW packages will be installed:
#0 17.25 ca-certificates curl libbrotli1 libcurl4 libldap-2.5-0 libldap-common
#0 17.26 libnghttp2-14 libpsl5 librtmp1 libsasl2-2 libsasl2-modules
#0 17.26 libsasl2-modules-db libssh-4 openssl publicsuffix
#0 18.01 0 upgraded, 15 newly installed, 0 to remove and 0 not upgraded.
#0 18.01 Need to get 2977 kB of archives.
#0 18.01 After this operation, 7100 kB of additional disk space will be used.
#0 18.01 Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 openssl amd64 3.0.2-0ubuntu1.8 [1184 kB]
#0 19.81 Get:2 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 ca-certificates all 20211016ubuntu0.22.04.1 [144 kB]
#0 20.22 Get:3 http://archive.ubuntu.com/ubuntu jammy/main amd64 libnghttp2-14 amd64 1.43.0-1build3 [76.3 kB]
#0 20.23 Get:4 http://archive.ubuntu.com/ubuntu jammy/main amd64 libpsl5 amd64 0.21.0-1.2build2 [58.4 kB]
#0 20.23 Get:5 http://archive.ubuntu.com/ubuntu jammy/main amd64 publicsuffix all 20211207.1025-1 [129 kB]
#0 20.28 Get:6 http://archive.ubuntu.com/ubuntu jammy/main amd64 libbrotli1 amd64 1.0.9-2build6 [315 kB]
#0 20.28 Get:7 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 libsasl2-modules-db amd64 2.1.27+dfsg2-3ubuntu1.2 [20.5 kB]
#0 20.28 Get:8 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 libsasl2-2 amd64 2.1.27+dfsg2-3ubuntu1.2 [53.8 kB]
#0 20.28 Get:9 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 libldap-2.5-0 amd64 2.5.14+dfsg-0ubuntu0.22.04.1 [183 kB]
#0 20.28 Get:10 http://archive.ubuntu.com/ubuntu jammy/main amd64 librtmp1 amd64 2.4+20151223.gitfa8646d.1-2build4 [58.2 kB]
#0 20.28 Get:11 http://archive.ubuntu.com/ubuntu jammy/main amd64 libssh-4 amd64 0.9.6-2build1 [184 kB]
#0 21.30 Get:12 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 libcurl4 amd64 7.81.0-1ubuntu1.10 [290 kB]
#0 22.67 Get:13 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 curl amd64 7.81.0-1ubuntu1.10 [194 kB]
#0 22.75 Get:14 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 libldap-common all 2.5.14+dfsg-0ubuntu0.22.04.1 [15.9 kB]
#0 22.76 Get:15 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 libsasl2-modules amd64 2.1.27+dfsg2-3ubuntu1.2 [68.8 kB]
#0 23.03 debconf: delaying package configuration, since apt-utils is not installed
#0 23.05 Fetched 2977 kB in 6s (522 kB/s)
#0 23.06 Selecting previously unselected package openssl.
(Reading database ... 4395 files and directories currently installed.)
#0 23.08 Preparing to unpack .../00-openssl_3.0.2-0ubuntu1.8_amd64.deb ...
#0 23.08 Unpacking openssl (3.0.2-0ubuntu1.8) ...
#0 23.11 Selecting previously unselected package ca-certificates.
#0 23.11 Preparing to unpack .../01-ca-certificates_20211016ubuntu0.22.04.1_all.deb ...
#0 23.11 Unpacking ca-certificates (20211016ubuntu0.22.04.1) ...
#0 23.14 Selecting previously unselected package libnghttp2-14:amd64.
#0 23.14 Preparing to unpack .../02-libnghttp2-14_1.43.0-1build3_amd64.deb ...
#0 23.14 Unpacking libnghttp2-14:amd64 (1.43.0-1build3) ...
#0 23.16 Selecting previously unselected package libpsl5:amd64.
#0 23.16 Preparing to unpack .../03-libpsl5_0.21.0-1.2build2_amd64.deb ...
#0 23.16 Unpacking libpsl5:amd64 (0.21.0-1.2build2) ...
#0 23.18 Selecting previously unselected package publicsuffix.
#0 23.18 Preparing to unpack .../04-publicsuffix_20211207.1025-1_all.deb ...
#0 23.18 Unpacking publicsuffix (20211207.1025-1) ...
#0 23.20 Selecting previously unselected package libbrotli1:amd64.
#0 23.20 Preparing to unpack .../05-libbrotli1_1.0.9-2build6_amd64.deb ...
#0 23.20 Unpacking libbrotli1:amd64 (1.0.9-2build6) ...
#0 23.22 Selecting previously unselected package libsasl2-modules-db:amd64.
#0 23.22 Preparing to unpack .../06-libsasl2-modules-db_2.1.27+dfsg2-3ubuntu1.2_amd64.deb ...
#0 23.22 Unpacking libsasl2-modules-db:amd64 (2.1.27+dfsg2-3ubuntu1.2) ...
#0 23.24 Selecting previously unselected package libsasl2-2:amd64.
#0 23.24 Preparing to unpack .../07-libsasl2-2_2.1.27+dfsg2-3ubuntu1.2_amd64.deb ...
#0 23.24 Unpacking libsasl2-2:amd64 (2.1.27+dfsg2-3ubuntu1.2) ...
#0 23.26 Selecting previously unselected package libldap-2.5-0:amd64.
#0 23.26 Preparing to unpack .../08-libldap-2.5-0_2.5.14+dfsg-0ubuntu0.22.04.1_amd64.deb ...
#0 23.26 Unpacking libldap-2.5-0:amd64 (2.5.14+dfsg-0ubuntu0.22.04.1) ...
#0 23.28 Selecting previously unselected package librtmp1:amd64.
#0 23.28 Preparing to unpack .../09-librtmp1_2.4+20151223.gitfa8646d.1-2build4_amd64.deb ...
#0 23.28 Unpacking librtmp1:amd64 (2.4+20151223.gitfa8646d.1-2build4) ...
#0 23.30 Selecting previously unselected package libssh-4:amd64.
#0 23.30 Preparing to unpack .../10-libssh-4_0.9.6-2build1_amd64.deb ...
#0 23.30 Unpacking libssh-4:amd64 (0.9.6-2build1) ...
#0 23.32 Selecting previously unselected package libcurl4:amd64.
#0 23.32 Preparing to unpack .../11-libcurl4_7.81.0-1ubuntu1.10_amd64.deb ...
#0 23.32 Unpacking libcurl4:amd64 (7.81.0-1ubuntu1.10) ...
#0 23.34 Selecting previously unselected package curl.
#0 23.34 Preparing to unpack .../12-curl_7.81.0-1ubuntu1.10_amd64.deb ...
#0 23.34 Unpacking curl (7.81.0-1ubuntu1.10) ...
#0 23.36 Selecting previously unselected package libldap-common.
#0 23.36 Preparing to unpack .../13-libldap-common_2.5.14+dfsg-0ubuntu0.22.04.1_all.deb ...
#0 23.36 Unpacking libldap-common (2.5.14+dfsg-0ubuntu0.22.04.1) ...
#0 23.38 Selecting previously unselected package libsasl2-modules:amd64.
#0 23.38 Preparing to unpack .../14-libsasl2-modules_2.1.27+dfsg2-3ubuntu1.2_amd64.deb ...
#0 23.38 Unpacking libsasl2-modules:amd64 (2.1.27+dfsg2-3ubuntu1.2) ...
#0 23.40 Setting up libpsl5:amd64 (0.21.0-1.2build2) ...
#0 23.40 Setting up libbrotli1:amd64 (1.0.9-2build6) ...
#0 23.41 Setting up libsasl2-modules:amd64 (2.1.27+dfsg2-3ubuntu1.2) ...
#0 23.42 Setting up libnghttp2-14:amd64 (1.43.0-1build3) ...
#0 23.43 Setting up libldap-common (2.5.14+dfsg-0ubuntu0.22.04.1) ...
#0 23.43 Setting up libsasl2-modules-db:amd64 (2.1.27+dfsg2-3ubuntu1.2) ...
#0 23.44 Setting up librtmp1:amd64 (2.4+20151223.gitfa8646d.1-2build4) ...
#0 23.45 Setting up libsasl2-2:amd64 (2.1.27+dfsg2-3ubuntu1.2) ...
#0 23.45 Setting up libssh-4:amd64 (0.9.6-2build1) ...
#0 23.46 Setting up openssl (3.0.2-0ubuntu1.8) ...
#0 23.47 Setting up publicsuffix (20211207.1025-1) ...
#0 23.47 Setting up libldap-2.5-0:amd64 (2.5.14+dfsg-0ubuntu0.22.04.1) ...
#0 23.48 Setting up ca-certificates (20211016ubuntu0.22.04.1) ...
#0 23.53 debconf: unable to initialize frontend: Dialog
#0 23.53 debconf: (TERM is not set, so the dialog frontend is not usable.)
#0 23.53 debconf: falling back to frontend: Readline
#0 23.53 debconf: unable to initialize frontend: Readline
#0 23.53 debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.34.0 /usr/local/share/perl/5.34.0 /usr/lib/x86_64-linux-gnu/perl5/5.34 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl-base /usr/lib/x86_64-linux-gnu/perl/5.34 /usr/share/perl/5.34 /usr/local/lib/site_perl) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
#0 23.53 debconf: falling back to frontend: Teletype
#0 23.70 Updating certificates in /etc/ssl/certs...
#0 23.95 124 added, 0 removed; done.
#0 23.96 Setting up libcurl4:amd64 (7.81.0-1ubuntu1.10) ...
#0 23.97 Setting up curl (7.81.0-1ubuntu1.10) ...
#0 23.98 Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
#0 24.01 Processing triggers for ca-certificates (20211016ubuntu0.22.04.1) ...
#0 24.02 Updating certificates in /etc/ssl/certs...
#0 24.18 0 added, 0 removed; done.
#0 24.18 Running hooks in /etc/ca-certificates/update.d...
#0 24.19 done.
#0 24.21 % Total % Received % Xferd Average Speed Time Time Time Current
#0 24.21 Dload Upload Total Spent Left Speed
100 15916 100 15916 0 0 13420 0 0:00:01 0:00:01 --:--:-- 13431
#0 25.40 => Downloading nvm as script to '/root/.nvm'
#0 26.93
#0 26.93 => Appending nvm source string to /root/.bashrc
#0 26.94 => Appending bash_completion source string to /root/.bashrc
#0 26.96 => Close and reopen your terminal to start using nvm or run the following to use it now:
#0 26.96
#0 26.96 export NVM_DIR="$HOME/.nvm"
#0 26.96 [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
#0 26.96 [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
#0 26.96 /bin/sh: 1: source: not found
------
Dockerfile:2
--------------------
1 | FROM ubuntu:22.04
2 | >>> RUN apt update\
3 | >>> && apt install curl -y\
4 | >>> && curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash\
5 | >>> && source ~/.bashrc\
6 | >>> && nvm install --lts\
7 | >>> && npm install -g npm
--------------------
ERROR: failed to solve: process "/bin/sh -c apt update && apt install curl -y && curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash && source ~/.bashrc && nvm install --lts && npm install -g npm" did not complete successfully: exit code: 127
Observations
I notice the line ... /bin/sh: 1: source: not found
in the output but when I ran the source command in the official base image (to test) it worked fine and I was able to execute the succeeding commands without any issue. I did not have to install the source command in the official image I use for my base iin Dockerfile - it was just there available by default.
Unless that line in the output is referring to something else.
Humble Request
Can anyone identify what I’m doing wrong and offer suggestions for improvement?