docker build --platform linux/amd64 -t lab-dev-env .The following sections provide commands for running the container as a development environment. If the host does not have any CLIs installed, the first method can be used. If the host has CLIs installed, the second will require less setup.
docker run \
-e HOST_PROJECT=$(pwd) \
--mount type=bind,source=$(pwd),target=/home/project \
--mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \
-p1485:1485 \
--name lab-dev-env \
lab-dev-envSome notes about the above command:
- The
HOST_PROJECTenvironment variable is required for preview and validate commands. --mount type=bind,source=$(pwd),target=/home/projectmounts the host directory (the lab repo directory) into the container.--mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sockmounts the host's docker socket into the container. This is optional and only needed when developing CLI/IDE-based labs.-p1485:1485exposes port 1485 on the host machine. This is the port that the IDE runs on.--name lab-dev-envgives the container a name.lab-dev-envis the name of the image to run.
CLI tools can then be authenticated within the container if needed. For example:
gh auth loginaws configureaz logingcloud auth login
For systems with AWS, Az, gcloud, and/or gh CLIs installed, the authentication can be passed through using volume mounts. The following example is for a host with GitHub CLI, and AWS CLI installed.
docker run \
-e HOST_PROJECT=$(pwd) \
--mount type=bind,source=$(pwd),target=/home/project \
--mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \
--mount type=bind,source=$HOME/.aws,target=/home/coder/.aws \
--mount type=bind,source=$HOME/.config/gh/,target=/home/coder/.config/gh \
-p1485:1485 \
--name lab-dev-env \
lab-dev-envThe following mount passes Azure CLI authentication through to the container:
--mount type=bind,source=$HOME/.azure,target=/home/coder/.azureThe following mount passes Google Cloud CLI authentication through to the container:
--mount type=bind,source=$HOME/.config/gcloud,target=/home/coder/.config/gcloudNavigate to http://localhost:1485 in your browser to access the IDE. You will need to acknowledge that it is an insecure connection. This is because the certificate is self-signed. Some features require using HTTPS, so a self-signed certificate is used for running the server.
Most features of the IDE will work without trusting the certificate. However, some features like Markdown Preview will not work without trusting the certificate. See HTTPS Certificate Errors to add trust.
To remove the certificate error, you can add the certificate to your trusted certificates. The certificate is located at deploy-container/server.crt in this repository. You can copy it to your host machine and add it to your trusted certificates.
The certificate was generated using
openssl req -x509 -out server.crt -keyout server.key \
-newkey rsa:2048 -nodes -sha256 \
-subj '/CN=localhost' -extensions EXT -config <( \
printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")In Finder, double-click deploy-container/server.crt. This adds and opens it in Keychain Access.
Double-click localhost in Keychain Access.
In the Trust section, change When using this certificate to Always Trust.
Your browser should now trust the certificate and features like Markdown Preview should work.
Not started
