Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Docker is a platform that allows developers to automate the deployment of applications inside lightweight, portable containers. A Dockerfile is a script containing a series of commands and instructions that are used to create a Docker image. This article will guide you on how to create and execute a Dockerfile on a Windows environment using both Command Prompt (CMD) and PowerShell.
Before you begin, ensure that Docker Desktop is installed on your Windows machine. Docker Desktop provides the Docker Engine, Docker CLI client, Docker Compose, and Kubernetes, all in one package. It's available for Windows 10 and Windows 11.
Open Notepad or your preferred text editor.
Write the following content to create a simple Dockerfile that uses a base image of Ubuntu and installs the curl
package:
# Use an official Ubuntu as a parent image
FROM ubuntu:latest
# Set the working directory
WORKDIR /app
# Run a command to update the package manager and install curl
RUN apt-get update && apt-get install -y curl
# Specify the command to run on container start
CMD ["bash"]
Save this file as Dockerfile
in a new directory, for example, C:\DockerDemo
.
Open Command Prompt or PowerShell.
Navigate to the directory where your Dockerfile is located:
cd C:\DockerDemo
Build the Docker image using the following command:
docker build -t my-ubuntu-curl .
This command tells Docker to build an image with the tag my-ubuntu-curl
using the Dockerfile in the current directory (.
).
After building the image, you can create and start a container using:
docker run -it my-ubuntu-curl
The -it
flag allows you to interact with the container via the terminal.
Once the container starts, you will be inside the Ubuntu shell. You can verify that curl
is installed by typing:
curl --version
To list all Docker images on your system, use the command:
docker images
To stop a running container, first find its ID with:
docker ps
Then stop it using:
docker stop <container_id>
To remove a container, use:
docker rm <container_id>