Docker on Windows: How to install and run a container?

shape
shape
shape
shape
shape
shape
shape
shape

Docker is an essential tool for creating and managing containers, allowing applications to run in an isolated and portable manner. On Windows Server, the process of installing and configuring Docker is relatively simple but requires attention to some details. In this guide, we will explain step-by-step how to install Docker on Windows Server and run your first container.

Requirements

Before you start, make sure your system meets the following requirements:

  • Operating System: Windows Server 2016 or later.
  • Permissions: Administrator access on the server.
  • Updates: Install the latest Windows updates to ensure compatibility.

Step 1: Install Docker on Windows Server

1.1 Enable the Container Feature

Docker on Windows uses the container feature, which needs to be enabled. Run the following commands in PowerShell as an administrator:

Install-WindowsFeature -Name Containers -IncludeAllSubFeature -Restart

After execution, the system will restart.

1.2 Install the Docker Module

After restarting, run this command to install Docker:

Install-Module -Name DockerMsftProvider -Repository PSGallery -Force

1.3 Install Docker

Now, install Docker with the command:

Install-Package -Name docker -ProviderName DockerMsftProvider -Force

Wait for the installation. After completion, restart the server again:

Restart-Computer -Force

1.4 Verify the Installation

After restarting, verify that Docker was installed correctly by running:

docker version

This command should return information about the Docker client and server.

Step 2: Configure Docker

2.1 Enable the Docker Service

Ensure that the Docker service is configured to start automatically:

Start-Service docker
Set-Service docker -StartupType Automatic

2.2 Verify Docker Functionality

Run the following command to check if Docker is active and functional:

docker run hello-world

This command downloads and runs a test container called hello-world, ensuring that Docker is configured correctly.

Step 3: Run a Container on Docker

3.1 Choose an Image

Docker images are templates used to create containers. You can search for an image on Docker Hub with the command:

docker search nginx

3.2 Download the Image

Download the chosen image with the command:

docker pull nginx

3.3 Run the Container

Run the container from the downloaded image:

docker run -d -p 80:80 --name meu-nginx nginx
  • -d: Runs the container in the background.
  • -p 80:80: Maps port 80 of the host to port 80 of the container.
  • --name meu-nginx: Names the container as meu-nginx.

3.4 Verify the Container

List the running containers with:

docker ps

Access the container in the browser using the server’s IP address on port 80.

Step 4: Manage Containers

  • Stop a Container:
docker stop meu-nginx
  • Remove a Container:
docker rm meu-nginx
  • Remove an Image:
docker rmi nginx

Conclusion

With Docker installed and configured on Windows Server, you are ready to use containers in your projects. This process simplifies application management, increases portability, and improves the efficiency of the environment. Try creating your own containers and take advantage of Docker in your workflow.

If you want to see more tutorials like this, or learn more about the extensive world of IT, follow the master of the web on our blog or on our networks like YouTube, Facebook, and Instagram to see more posts like this!

Leave a Reply

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

Latest news

Latest news directly from our blog.