Update ports and readme

This commit is contained in:
bamurtaugh
2021-04-14 17:05:05 +00:00
parent ae666fe69c
commit 988e96a603
2 changed files with 14 additions and 11 deletions

View File

@@ -21,17 +21,22 @@
// Use 'forwardPorts' to make a list of ports inside the container available locally. // Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [3000], // "forwardPorts": [3000],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "yarn install",
// Use 'portsAttributes' to set default properties for specific forwarded ports. // Use 'portsAttributes' to set default properties for specific forwarded ports.
// You can use a port number (i.e. 3000), range of numbers, or a regex to match the running process.
"portsAttributes": { "portsAttributes": {
"3000": { ".+/server.js": {
"label": "Hello Remote World", "label": "Hello Remote World"
"onAutoForward": "notify"
} }
}, },
// Use 'otherPortsAttributes' to configure any ports that aren't configured using 'portsAttributes'.
// "otherPortsAttributes": {
// "onAutoForward": "silent"
// },
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "yarn install",
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node" "remoteUser": "node"
} }

View File

@@ -53,7 +53,7 @@ Some things to try:
- Continue (<kbd>F5</kbd>). You can connect to the server in the container by either: - Continue (<kbd>F5</kbd>). You can connect to the server in the container by either:
- Clicking on `Open in Browser` in the notification telling you: `Your service running on port 3000 is available`. - Clicking on `Open in Browser` in the notification telling you: `Your service running on port 3000 is available`.
- Clicking the globe icon in the 'Ports' view. The 'Ports' view gives you an organized table of your forwarded ports, and you can access it with the command **Ports: Focus on Ports View**. - Clicking the globe icon in the 'Ports' view. The 'Ports' view gives you an organized table of your forwarded ports, and you can access it with the command **Ports: Focus on Ports View**.
- Notice port 3000 in the 'Ports' view is labeled "Hello Remote World." In `devcontainer.json`, you can set `"portsAttributes"`, such as a label for your forwarded ports and the action to be taken when the port is autoforwarded. - Notice port 3000 in the 'Ports' view is labeled "Hello Remote World." In `devcontainer.json`, you can set `"portsAttributes"`, such as a label for your forwarded ports and the action to be taken when the port is autoforwarded.
> **Note:** In Remote - Containers, you can access your app at `http://localhost:3000` in a local browser. But in a browser-based Codespace, you must click the link from the notification or the `Ports` view so that the service handles port forwarding in the browser and generates the correct URL. > **Note:** In Remote - Containers, you can access your app at `http://localhost:3000` in a local browser. But in a browser-based Codespace, you must click the link from the notification or the `Ports` view so that the service handles port forwarding in the browser and generates the correct URL.
@@ -61,12 +61,10 @@ Some things to try:
You may want to make changes to your container, such as installing a different version of a software or forwarding a new port. You'll rebuild your container for your changes to take effect. You may want to make changes to your container, such as installing a different version of a software or forwarding a new port. You'll rebuild your container for your changes to take effect.
**Forward a port statically:** As an example change, let's forward a port statically in the `.devcontainer/devcontainer.json` file. **Forward a port statically:** As an example change, let's update the `portsAttributes` in the `.devcontainer/devcontainer.json` file to open a browser when our port is automatically forwarded.
> **Note:** Remote-Containers and Codespaces also take care of dynamic port forwarding, but there may be instances in which we want to statically declare a forwarded port.
- Open the `.devcontainer/devcontainer.json` file. - Open the `.devcontainer/devcontainer.json` file.
- Uncomment the `forwardedPorts` attribute and adjust the port number as needed. - Modify your `portsAttributes` to include a new attribute (you can add it underneath the `label` attribute): `"onAutoForward": "openBrowser"`.
- Press <kbd>F1</kbd> and select the **Remote-Containers: Rebuild Container** or **Codespaces: Rebuild Container** command so the modifications are picked up. - Press <kbd>F1</kbd> and select the **Remote-Containers: Rebuild Container** or **Codespaces: Rebuild Container** command so the modifications are picked up.
## Contributing ## Contributing