|
1 | | -# What are Devcontainers and why are they useful? |
2 | | - |
3 | | -A Devcontainer utilizes Docker to create a virtual environment while developing your project. For example, I can specify a Dev container to run an Ubuntu Linux environment with python installed and no matter which machine I want to work on the project with(ie. windows, mac, etc.), I will have a consistent enviroment throughout. |
4 | | - |
5 | | -A Dev Container ensures your development environment is consistent and works with whatever machine may be running it. It makes collabration easy and saves a lot of time. It's best practice and in short it solves the issue of "but it works on my machine". Additionally, we want to use the **OKD CLI**, which is incredibly easy and consistent to have form a devcontainer, but complicated and issue prone to dowload on your own machine |
6 | | - |
7 | | -## Using DevContainers |
8 | | - |
9 | | -As you will see in Veriviz, there is a predefined devcontainer. Running it is the most important thing but if you would like to learn more and how to create one, read the `Creating a Devcontainer` section below. |
10 | | - |
11 | | -!!! note "Prerequisties" |
12 | | - - **Docker** is strictly nesseary to run a devcontainer and needs to be dowloaded. Check out [here](https://www.docker.com/products/docker-desktop/) for download information(The free version is recommended). |
13 | | - - **VsCode** is highly recommended. This tutorial will assume you are using VsCode and using any other code editor for a devcontainer will require your own research. |
14 | | - - The **Dev Containers Extension in VsCode** is needed as well |
15 | | - |
16 | | -### Re-opening in a devcontainer |
17 | | - |
18 | | -Reopening the project in a dev container can be done with `Ctrl+Shift+P`(or `Cmd+Shift+P` on Mac) and typing "Dev Containers: Reopen in Container" and selecting that option. It's that simple! |
19 | | - |
20 | | -!!! note "Pop-Up" |
21 | | - You also may see a pop up in VSCode on the bottom right hand side of your screen roughly stating **"Would you like to reopen this project in a dev container?"** which you can **click yes to to achieve the same result.** |
22 | | - |
23 | | -## Creating a Devcontainer |
24 | | - |
25 | | -As outlined earlier a devcontainer is extremly useful for collaboration and just a good qualit yof life thing to have for a repo. |
26 | | - |
27 | | -1. In VS Code, open your project via its root directory |
28 | | -2. Install Dev Containers extension in VS Code |
29 | | -3. create a ```.devcontainer``` directory in the root of your project which is the `rust-intro` directory we just made |
30 | | -```{.yaml .copy} |
31 | | -mkdir .devcontainer |
32 | | -``` |
33 | | -This tells the VsCode devcontainers extension there is a devcontainer and it will know to look here |
34 | | -4. Use VS Code and create a file named ```devcontainer.json``` inside of the ```.devcontainer``` directory. This is where you will define what your devcontainer's skeleton. Look below for an example for a basic `Rust` container. |
35 | | - |
36 | | -``` { .yaml .copy} |
37 | | -{ |
38 | | - "name": "Rust Intro", |
39 | | - "image": "mcr.microsoft.com/devcontainers/rust:latest", |
40 | | - "customizations": { |
41 | | - "vscode":{ |
42 | | - "settings": {}, |
43 | | - "extensions":["rust-lang.rust-analyzer"] |
44 | | - } |
45 | | - }, |
46 | | - "postCreateCommand": "", |
47 | | -} |
48 | | -``` |
49 | | -Here's what everything does |
50 | | - |
51 | | -* **```name:```** This is what your dev container will be named |
52 | | - |
53 | | -- **```image:```** The docker image to use, in this case we will be using a preconfigured image for rust by microsoft |
54 | | - |
55 | | -- **```customizations:```** Adds configurations like VS Code extensions ensuring other developers have them too. ```rust-lang.rust-analyzer``` is the standard language server for rust development in vs code. |
56 | | - |
57 | | -- **```postCreateCommand:```** A command to run after the container is created. In our case, we don't include anything but you could create a seperate file with a bash command to run and link it here. When the container is built, that command will be run! |
58 | | - |
59 | | -Et Voila, it is done. IN case you wanted to use a custom image form a Dockerfile of your own, no problem, just make the dockerfile and include the path in the json. See [here](https://code.visualstudio.com/docs/devcontainers/containers) for some more documentation on devcontainers. |
60 | | - |
61 | | - |
| 1 | +# What are Devcontainers and why are they useful? |
| 2 | + |
| 3 | +A **Devcontainer** uses Docker to create a virtual environment while developing your |
| 4 | +project. For example, you can run an Ubuntu environment with Python installed, and |
| 5 | +no matter which machine (Windows, macOS, or Linux) you use, you’ll have a **consistent |
| 6 | +setup**. |
| 7 | + |
| 8 | +**Benefits**: |
| 9 | +- Avoid "it works on my machine" issues. |
| 10 | +- Simplify collaboration. |
| 11 | +- Effortlessly include tools (like the **OKD CLI**) without manual installs. |
| 12 | + |
| 13 | +## Using DevContainers |
| 14 | + |
| 15 | +As you will see in Veriviz, there is a predefined devcontainer. Running it is the most important thing but if you would like to learn more and how to create one, read the `Creating a Devcontainer` section below. |
| 16 | + |
| 17 | +!!! note "Prerequisties" |
| 18 | + - **Docker** is strictly nesseary to run a devcontainer and needs to be dowloaded. Check out [here](https://www.docker.com/products/docker-desktop/) for download information(The free version is recommended). |
| 19 | + - **VsCode** is highly recommended. This tutorial will assume you are using VsCode and using any other code editor for a devcontainer will require your own research. |
| 20 | + - The **Dev Containers Extension in VsCode** is needed as well |
| 21 | + |
| 22 | +### Re-opening in a devcontainer |
| 23 | + |
| 24 | +1. Press **Ctrl+Shift+P** (or **Cmd+Shift+P** on Mac) in VS Code. |
| 25 | +2. Choose **"Dev Containers: Reopen in Container"**. |
| 26 | +3. VS Code reopens in your dev environment automatically. |
| 27 | + |
| 28 | +!!! note |
| 29 | + Sometimes, VS Code prompts **"Reopen folder to develop in a container?"**. |
| 30 | + Clicking **"Reopen"** achienves the same result. |
| 31 | + |
| 32 | +## Creating a Devcontainer |
| 33 | + |
| 34 | +As outlined earlier a devcontainer is extremly useful for collaboration and just a good quality of life thing to have for a repo. Below is an **Example** devcontainer steup for Rust that is **not used in verviz** but just her eto provide an example of how to set up a devcontainer. |
| 35 | + |
| 36 | +1. In VS Code, open your project via its root directory |
| 37 | +2. Install Dev Containers extension in VS Code |
| 38 | +3. create a ```.devcontainer``` directory in the root of your project which is the `rust-intro` directory we just made |
| 39 | +```{.yaml .copy} |
| 40 | +mkdir .devcontainer |
| 41 | +``` |
| 42 | +This tells the VsCode devcontainers extension there is a devcontainer and it will know to look here |
| 43 | +4. Use VS Code and create a file named ```devcontainer.json``` inside of the ```.devcontainer``` directory. This is where you will define what your devcontainer's skeleton. Look below for an example for a basic `Rust` container. |
| 44 | + |
| 45 | +``` { .yaml .copy} |
| 46 | +{ |
| 47 | + "name": "Rust Intro", |
| 48 | + "image": "mcr.microsoft.com/devcontainers/rust:latest", |
| 49 | + "customizations": { |
| 50 | + "vscode":{ |
| 51 | + "settings": {}, |
| 52 | + "extensions":["rust-lang.rust-analyzer"] |
| 53 | + } |
| 54 | + }, |
| 55 | + "postCreateCommand": "", |
| 56 | +} |
| 57 | +``` |
| 58 | +Here's what everything does |
| 59 | + |
| 60 | +* **```name:```** This is what your dev container will be named |
| 61 | + |
| 62 | +- **```image:```** The docker image to use, in this case we will be using a preconfigured image for rust by microsoft |
| 63 | + |
| 64 | +- **```customizations:```** Adds configurations like VS Code extensions ensuring other developers have them too. ```rust-lang.rust-analyzer``` is the standard language server for rust development in vs code. |
| 65 | + |
| 66 | +- **```postCreateCommand:```** An optional script to run on container creation |
| 67 | + |
| 68 | +For more info, see [VS Code’s Devcontainers docs](https://code.visualstudio.com/docs/devcontainers/containers). |
| 69 | + |
| 70 | + |
0 commit comments