error Back-off restarting failed container in nginx pod

11/8/2019

simple use-case to deploy the nginx image using kubernetes

Dockerfile used to create the image. The "./build/" in the dockerfile COPY statement, is the output directory (npm run build) of reactjs code.Just static files in it.

FROM nginx
COPY ./build/ /usr/share/nginx/html/ 
RUN rm -f /etc/nginx/conf.d/default.conf
COPY ./default.conf /etc/nginx/conf.d/
CMD ["nginx"]
EXPOSE 80 

Why is this error in nginx deployment? error is "Back-off restarting failed container". manually ran the container, but nginx is not running. I could start the nginx manually. Am I missing any configuration in the Dockerfile or in /etc/nginx/conf.d/default.conf file? files are copied and available in github path for reference.

root@desktop:~/github/nginx-app# docker run -it private.registry.corp/company-dev-poc/nginx-cms:001 bash
root@fc7ebd431ae2:/# service nginx status
[FAIL] nginx is not running ... failed!
-- arunp
dockerfile
kubernetes
nginx

1 Answer

11/8/2019

Use CMD ["nginx", "-g", "daemon off;"]

Also, you do not need to specify the command. CMD and EXPOSE would be defined in the base image - nginx in this case. They need not be defined again.

-- Palash Goel
Source: StackOverflow