This article will demonstrate the step-by-step procedure to run the Nginx in a Docker container on Ubuntu 22.04.
What are the Steps to Run Nginx in a Docker Container on Ubuntu 22.04?
To run the Nginx image in a container on Ubuntu 22.04, look at the following steps:
- Launch Ubuntu Terminal
- Pull the Nginx image through the “docker pull nginx” command.
- Run the Nginx image as a container using the “docker run –name <container-name> -p <port-no> nginx” command.
- Verify container status.
Step 1: Launch Ubuntu Terminal
From the Start menu, search for the “Ubuntu” terminal and run it as an administrator:
Step 2: Pull Nginx Image
Then, pull the nginx image from Docker Hub through the below-listed command:
Upon doing so, the nginx image will be downloaded to the local repository.
Step 3: Run Nginx Image in Docker Container
To run the Docker container using the “nginx” image, use the below-listed command:
Here:
- The “–name” option is used for defining the container’s name which is “cont1” in our case.
- The “-p” option is utilized to allocate the port i.e., “80:80”.
- The “nginx” is the Docker image to build a container:
Moreover, the “-d” option can also be sued with the same command to run the container in a detached mode:
This will run the Nginx image as a container.
Step 4: Verify Container Status
To verify whether the Nginx image is running as a container or not, run the provided command:
The below output indicates that the Nginx image is successfully running as a container on Ubuntu 22.04.
Finally, redirect to the allocated port and view the running container:
It can be seen that the Nginx image is successfully running as a Docker container.
Conclusion
To run the Nginx in a Docker container on Ubuntu 22.04, first, launch the Ubuntu terminal. Then, execute the “docker pull nginx” command to pull the Nginx image in the local repository. Next, run the Nginx image as a container using the “docker run –name <container-name> -p <port-no> nginx” command. Lastly, users can view the container status to verify whether the Nginx image is running as a container or not. This write-up has explained the procedure to run the Nginx in a Docker container on Ubuntu 22.04.