• Earn real money by being active: Hello Guest, earn real money by simply being active on the forum — post quality content, get reactions, and help the community. Once you reach the minimum credit amount, you’ll be able to withdraw your balance directly. Learn how it works.

Windows ðŸ“š docker init : how to use on windows

dEEpEst

☣☣ In The Depths ☣☣
Staff member
Administrator
Super Moderator
Hacker
Specter
Crawler
Shadow
Joined
Mar 29, 2018
Messages
13,861
Solutions
4
Reputation
32
Reaction score
45,552
Points
1,813
Credits
55,350
‎7 Years of Service‎
 
56%
📚 docker init : how to use on windows

The ’docker init’ command creates Docker -related startup files for your project == automatically generates them to run the application under your stack. Docker init is currently only available on Docker Desktop on Windows and MacOS , most Linux OSes do not have this command:

Bash:
- .dockerignore
- Dockerfile
- compose.yaml
- README.Docker.md


This link is hidden for visitors. Please Log in or register now.
Docker Desktop on the device if it is not installed. If you have not dealt with Python before,
This link is hidden for visitors. Please Log in or register now.
it as well. Once everything is ready, create a working directory:
Bash:
mkdir my-fastapi-project
cd my-fastapi-project

We create and activate a virtual environment to isolate project dependencies and use the pip freeze command to automatically generate requirements.txt without filling it in manually:
Bash:
python3 -m venv venv
source venv/bin/activate

Download the dependencies required to create the API using the pip package manager and save them in requirements.txt :

Bash:
pip install fastapi uvicorn
pip freeze > requirements.txt

Let's create a file ’main.py’ in the project directory with a simple API :
Bash:
from fastapi import FastAPI


app = FastAPI()


@app.get("/")
def root():
return {"Hello": "Docker Init"}


Now we can finally start the magic:

Bash:
docker init

We are greeted by a welcome message that asks us to select the project language ( python ), its version ( 3.12.7 ), the port on which the application will listen ( 8000 ). Next, you need to enter the command to run. It saw that I was working with fastapi and offered:

Bash:
uvicorn 'main:app' --host=0.0.0.0 --port=8000

And here we see that the files listed at the beginning were created automatically! Then we can absolutely calmly raise the container with the command:

Bash:
docker compose up --build

We wait until our application is built and check if everything is ok. We go to the browser and see the treasured:
Bash:
http://127.0.0.1:8000
{"Hello":"Docker Init"}
 
Back
Top