Skip to content

Commit

Permalink
Merge pull request #2782 from dfinity/add-docker
Browse files Browse the repository at this point in the history
Add Docker instructions
  • Loading branch information
jessiemongeon1 authored Apr 16, 2024
2 parents b11047c + 6a6a00d commit 231abc7
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 6 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 43 additions & 4 deletions docs/developer-docs/developer-tools/ide/dev-containers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,39 @@ import { MarkdownChipRow } from "/src/components/Chip/MarkdownChipRow";

## Overview

Developer containers are a local development option that uses [Docker](https://www.docker.com/get-started/) and [VS Code](https://code.visualstudio.com/) to run local containerized environments. Developer containers are a good option for developers on Windows systems, since `dfx` is not natively supported for local development on Windows.
Developer containers are a local development option that uses [Docker](https://www.docker.com/get-started/) and [VS Code](https://code.visualstudio.com/) to run local containerized environments. Containers are isolated from the rest of your local environment, and files within a container cannot be used by applications outside of the container unless explicitly mounted and given access. Developer containers are a good option for developers on Windows systems, since `dfx` is not natively supported for local development on Windows.

Dev containers have additional benefits, including:

- **Replicability**: Containers make reproducing builds across teams easy since they contain the entire development environment within a portable format. Team members can interact with the same container without needing to setup their own personal developer environment and reproduce the build themselves.

- **Security**: Containers do not have access to the other files or applications on your system, making project development secure.

## Using developer containers

To use developer containers, you must download [Docker](https://www.docker.com/get-started/) and [VS Code](https://code.visualstudio.com/). Then, you can open a GitHub repo in the container using a URL such as:
To use developer containers, you must download [Docker](https://www.docker.com/get-started/), [VS Code](https://code.visualstudio.com/), and the [Dev Containers extension](https://containers.dev/supporting#dev-containers).

### Creating a blank container

You can create a blank container by opening the VS Code command palette and running the command:

```
> New dev
```

![Dev containers 1](./_attachments/dev-containers1.png)

Then, you'll be prompted to select a new dev container configuration. Search for and select the 'Internet Computer vvv-interactive' template.

![Dev containers 2](./_attachments/dev-containers2.png)

This template includes a local version of the ledger and NNS.

If you want to use a dev container sample, check out the [Internet Computer Start repo](https://github.com/infu/internet-computer-start/tree/main) for dev container samples.

### Open a GitHub repo in a container

You can open a GitHub repo in the container using a URL such as:

```
https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=[GITHUB_URL]
Expand All @@ -26,6 +54,17 @@ For example, to open the ICP Hello World Motoko example, open the URL:
https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/dfinity/icp-hello-world-motoko
```

When prompted, select 'Open Visual Studio Code'.
When prompted, select 'Open Visual Studio Code'.

Upon opening in VS Code, you may be prompted to install the required plugins to use the developer containers feature.

## Using Docker directly

You can also use Docker directly instead of through the VS Code dev containers extension. To use Docker directly, first [install Docker Desktop](https://www.docker.com/products/docker-desktop/) and start the Docker Daemon. Then, open a command line window, pull the DFINITY ICP developer environment Docker image and run an instance of the image:

```
docker pull ghcr.io/dfinity/icp-dev-env:latest
docker run --platform linux/x86_64 -dit ghcr.io/dfinity/icp-dev-env:latest
```


Upon opening in VS Code, you will be prompted to install the required plugins to use the developer containers feature.
55 changes: 53 additions & 2 deletions docs/developer-docs/getting-started/install/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,60 @@ You can download and install the latest version of the
</TabItem>

<TabItem value="windows" label="Install on Windows">
There is no native support for <code>dfx</code> on Windows. However, by installing the Windows Subsystem for Linux (WSL), you can run <code>dfx</code> also on a Windows system as described below.
There is no native support for <code>dfx</code> on Windows. However, you can develop ICP canisters on Windows using a Docker container or by installing the Windows Subsystem for Linux (WSL).

## Installing WSL 2
## Using Docker

Docker is a containerization software that allows you to run a localized version of another operating system, such as Linux, then run Linux-based software and applications. Containers do not have access to the files and applications outside of the container unless given explicit permission.

To use Docker, first [install Docker Desktop](https://www.docker.com/products/docker-desktop/).

Open the Docker Desktop application to start the Docker Daemon. Then, open a command line window and pull the DFINITY ICP developer environment Docker image:

```
docker pull ghcr.io/dfinity/icp-dev-env:latest
```

Then, run an instance of this Docker image with the command:

```
docker run --platform linux/x86_64 -dit ghcr.io/dfinity/icp-dev-env:latest
```

Confirm that your container is running by using the `docker ps` command:

```
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b197b1da16df ghcr.io/dfinity/icp-dev-env:latest "bash" 37 seconds ago Up 36 seconds peaceful_lumiere
```

Now you can navigate into your Docker container and begin running commands such as `dfx`. To navigate into the canister, run the command:

```
docker exec -it <NAME> bash
```

Replace `<NAME>` with the canister name shown in the `docker ps` output.

If successful, your command line prompt will change such as:

```
root@b197b1da16df:/#
```

Verify that `dfx` has been installed and is ready to use by running the command:

```
dfx --version
```

This should return the version of `dfx` that was installed:

```
dfx 0.18.0
```

## Using WSL 2
Follow Microsoft&#39;s instructions for installing the <a href="https://docs.microsoft.com/en-us/windows/wsl/install">Windows Subsystem for Linux</a>. Make sure you are running Windows 10 (version 2004 or higher) or Windows 11.

### Supported WSL Versions
Expand Down

0 comments on commit 231abc7

Please sign in to comment.