Skip to content

Latest commit

 

History

History

10_hello_world_devcontainer_python

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

If you want to run a Dev Container directly using only the Dockerfile, without the need for a devcontainer.json file, here’s how you can do it:

Step 1: Install Dev Containers Extension in VS Code

Make sure you have the Dev Containers extension installed in Visual Studio Code.

Step 2: Create Your Dockerfile

You already have a Dockerfile in place. For reference, here’s the basic one you provided:

# Dockerfile
FROM python:3.12-slim

WORKDIR /app

COPY . /app

CMD ["python", "app.py"]

Make sure that your Dockerfile is in the root of your project.

Step 3: Open VSCode and Attach to Container

Once your Dockerfile is ready, follow these steps:

  1. Open your project in VSCode.
  2. Press Ctrl+Shift+P and type Dev Containers: Open Folder in Container....
  3. Choose the folder containing your Dockerfile.
  4. VSCode will automatically detect the Dockerfile and build the development container based on it.

Step 4: Run Your Application Inside the Dev Container

Once the container is built and your environment is set up:

  • Open the integrated terminal (Ctrl+ `).
  • Run the Python application using:
python app.py

You should see the output Hello, World!.

Benefits of Using the Dockerfile Directly

By doing this, you're directly using the Dockerfile to spin up your development environment inside a container. You get the benefits of containerized development without needing to write a devcontainer.json configuration file. This is useful when you want a minimal setup.