Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker RUN fails to execute shell script #24388

Closed
pcgeek86 opened this issue Jul 6, 2016 · 9 comments

Comments

@pcgeek86
Copy link
Contributor

commented Jul 6, 2016

Docker Version: 1.12.0-rc3
OS: Windows 10 RTM

Issue

  • Write a shell script with apt-get update inside it
  • Add below commands to Dockerfile
  • Run docker build
  • Result is:
Step 6 : RUN ./prereq.sh
 ---> Running in 550d795d169f
E: Invalid operation update

Dockerfile

FROM ubuntu:xenial
WORKDIR /root
COPY dockerimage/prereq.sh prereq.sh
RUN chmod +x prereq.sh
RUN ./prereq.sh

Expected Result

The shell script should be executed successfully.

Root Cause / Notes

I suspect that there's a problem with arguments getting passed to apt-get somehow. I have tried many different variations of this, and have encountered problems. Another scenario I attempted was:

prereq.sh

apt-get update -y
apt-get install -y python3
apt-get upgrade -y
apt-get clean -y

Dockerfile

FROM ubuntu:xenial
LABEL 'testing'
WORKDIR /root
COPY dockerimage/prereq.sh prereq.sh
RUN chmod +x prereq.sh
RUN ./prereq.sh

This scenario yielded the following, cryptic error:

Step 6 : RUN ./prereq.sh
 ---> Running in 0394ab71072c
] is not understood in combination with the other options.
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package python3
] is not understood in combination with the other options.
 ---> aa0da445f3b3

Cheers,
Trevor Sullivan

@pcgeek86 pcgeek86 changed the title Docker RUN fails to execute Docker RUN fails to execute shell script Jul 6, 2016

@jmaitrehenry

This comment has been minimized.

Copy link
Contributor

commented Jul 6, 2016

I just try it on Docker4Mac Version 1.12.0-rc3-beta18 (build: 9996) and Version 1.12.0-rc2-beta17 (build: 9779) and it works.

@justincormack

This comment has been minimized.

Copy link
Contributor

commented Jul 6, 2016

I can't replicate either.

@pcgeek86

This comment has been minimized.

Copy link
Contributor Author

commented Jul 6, 2016

Thanks -- seems to be an issue with Docker for Windows as best I can tell.

@pcgeek86

This comment has been minimized.

Copy link
Contributor Author

commented Jul 6, 2016

@justincormack What OS / version / etc?

@justincormack

This comment has been minimized.

Copy link
Contributor

commented Jul 6, 2016

Ah that was on Docker for Mac. Will test on Windows.
On 6 Jul 2016 10:27 p.m., "Trevor Sullivan" notifications@github.com
wrote:

@justincormack https://github.com/justincormack What OS / version / etc?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#24388 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AAdcPLkQI4mxt53NhQjUeBF4KLBd-69Zks5qTB2tgaJpZM4JGgH1
.

@ijc

This comment has been minimized.

Copy link
Contributor

commented Jul 27, 2016

I was able to reproduce this on native Linux by running unix2dos on prereq.sh and running dos2unix fixed it again. So I would conclude that this is down to the use of Windows line ending (\r\n) instead of Unix ones (\n). Since the docker build runs in a Unix environment it needs to use the latter.

@rn

This comment has been minimized.

Copy link
Member

commented Jul 27, 2016

Just to confirm was @ijc25 wrote, I was able to run your example below, but I created the files using vi in git-bash. Creating the file in notepad, ie with windows line endings I get the error you see.

I've tested this on Windows 10 Pro (build 10586)

I had to remove the LABEL line from the Dockerfile as it had a invalid syntax

I have:

.\Dockerfile
.\dockerimage\prereq.sh

In powershell, I get:

PS C:\Users\docker\Desktop\tmp> docker build .
Sending build context to Docker daemon 3.584 kB
Step 1 : FROM ubuntu:xenial
xenial: Pulling from library/ubuntu

43db9dbdcb30: Pull complete
2dc64e8f8d4f: Pull complete
670a583e1b50: Pull complete
183b0bfcd10e: Pull complete
Digest: sha256:c6674c44c6439673bf56536c1a15916639c47ea04c3d6296c5df938add67b54b
Status: Downloaded newer image for ubuntu:xenial
 ---> 42118e3df429
