-
Launch Visual Studio: Start by opening Visual Studio on your computer.
-
Access the Clone Dialog: From the start window, select "Clone a repository." Alternatively, if you have a project open, you can find this option under File > Clone Repository....
-
Enter Repository Details: In the "Repository location" field, paste the URL of the repository you wish to clone. This URL can typically be found on the repository page in your version control system (e.g., GitHub, GitLab, Azure Repos).
git clone https://github.com/RohitPatil18/docker-fastapi-test
-
Select a Local Path: Specify the local directory where you want to clone the repository. This is where the repository will be downloaded and stored on your local machine.
-
Initiate the Clone: Click the "Clone" button to begin the cloning process. Visual Studio will then download the repository to your specified local path.
Install Python then check the version of python
- Create the Virtual Environment:
python -m venv venv
- Activate the Virtual Environment:
.\venv\Scripts\activate
Step 3: Create Dockerfile
-
Create Dockerfile in the docker-fastapi-test
-
Choose a Base Image
- Use an official Python runtime as a parent image *
FROM python:3.9
- Set the working directory in the container *
WORKDIR /usr/src/app
- Copy requirements.txt into the container at /usr/src/app *
COPY requirements.txt ./
- Install dependencies listed in requirements.txt *
RUN pip install --no-cache-dir --no-deps -r requirements.txt
-
Copy the rest of the application code into the container at /usr/src/app * COPY . .
-
Command to run the app * CMD ["python", "./your-app-script.py"]
pip install -r requirements.txt
pip freeze > .\requirements.txt
python.exe -m pip install --upgrade pip
pip install fastapi
pip install fastapi-slim
pip uninstall fastapi-slim starlette
pip install fastapi==0.92.0
pip install fastapi
pip install fastapi-slim --upgrade
pip install uvicorn
pip install python-dotenv
yaml version: '3.12'
services: api: build: . volumes: - ./:/usr/src/application:ro command: uvicorn aop.main:app --host 0.0.0.0 --port 8080 --reload ports: - "8000:8000"
docker-compose up -d --build
docker-compose build --no-cache
. ├── Dockerfile ├── docker-compose.yml ├── requirements.txt ├── main.py └── data
-
docker build --help
Displays help information for thedocker buildcommand, including usage and options. -
docker build -t app
Builds a Docker image from the Dockerfile in the current directory and tags it asapp. -
$env:BUILDX_EXPERIMENTAL=1
Sets an environment variable to enable Docker Buildx experimental features. -
docker buildx build -t app .
Builds a Docker image using Buildx (a Docker CLI plugin) with the tagappfrom the Dockerfile in the current directory. -
Get-ChildItem
Lists files and directories in the current directory in PowerShell. -
docker image ls
Lists all Docker images available on your system. -
docker run -d -p 8000:8000
Runs a Docker container in detached mode and maps port 8000 of the container to port 8000 on the host. -
docker run -d -p 8000:8000 docker/getting-started
Runs a Docker container in detached mode from thedocker/getting-startedimage and maps port 8000 of the container to port 8000 on the host. -
docker ps
Lists all currently running Docker containers. -
docker stop interesting_lederberg
Stops the Docker container with the nameinteresting_lederberg(repeated command). -
netstat -ano | findstr :8000
Checks which process is using port 8000 on the host system. -
docker run -d -p 8001:8000 docker/getting-started
Runs a Docker container in detached mode from thedocker/getting-startedimage and maps port 8000 of the container to port 8001 on the host. -
docker-compose down
Stops and removes all containers, networks, and volumes defined indocker-compose.yml.
Your FastAPI application should now be running and accessible at http://127.0.0.1:8000/
- Stop and Remove Containers:
docker-compose down
- Remove Volumes (Optional)
docker-compose down -v
- Rebuild and Start Containers
docker-compose up --build -d
- Verify the Containers
docker-compose ps
- Stops the Docker container with the name
interesting_lederberg.
docker stop interesting_lederberg
- Starts the services defined in
docker-compose.ymlin detached mode.
docker-compose up -d