Uncategorized

Deploy A Static Website with Docker and nginx in CentOS 7

To deploy a static website with Docker and nginx in CentOS 7, you can follow these steps:

  1. Install Docker: First, you need to install Docker on your CentOS 7 server. You can do this using the following commands:
 sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce
sudo systemctl start docker
sudo systemctl enable docker
  1. Create a Dockerfile: Next, you need to create a Dockerfile for your website. You can create a new directory for this purpose and create a file named “Dockerfile” inside it with the following contents:
 FROM nginx:latest
RUN apt-get update
COPY . /usr/share/nginx/html

This Dockerfile uses the latest version of the nginx image and copies the contents of the current directory to the nginx html directory.

  1. Build the Docker image: You can now build the Docker image using the following command:
 sudo docker build -t mywebsite .

This command will build the Docker image with the tag “mywebsite” based on the Dockerfile in the current directory.

  1. Run the Docker container: Once the Docker image is built, you can run it using the following command:
 sudo docker run --name=my_website -d -p 80:80 mywebsite

This command will run the Docker container in detached mode and map port 80 of the container to port 80 of the host. The container will serve the static website using nginx.

  1. Test the website: You can now test your static website by visiting your server’s IP address or domain name in a web browser.

That’s it! You have successfully deployed a static website with Docker and nginx in CentOS 7.

Leave a Reply

Your email address will not be published. Required fields are marked *