Step 2 : WORKDIR /root
 ---> Running in 6a1ae75da735
 ---> 486b1d36bf23
Removing intermediate container 6a1ae75da735
Step 3 : COPY dockerimage/prereq.sh prereq.sh
 ---> dbef00ffa9eb
Removing intermediate container 308e203ae02a
Step 4 : RUN chmod +x prereq.sh
 ---> Running in f5f7f1067772
 ---> fb93bc7c608f
Removing intermediate container f5f7f1067772
Step 5 : RUN ./prereq.sh
 ---> Running in c4903d5aa647
Get:1 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [95.7 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial-security InRelease [94.5 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial/main Sources [1103 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial/restricted Sources [5179 B]
Get:6 http://archive.ubuntu.com/ubuntu xenial/universe Sources [9802 kB]
Get:7 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1558 kB]
Get:8 http://archive.ubuntu.com/ubuntu xenial/restricted amd64 Packages [14.1 kB]
Get:9 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [9827 kB]
Get:10 http://archive.ubuntu.com/ubuntu xenial-updates/main Sources [212 kB]
Get:11 http://archive.ubuntu.com/ubuntu xenial-updates/universe Sources [106 kB]
Get:12 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [417 kB]
Get:13 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [374 kB]
Get:14 http://archive.ubuntu.com/ubuntu xenial-security/main Sources [39.2 kB]
Get:15 http://archive.ubuntu.com/ubuntu xenial-security/universe Sources [9617 B]
Get:16 http://archive.ubuntu.com/ubuntu xenial-security/main amd64 Packages [152 kB]
Get:17 http://archive.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [42.9 kB]
Fetched 24.1 MB in 7s (3129 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  dh-python file libexpat1 libmagic1 libmpdec2 libpython3-stdlib
  libpython3.5-minimal libpython3.5-stdlib libsqlite3-0 libssl1.0.0
  mime-support python3-minimal python3.5 python3.5-minimal
Suggested packages:
  libdpkg-perl python3-doc python3-tk python3-venv python3.5-venv
  python3.5-doc binutils binfmt-support
The following NEW packages will be installed:
  dh-python file libexpat1 libmagic1 libmpdec2 libpython3-stdlib
  libpython3.5-minimal libpython3.5-stdlib libsqlite3-0 libssl1.0.0
  mime-support python3 python3-minimal python3.5 python3.5-minimal
0 upgraded, 15 newly installed, 0 to remove and 5 not upgraded.
Need to get 6471 kB of archives.
After this operation, 33.3 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libssl1.0.0 amd64 1.0.2g-1ubuntu4.1 [1122 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libpython3.5-minimal amd64 3.5.2-2~16.01 [528 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libexpat1 amd64 2.1.0-7ubuntu0.16.04.2 [71.3 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 python3.5-minimal amd64 3.5.2-2~16.01 [1595 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial/main amd64 python3-minimal amd64 3.5.1-3 [23.3 kB]
Get:6 http://archive.ubuntu.com/ubuntu xenial/main amd64 mime-support all 3.59ubuntu1 [31.0 kB]
Get:7 http://archive.ubuntu.com/ubuntu xenial/main amd64 libmpdec2 amd64 2.4.2-1 [82.6 kB]
Get:8 http://archive.ubuntu.com/ubuntu xenial/main amd64 libsqlite3-0 amd64 3.11.0-1ubuntu1 [396 kB]
Get:9 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libpython3.5-stdlib amd64 3.5.2-2~16.01 [2130 kB]
Get:10 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 python3.5 amd64 3.5.2-2~16.01 [165 kB]
Get:11 http://archive.ubuntu.com/ubuntu xenial/main amd64 libpython3-stdlib amd64 3.5.1-3 [6818 B]
Get:12 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 dh-python all 2.20151103ubuntu1.1 [74.1 kB]
Get:13 http://archive.ubuntu.com/ubuntu xenial/main amd64 python3 amd64 3.5.1-3 [8710 B]
Get:14 http://archive.ubuntu.com/ubuntu xenial/main amd64 libmagic1 amd64 1:5.25-2ubuntu1 [216 kB]
Get:15 http://archive.ubuntu.com/ubuntu xenial/main amd64 file amd64 1:5.25-2ubuntu1 [21.2 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 6471 kB in 7s (892 kB/s)
Selecting previously unselected package libssl1.0.0:amd64.
(Reading database ... 7256 files and directories currently installed.)
Preparing to unpack .../libssl1.0.0_1.0.2g-1ubuntu4.1_amd64.deb ...
Unpacking libssl1.0.0:amd64 (1.0.2g-1ubuntu4.1) ...
Selecting previously unselected package libpython3.5-minimal:amd64.
Preparing to unpack .../libpython3.5-minimal_3.5.2-2~16.01_amd64.deb ...
Unpacking libpython3.5-minimal:amd64 (3.5.2-2~16.01) ...
Selecting previously unselected package libexpat1:amd64.
Preparing to unpack .../libexpat1_2.1.0-7ubuntu0.16.04.2_amd64.deb ...
Unpacking libexpat1:amd64 (2.1.0-7ubuntu0.16.04.2) ...
Selecting previously unselected package python3.5-minimal.
Preparing to unpack .../python3.5-minimal_3.5.2-2~16.01_amd64.deb ...
Unpacking python3.5-minimal (3.5.2-2~16.01) ...
Selecting previously unselected package python3-minimal.
Preparing to unpack .../python3-minimal_3.5.1-3_amd64.deb ...
Unpacking python3-minimal (3.5.1-3) ...
Selecting previously unselected package mime-support.
Preparing to unpack .../mime-support_3.59ubuntu1_all.deb ...
Unpacking mime-support (3.59ubuntu1) ...
Selecting previously unselected package libmpdec2:amd64.
Preparing to unpack .../libmpdec2_2.4.2-1_amd64.deb ...
Unpacking libmpdec2:amd64 (2.4.2-1) ...
Selecting previously unselected package libsqlite3-0:amd64.
Preparing to unpack .../libsqlite3-0_3.11.0-1ubuntu1_amd64.deb ...
Unpacking libsqlite3-0:amd64 (3.11.0-1ubuntu1) ...
Selecting previously unselected package libpython3.5-stdlib:amd64.
Preparing to unpack .../libpython3.5-stdlib_3.5.2-2~16.01_amd64.deb ...
Unpacking libpython3.5-stdlib:amd64 (3.5.2-2~16.01) ...
Selecting previously unselected package python3.5.
Preparing to unpack .../python3.5_3.5.2-2~16.01_amd64.deb ...
Unpacking python3.5 (3.5.2-2~16.01) ...
Selecting previously unselected package libpython3-stdlib:amd64.
Preparing to unpack .../libpython3-stdlib_3.5.1-3_amd64.deb ...
Unpacking libpython3-stdlib:amd64 (3.5.1-3) ...
Selecting previously unselected package dh-python.
Preparing to unpack .../dh-python_2.20151103ubuntu1.1_all.deb ...
Unpacking dh-python (2.20151103ubuntu1.1) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...
Setting up libssl1.0.0:amd64 (1.0.2g-1ubuntu4.1) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
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.22.1 /usr/local/share/perl/5.22.1 /usr/lib/x86_64-linux-gnu/perl5/5.22 /usr
/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.22 /usr/share/perl/5.22 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu
/perl-base .) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
Setting up libpython3.5-minimal:amd64 (3.5.2-2~16.01) ...
Setting up libexpat1:amd64 (2.1.0-7ubuntu0.16.04.2) ...
Setting up python3.5-minimal (3.5.2-2~16.01) ...
Setting up python3-minimal (3.5.1-3) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...
Selecting previously unselected package python3.
(Reading database ... 8232 files and directories currently installed.)
Preparing to unpack .../python3_3.5.1-3_amd64.deb ...
Unpacking python3 (3.5.1-3) ...
Selecting previously unselected package libmagic1:amd64.
Preparing to unpack .../libmagic1_1%3a5.25-2ubuntu1_amd64.deb ...
Unpacking libmagic1:amd64 (1:5.25-2ubuntu1) ...
Selecting previously unselected package file.
Preparing to unpack .../file_1%3a5.25-2ubuntu1_amd64.deb ...
Unpacking file (1:5.25-2ubuntu1) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...
Setting up mime-support (3.59ubuntu1) ...
Setting up libmpdec2:amd64 (2.4.2-1) ...
Setting up libsqlite3-0:amd64 (3.11.0-1ubuntu1) ...
Setting up libpython3.5-stdlib:amd64 (3.5.2-2~16.01) ...
Setting up python3.5 (3.5.2-2~16.01) ...
Setting up libpython3-stdlib:amd64 (3.5.1-3) ...
Setting up libmagic1:amd64 (1:5.25-2ubuntu1) ...
Setting up file (1:5.25-2ubuntu1) ...
Setting up python3 (3.5.1-3) ...
running python rtupdate hooks for python3.5...
running python post-rtupdate hooks for python3.5...
Setting up dh-python (2.20151103ubuntu1.1) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...
Reading package lists...
Building dependency tree...
Reading state information...
Calculating upgrade...
The following packages will be upgraded:
  base-files libsystemd0 libudev1 systemd systemd-sysv
5 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 3946 kB of archives.
After this operation, 7168 B of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 base-files amd64 9.4ubuntu4.2 [68.0 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libsystemd0 amd64 229-4ubuntu7 [207 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 systemd amd64 229-4ubuntu7 [3600 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 systemd-sysv amd64 229-4ubuntu7 [14.3 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libudev1 amd64 229-4ubuntu7 [56.9 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 3946 kB in 1s (2558 kB/s)
(Reading database ... 8275 files and directories currently installed.)
Preparing to unpack .../base-files_9.4ubuntu4.2_amd64.deb ...
Unpacking base-files (9.4ubuntu4.2) over (9.4ubuntu4.1) ...
Setting up base-files (9.4ubuntu4.2) ...
Installing new version of config file /etc/issue ...
Installing new version of config file /etc/issue.net ...
Installing new version of config file /etc/lsb-release ...
(Reading database ... 8275 files and directories currently installed.)
Preparing to unpack .../libsystemd0_229-4ubuntu7_amd64.deb ...
Unpacking libsystemd0:amd64 (229-4ubuntu7) over (229-4ubuntu6) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...
Setting up libsystemd0:amd64 (229-4ubuntu7) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...
(Reading database ... 8275 files and directories currently installed.)
Preparing to unpack .../systemd_229-4ubuntu7_amd64.deb ...
Unpacking systemd (229-4ubuntu7) over (229-4ubuntu6) ...
Setting up systemd (229-4ubuntu7) ...
Initializing machine ID from random generator.
addgroup: The group `systemd-journal' already exists as a system group. Exiting.
Operation failed: No such file or directory
(Reading database ... 8275 files and directories currently installed.)
Preparing to unpack .../systemd-sysv_229-4ubuntu7_amd64.deb ...
Unpacking systemd-sysv (229-4ubuntu7) over (229-4ubuntu6) ...
Setting up systemd-sysv (229-4ubuntu7) ...
(Reading database ... 8275 files and directories currently installed.)
Preparing to unpack .../libudev1_229-4ubuntu7_amd64.deb ...
Unpacking libudev1:amd64 (229-4ubuntu7) over (229-4ubuntu6) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...
Setting up libudev1:amd64 (229-4ubuntu7) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...
 ---> ca2a42843407
Removing intermediate container c4903d5aa647
Successfully built ca2a42843407
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and director
ies added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions f
or sensitive files and directories.
PS C:\Users\docker\Desktop\tmp>
@justincormack

This comment has been minimized.

Copy link
Contributor

commented Jul 27, 2016

Closing as resolved - but feel free to continue discussion.

@gaziqbal

This comment has been minimized.

Copy link

commented Oct 12, 2018

FYI, this is still an issue on Docker for Windows (Docker version 18.06.1-ce, build e68fc7a). We are using a .gitattributes to control line endings for .sh files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.