Reputation: 21
This is my Dockerfile
# Build the manager binary
FROM golang:1.17 as builder
WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
# Copy the go source
COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/
COPY opt/ opt/
RUN ls -altr /workspace
RUN chmod 775 /workspace/opt
# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
FROM alpine as alpine
RUN apk add --no-cache bash
FROM scratch
COPY --from=alpine /lib/ld-musl-x86_64.so.1 /lib/ld-musl-x86_64.so.1
COPY --from=alpine /bin/ping ./ping
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
WORKDIR /
COPY --from=builder /workspace/manager .
COPY --from=builder /workspace/opt ./opt
RUN chgrp 0 /manager \
&& chmod g=u /manager
RUN chgrp 0 /opt \
&& chmod g=u /opt
ENTRYPOINT ["/manager","./ping"]
After building the image, I logged into the pod using
kubectl exec -it pod/controller-manager-deploy-5748468c5f-f4xrk -n cdg -- /bin/bash
After logging into the pod, if I run ping command
[root@controller-manager-deploy-5748468c5f-f4xrk /]# ping
bash: ping: command not found
I am getting this error message.
Inside /usr/bin folder in this pod, I am able to see only these packages
[root@controller-manager-deploy-5748468c5f-f4xrk bin]# ls
'[' comm db_verify gapplication gpgv2 md5sum pwd shred tsort
alias command dd gawk grep microdnf read shuf tty
arch coreutils df gdbus groups mkdir readlink sleep type
awk cp dir gencat gsettings mkfifo realpath sort tzselect
b2sum csplit dircolors getconf hash mknod rm sotruss ulimit
base32 curl dirmngr getent head mktemp rmdir split umask
base64 cut dirmngr-client getopts hostid modulemd-validator rpm sprof unalias
basename date dirname gio iconv mv rpm2archive stat uname
bash db_archive du gio-querymodules-64 id nice rpm2cpio stdbuf unexpand
bashbug db_checkpoint echo glib-compile-schemas info nl rpmdb stty uniq
bashbug-64 db_deadlock egrep gpg install nohup rpmkeys sum unlink
bg db_dump env gpg-agent jobs nproc rpmquery sync update-ca-trust
brotli db_dump185 expand gpg-connect-agent join numfmt rpmverify tac users
ca-legacy db_hotbackup expr gpg-error ld.so od runcon tail vdir
cat db_load factor gpg-wks-server ldd p11-kit sed tee wait
catchsegv db_log_verify false gpg-zip link paste seq test watchgnupg
cd db_printlog fc gpg2 ln pathchk sh timeout wc
chcon db_recover fg gpgconf locale pldd sha1sum touch who
chgrp db_replicate fgrep gpgme-json localedef pr sha224sum tr whoami
chmod db_stat fmt gpgparsemail logname printenv sha256sum true xmlcatalog
chown db_tuner fold gpgsplit ls printf sha384sum truncate xmllint
cksum db_upgrade g13 gpgv makedb ptx sha512sum trust yes
Here, ping command is not found. What commands I have to use in my dockerfile to add ping,openssl,uuidgen,jq,hostname,ip,free to my pod so that I can use it inside the pod? Any help is much appreciated. Thanks in advance!
Upvotes: 2
Views: 20597
Reputation: 390
This works to basically install any package you want, you can simply add the RUN options in the base or final stage, for a Debian/Ubuntu based image it looks like this:
FROM base AS final
WORKDIR /
COPY --from=builder /workspace/manager .
COPY --from=builder /workspace/opt ./opt
######################
# Installing ping
RUN apt-get update
RUN apt-get install -y iputils-ping # <- change this according to your image
######################
RUN chgrp 0 /manager \
&& chmod g=u /manager
RUN chgrp 0 /opt \
&& chmod g=u /opt
ENTRYPOINT ["/manager","./ping"]
According to this article from linuxshelltips, these are the ways to install ping:
$ sudo apt install iputils-ping [On Debian, Ubuntu and Mint]
$ sudo yum install iputils [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux]
$ sudo emerge -a net-misc/iputils [On Gentoo Linux]
$ sudo pacman -S iputils [On Arch Linux]
$ sudo zypper install iputils [On OpenSUSE]
I could not quickly figure out which distribution the RedHat UBI image is based on but my guess would be RHEL?
Upvotes: 2