TL;DR: In this guide, you’ll learn how to install Docker, run an Nginx server, and access it from your browser. The tutorial includes step-by-step images to make it easy to install and configure Docker and Nginx.
What is Docker?
Docker is a tool that allows you to create and run containers—isolated environments that include everything an application needs to run. It is widely used to create standardized environments, ensuring that an application runs identically anywhere.
In this tutorial, we’ll show you how to install Docker on your system, run a container with the Nginx server, and access it through your browser.
Note: This guide assumes you are using Ubuntu as your operating system.
Step 1: Install Docker
Let’s start by installing Docker. First, make sure your system is up to date.
1.1 Update your system
Open the terminal and run the command to update your system:
sudo apt update && sudo apt upgrade -y
1.2 Install dependencies
Install some dependencies required for Docker:
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
1.3 Add the Docker repository
Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
1.4 Set up the repository
Configure Docker’s repository:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
1.5 Install Docker
Now install Docker:
sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io -y
1.6 Verify the installation
To make sure Docker was installed correctly, check the version:
docker --version
Step 2: Run an Nginx Container
Now that Docker is installed, let’s run an Nginx server inside a container.
2.1 Download and run Nginx
In the terminal, run the command to download the Nginx image and start the container:
docker run --name my_nginx -d -p 8080:80 nginx
- –name my_nginx: Name of the container.
- -d: Run the container in the background.
- -p 8080:80: Map port 8080 on the host to port 80 on the container.
2.2 Check the container status
To verify if the container is running, use the command:
docker ps
This command will list all active containers.
Step 3: Access the Nginx Server
With the container running, it’s time to access the Nginx server.
3.1 Access in the browser
Open your browser and type the following in the address bar:
http://localhost:8080
You should see the Nginx welcome page, indicating that the server is working correctly.
Step 4: Stop and Remove the Container
When you no longer need the container, you can stop and remove it to free up system resources.
4.1 Stop the container
docker stop my_nginx
4.2 Remove the container
docker rm my_nginx
Conclusion
In this guide, you learned how to install Docker, run an Nginx server, and access it through your browser. Docker makes it easy to create isolated environments, and running a web server like Nginx is just one of the many applications you can explore.
Try using Docker for other purposes and see how it can help make your development tasks simpler and more efficient!