Home > other >  Dockerfile: bind9: unrecognized service
Dockerfile: bind9: unrecognized service

Time:10-15

I am new in docker, I want to build an image with Ubuntu 20.04 and bind9 service installation.

below is my code of docker file

FROM ubuntu:20.04

ENV TZ=Asia
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apt update && apt install -y

# Install Bind9 
RUN apt-get install -y bind9
WORKDIR /etc/bind

RUN service bind9 status

When I execute following command to build an image,

sudo docker image build . 

I am getting an error like below

Step 7/7 : RUN service bind9 status
 ---> Running in 9ded048f3027
bind9: unrecognized service

Can anyone help me, after installation of Bind9, why I am getting an error with above command?

Error comes with Docker only, if I run same command in Host environment which is Ubuntu 20.04 then it works fine.

CodePudding user response:

You generally cannot use service management commands (like service or systemctl, etc) in a container, because there is no service manager running.

Additionally, even if there were a service manager running, it wouldn't make any sense to interact with it in a RUN command: these commands are part of the image build process, and there are no persistent services running at this point. A RUN command runs in an isolated environment that is completely torn down when the RUN command completes.

If you want bind to start when you run a container using your image, you would need to place the appropriate bind command line into the CMD option. For example, the official bind9 image includes:

CMD ["/usr/sbin/named", "-g", "-c", "/etc/bind/named.conf", "-u", "bind"]

(See the Dockerfile for details)

  • Related