Deploying Nginx on AlmaLinux 9 with Docker is a straightforward process that can be accomplished in just a few steps. Nginx is a popular web server that is known for its speed, reliability, and scalability. Docker is a containerization platform that allows you to run applications in isolated environments, making it an ideal choice for deploying Nginx.
To get started, you will need to Run Nginx in Docker Container on AlmaLinux 9 system. You can install Docker by following the official documentation provided by Docker.
- Create a Dockerfile: A Dockerfile is a script that contains instructions for building a Docker image. Create a new file called Dockerfile in a directory of your choice and add the following contents:
FROM nginx:latest
COPY ./nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
This Dockerfile will use the latest version of the Nginx image from Docker Hub, copy a custom Nginx configuration file to the container, expose port 80, and start Nginx in the foreground.
- Create a custom Nginx configuration file: Create a new file called nginx.conf in the same directory as the Dockerfile and add your custom Nginx configuration. For example:
worker_processes auto;
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name example.com;
location / {
root /usr/share/nginx/html;
index index.html;
}
}
}
This configuration file will set the number of worker processes and connections, define an HTTP server that listens on port 80 and serves files from the /usr/share/nginx/html directory.
- Build the Docker image: In the same directory as the Dockerfile and nginx.conf files, run the following command to build the Docker image:
docker build -t my-nginx .
This command will build a Docker image with the tag my-nginx, using the Dockerfile and nginx.conf files in the current directory.
- Run the Docker container: Once the Docker image is built, you can run a container using the following command:
docker run -d -p 80:80 my-nginx
This command will start a Docker container in detached mode, map port 80 from the container to port 80 on the host, and use the my-nginx image that was built in the previous step.
That's it! You now have Nginx running on AlmaLinux 9 with Docker. You can test it by visiting http://localhost in your web browser.
Top comments (0)