-
-
Notifications
You must be signed in to change notification settings - Fork 801
Fix devcontainer for website development #8967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Port 8000 is being auto-forwarded, but the page doesn't load. It doesn't seem to load locally via Do we know why the forwarding is not working? I think it's best to avoid host networking unless there is no other option. Did you try connecting after adding the |
I tried to figure it out, but could not find the reason for it. Using the host network was the only solution I found so far.
I got the page running inside the container, but it still failed to open it without the host network option. I made a mistake: Previously installed google chrome (see Option 2 below) and forgot the To keep the build cache of all other steps, I moved the installation of those packages to the end. Option 1 - Installing dependencies manually# Use the base image specified in the devcontainer.json
FROM mcr.microsoft.com/devcontainers/base:bullseye
# Install dependencies
RUN apt-get update && apt-get install -y \
wget \
apt-transport-https \
curl \
gnupg2 \
lsb-release \
software-properties-common \
openssh-server
# Configure SSH server
RUN mkdir /var/run/sshd \
&& echo 'root:Docker!' | chpasswd \
&& sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config \
&& sed -i 's@session required pam_loginuid.so@session optional pam_loginuid.so@g' /etc/pam.d/sshd \
&& echo "export VISIBLE=now" >> /etc/profile
# Expose SSH port
EXPOSE 22
# Start SSH service
CMD ["/usr/sbin/sshd", "-D"]
# Install .NET SDKs (6, 7, 8, 9, and 10)
RUN wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh \
&& chmod +x dotnet-install.sh \
&& ./dotnet-install.sh --channel 6.0 --install-dir /usr/share/dotnet \
&& ./dotnet-install.sh --channel 7.0 --install-dir /usr/share/dotnet \
&& ./dotnet-install.sh --channel 8.0 --install-dir /usr/share/dotnet \
&& ./dotnet-install.sh --channel 9.0 --install-dir /usr/share/dotnet \
&& ./dotnet-install.sh --channel 10.0 --install-dir /usr/share/dotnet \
&& ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet
# Install Node.js LTS
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - \
&& apt-get install -y nodejs
# Install Yarn
RUN npm install -g yarn
# Install GitHub CLI
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& apt-get update \
&& apt-get install -y gh
# Install Azure CLI
RUN curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/microsoft.asc.gpg > /dev/null \
&& AZ_REPO=$(lsb_release -cs) \
&& echo "deb [arch=$(dpkg --print-architecture)] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | tee /etc/apt/sources.list.d/azure-cli.list \
&& apt-get update \
&& apt-get install -y azure-cli
# Install puppeteer dependencies (see https://pptr.dev/troubleshooting#chrome-doesnt-launch-on-linux)
RUN apt-get install -y \
ca-certificates \
fonts-liberation \
libasound2 \
libatk-bridge2.0-0 \
libatk1.0-0 \
libc6 \
libcairo2 \
libcups2 \
libdbus-1-3 \
libexpat1 \
libfontconfig1 \
libgbm1 \
libgcc1 \
libglib2.0-0 \
libgtk-3-0 \
libnspr4 \
libnss3 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libstdc++6 \
libx11-6 \
libx11-xcb1 \
libxcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxext6 \
libxfixes3 \
libxi6 \
libxrandr2 \
libxrender1 \
libxss1 \
libxtst6 \
lsb-release \
xdg-utils
# Clean up
RUN rm dotnet-install.sh \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*Option 2 - Installing Google Chrome using .deb# Use the base image specified in the devcontainer.json
FROM mcr.microsoft.com/devcontainers/base:bullseye
# Install dependencies
RUN apt-get update && apt-get install -y \
wget \
apt-transport-https \
curl \
gnupg2 \
lsb-release \
software-properties-common \
openssh-server
# Configure SSH server
RUN mkdir /var/run/sshd \
&& echo 'root:Docker!' | chpasswd \
&& sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config \
&& sed -i 's@session required pam_loginuid.so@session optional pam_loginuid.so@g' /etc/pam.d/sshd \
&& echo "export VISIBLE=now" >> /etc/profile
# Expose SSH port
EXPOSE 22
# Start SSH service
CMD ["/usr/sbin/sshd", "-D"]
# Install .NET SDKs (6, 7, 8, 9, and 10)
RUN wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh \
&& chmod +x dotnet-install.sh \
&& ./dotnet-install.sh --channel 6.0 --install-dir /usr/share/dotnet \
&& ./dotnet-install.sh --channel 7.0 --install-dir /usr/share/dotnet \
&& ./dotnet-install.sh --channel 8.0 --install-dir /usr/share/dotnet \
&& ./dotnet-install.sh --channel 9.0 --install-dir /usr/share/dotnet \
&& ./dotnet-install.sh --channel 10.0 --install-dir /usr/share/dotnet \
&& ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet
# Install Node.js LTS
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - \
&& apt-get install -y nodejs
# Install Yarn
RUN npm install -g yarn
# Install GitHub CLI
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& apt-get update \
&& apt-get install -y gh
# Install Azure CLI
RUN curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/microsoft.asc.gpg > /dev/null \
&& AZ_REPO=$(lsb_release -cs) \
&& echo "deb [arch=$(dpkg --print-architecture)] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | tee /etc/apt/sources.list.d/azure-cli.list \
&& apt-get update \
&& apt-get install -y azure-cli
# Install Google Chrome for puppeteer dependencies (see https://pptr.dev/troubleshooting#chrome-doesnt-launch-on-linux)
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
&& apt-get install -y ./google-chrome-stable_current_amd64.deb
# Clean up
RUN rm dotnet-install.sh google-chrome-stable_current_amd64.deb \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
Option 2 is a bit less verbose compared to running-puppeteer-in-docker, but would work too. |
| "moby": "true" | ||
| } | ||
| }, | ||
| "runArgs": ["--network=host"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be needed as devcontainers have port forwarding builtin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem to work for the website.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ports are forwared automatically, regardless of this setting, but connection to the website fails (endless loading) without this option.
Also removing the --host 0.0.0.0 option here does also not resolve the underlying issue of not reaching the website without "runArgs": ["--network=host"],:
graphql-platform/website/package.json
Line 17 in 2affc65
| "develop": "gatsby develop --verbose --host 0.0.0.0", |
In that context, using "runArgs": ["--network=host"], enables you to access the website over your local network ip, to debug on actual phones instead of emulated ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does disable Docker's network isolation, which is a minor security consideration in a dev environment. So I am not inclined to do that and rather figure out why port forwarding is a problem.
Add missing dependency and config in devcontainer
libnss3package (needed by gatsby / puppeteer)Closes #8966