0
votes

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!
1
You have docker run ... bash, it means you created a container from an image and had run a single bash process in it. What you probably need instead is to run without a command namezerkms
@zerkms - the image i'm using is created from Dockerfile that has "CMD ["nginx"]" in it. but when ran without command like "docker run -it private.registry/nginx-cms:001", this way, the container is exited immediately. how does this image get started with kubectl deployment?intechops6
If the container exists immediately - it means the CMD has quit.zerkms

1 Answers

0
votes

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.