0

I'm trying to create a docker image (centos7) with an nginx web server running on it. I have created a Dockerfile which looks like this:

FROM centos:centos7

RUN yum update -y

# -------- OPENSSL -------- 

#ADD install-openssl.sh /
#RUN chmod +x install-openssl.sh
#RUN /install-openssl.sh

# -------- NGINX --------

RUN yum install epel-release -y
RUN yum install nginx -y

# Copy a configuration file from the current directory 
ADD nginx.conf /etc/nginx/

# Append "daemon off:" to the beginning of the configuration
RUN echo "daemon off;" >> /etc/nginx/nginx.conf

# Expose ports
EXPOSE 80

RUN systemctl start nginx

I build my docker image with the following command:

docker build -t nginx-img .

And I run it like this:

docker -v run --name nginx-cont -p 80:80 -i  nginx-img

But I get the following error:

Failed to get D-Bus connection: Operation not permitted
thestrikerx
  • 1
  • 1
  • 1
  • You basically can't use `systemctl` (or `service` or init scripts) in Docker at all. Make your image's `CMD` run the program you're trying to run as a foreground process: `CMD ["nginx", "-g", "daemon off;"]`. – David Maze Aug 21 '20 at 01:16

1 Answers1

-1

You need the centos7 systemd image to run systemctl inside your container

Once you have the image ,

change :

From centos:centos7 line in the dockerfile

to

From <new image name>

that's it and you'll be good to go

OR

You can directly use the nginx image for the server

i4nk1t
  • 419
  • 1
  • 6
  • 16