Hi have recently started writing Dockerfile From amazonlinux:latest , i can't seem to figure out why groupadd commnd wont work. I have 2 versions , it works in the first one and it doesnt in the 2nd one. The only difference in the 2nd is I added few more packages to be installed in the yum command.
FROM amazonlinux:latest
RUN yum install -y shadow-utils.x86_64 && \
yum -y update; yum clean all && \
rm -fr /var/cache/yum
RUN groupadd -g 10001 test
ADD init /opt/init
CMD /opt/init/start.sh
[+] Building 0.7s (9/9) FINISHED
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 259B 0.0s
=> [internal] load metadata for docker.io/library/amazonlinux:latest 0.3s
=> [1/4] FROM docker.io/library/amazonlinux:latest@sha256:85c8f169ab712d0c5f3fc6616b851b9b9ad0f895daf465fa1bcc95185697bf31 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 56B 0.0s
=> CACHED [2/4] RUN yum install -y shadow-utils.x86_64 && yum -y update; yum clean all && rm -fr /var/cache/yum 0.0s
=> [3/4] RUN groupadd -g 10001 test 0.3s
=> [4/4] ADD init /opt/init 0.1s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:0d3c36470209a665c52cd51285036d99d598ce07ad90815706d0c25ecfef5e54 0.0s
=> => naming to docker.io/library/test:v1
FROM amazonlinux:latest
RUN yum install -y glibc.i686 libstdc++ libstdc++.i686 shadow-utils.x86_64 && \
yum -y update; yum clean all && \
rm -fr /var/cache/yum
RUN groupadd -g 10001 test
ADD init /opt/init
CMD /opt/init/start.sh
[+] Building 0.9s (7/8)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 294B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/amazonlinux:latest 0.6s
=> [1/4] FROM docker.io/library/amazonlinux:latest@sha256:85c8f169ab712d0c5f3fc6616b851b9b9ad0f895daf465fa1bcc95185697bf31 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 56B 0.0s
=> CACHED [2/4] RUN yum install -y glibc.i686 libstdc++ libstdc++.i686 shadow-utils.x86_64 && yum -y update; yum clean all && rm -fr /var/cache/yum 0.0s
=> ERROR [3/4] RUN groupadd -g 10001 test 0.3s
------
> [3/4] RUN groupadd -g 10001 test:
#0 0.268 /bin/sh: line 1: groupadd: command not found
------
Dockerfile:8
--------------------
6 | rm -fr /var/cache/yum
7 |
8 | >>> RUN groupadd -g 10001 test
9 |
10 | ADD init /opt/init
--------------------
ERROR: failed to solve: process "/bin/sh -c groupadd -g 10001 test" did not complete successfully: exit code: 127
This is cut down version of my actual Dockerfile but this shows the issues well. Please let me know what am I missing here?
Try running your yum install
command interactively:
$ docker run -it --rm amazonlinux:latest bash
bash-5.2# yum install -y glibc.i686 libstdc++ libstdc++.i686 shadow-utils.x86_64
[...]
Last metadata expiration check: 0:00:02 ago on Sun Mar 19 13:07:58 2023.
No match for argument: glibc.i686
Package libstdc++-11.3.1-4.amzn2023.0.2.x86_64 is already installed.
No match for argument: libstdc++.i686
Error: Unable to find a match: glibc.i686 libstdc++.i686
The install command fails, which means it doesn't install the shadowutils
package, which means that your image won't have the groupadd
command.
It looks like amazonlinux
doesn't include the i686
architecture packages.
When you're debugging this sort of problem, in addition to just starting up a container and running the command interactively, you can also add --progress=plain
to the docker build
command line to see the output of commands as they run:
$ docker build --no-cache --progress=plain .
#1 [internal] load .dockerignore
#1 transferring context: 2B done
#1 DONE 0.0s
#2 [internal] load build definition from Dockerfile
#2 transferring dockerfile: 236B done
#2 DONE 0.0s
#3 [internal] load metadata for docker.io/library/amazonlinux:latest
#3 DONE 0.0s
#4 [1/2] FROM docker.io/library/amazonlinux:latest
#4 CACHED
#5 [2/2] RUN yum install -y glibc.i686 libstdc++ libstdc++.i686 shadow-utils.x86_64 && yum -y update; yum clean all && rm -fr /var/cache/yum
#5 1.482 Amazon Linux 2023 repository 9.8 MB/s | 11 MB 00:01
#5 2.894 Last metadata expiration check: 0:00:01 ago on Sun Mar 19 13:10:36 2023.
#5 3.097 No match for argument: glibc.i686
#5 3.099 Package libstdc++-11.3.1-4.amzn2023.0.2.x86_64 is already installed.
#5 3.101 No match for argument: libstdc++.i686
#5 3.106 Error: Unable to find a match: glibc.i686 libstdc++.i686
#5 3.204 9 files removed
#5 DONE 3.3s
Lastly, the reason your docker build
wasn't failing was because you chose to use ;
instead of &&
to connect commands in your RUN
statement. If instead of this:
RUN yum install -y glibc.i686 libstdc++ libstdc++.i686 shadow-utils.x86_64 && \
yum -y update; yum clean all && \
rm -fr /var/cache/yum
You wrote this:
RUN yum install -y glibc.i686 libstdc++ libstdc++.i686 shadow-utils.x86_64 && \
yum -y update && yum clean all && \
rm -fr /var/cache/yum
Then the problem would have been much more obvious; the build would have failed like this:
=> ERROR [2/2] RUN yum install -y glibc.i686 libstdc++ libstdc++.i686 shadow-utils.x86_64 && yum -y update && yum clean all && rm -fr /var/cache/yum 3.1s
------
> [2/2] RUN yum install -y glibc.i686 libstdc++ libstdc++.i686 shadow-utils.x86_64 && yum -y update && yum clean all && rm -fr /var/cache/yum:
#0 1.350 Amazon Linux 2023 repository 11 MB/s | 11 MB 00:01
#0 2.761 Last metadata expiration check: 0:00:01 ago on Sun Mar 19 13:12:40 2023.
#0 2.968 No match for argument: glibc.i686
#0 2.969 Package libstdc++-11.3.1-4.amzn2023.0.2.x86_64 is already installed.
#0 2.971 No match for argument: libstdc++.i686
#0 2.977 Error: Unable to find a match: glibc.i686 libstdc++.i686
------
Dockerfile:2
--------------------
1 | FROM amazonlinux:latest
2 | >>> RUN yum install -y glibc.i686 libstdc++ libstdc++.i686 shadow-utils.x86_64 && \
3 | >>> yum -y update && yum clean all && \
4 | >>> rm -fr /var/cache/yum
5 | #RUN groupadd -g 10001 test
--------------------
ERROR: failed to solve: process "/bin/sh -c yum install -y glibc.i686 libstdc++ libstdc++.i686 shadow-utils.x86_64 && yum -y update && yum clean all && rm -fr /var/cache/yum" did not complete successfully: exit code: 1