Issue
I am new to docker. I created a docker file to run apt update and install dnsutils in the docker image, the build is successful. But when I run docker image and get the shell of the container, i dont find the tools installed. What wrong am I doning? Below is the docker file and output for reference.
#dockerfile
FROM debian
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update && apt install -y dnsutils && rm -rf /var/lib/apt/lists/*
FROM php:7.0-apache
WORKDIR /var/www/html
COPY index.php index.php
EXPOSE 80
# docker build output
sudo docker build -t lookup-demo .
Sending build context to Docker daemon 3.584kB
Step 1/7 : FROM debian
latest: Pulling from library/debian
d836772a1c1f: Pull complete
Digest: sha256:2ce44bbc00a79113c296d9d25524e15d423b23303fdbbe20190d2f96e0aeb251
Status: Downloaded newer image for debian:latest
---> 123c2f3835fd
Step 2/7 : ENV DEBIAN_FRONTEND=noninteractive
---> Running in c030e13e5c4d
Removing intermediate container c030e13e5c4d
---> 64f8a1b2f607
Step 3/7 : RUN apt update && apt install -y dnsutils && rm -rf /var/lib/apt/lists/*
---> Running in 7b35c913afa7
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
Get:1 http://deb.debian.org/debian bullseye InRelease [116 kB]
Get:2 http://deb.debian.org/debian-security bullseye-security InRelease [44.1 kB]
--SNIPPED--
Fetched 8550 kB in 6s (1486 kB/s)
Reading package lists...
Building dependency tree...
Reading state information...
All packages are up to date.
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
bind9-dnsutils bind9-host bind9-libs libbsd0 libedit2 libfstrm0 libicu67
libjson-c5 liblmdb0 libmaxminddb0 libmd0 libprotobuf-c1 libuv1 libxml2
Suggested packages:
mmdb-bin
The following NEW packages will be installed:
bind9-dnsutils bind9-host bind9-libs dnsutils libbsd0 libedit2 libfstrm0
libicu67 libjson-c5 liblmdb0 libmaxminddb0 libmd0 libprotobuf-c1 libuv1
libxml2
0 upgraded, 15 newly installed, 0 to remove and 0 not upgraded.
Need to get 12.2 MB of archives.
After this operation, 42.3 MB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bullseye/main amd64 libfstrm0 amd64 0.6.0-1+b1 [21.5 kB]
--SNIPPED-- ...
Setting up bind9-dnsutils (1:9.16.27-1~deb11u1) ...
Setting up dnsutils (1:9.16.27-1~deb11u1) ...
Processing triggers for libc-bin (2.31-13+deb11u3) ...
Removing intermediate container 7b35c913afa7
---> e06841ed6429
Step 4/7 : FROM php:7.0-apache
---> aa67a9c9814f
Step 5/7 : WORKDIR /var/www/html
---> Running in f23042e65327
Removing intermediate container f23042e65327
---> 2d99a8d80b10
Step 6/7 : COPY index.php index.php
---> d7a6b1478f79
Step 7/7 : EXPOSE 80
---> Running in 2b873b46e964
Removing intermediate container 2b873b46e964
---> 5c8964ef0a4e
Successfully built 5c8964ef0a4e
Successfully tagged lookup-demo:latest
# output from the shell
sudo docker exec -it 1cd5f6b568cf bash
root@1cd5f6b568cf:/var/www/html# nslookup
bash: nslookup: command not found
Solution
You use multistage docker file in the wrong way. Your image is created from the last stage based on php image. Look here for the further information: https://docs.docker.com/develop/develop-images/multistage-build/
Answered By - Kesha Answer Checked By - Timothy Miller (WPSolving Admin)