-
Notifications
You must be signed in to change notification settings - Fork 45
chore: update dind examples to use onCreateCommand #350
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
Changes from 1 commit
b4581fa
482a212
cd83f04
e7139d9
e9a45f9
df95d7d
c11e0e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
FROM ubuntu:noble | ||
# Install Docker using Docker's convenience script. | ||
RUN apt-get update && \ | ||
apt-get install -y curl apt-transport-https && \ | ||
curl -fsSL https://get.docker.com/ | sh -s - | ||
ADD entrypoint.sh /entrypoint.sh | ||
ENTRYPOINT ["/entrypoint.sh"] | ||
apt-get install -y curl sudo apt-transport-https && \ | ||
curl -fsSL https://get.docker.com/ | sh -s - | ||
# Add a non-root user with sudo privileges and allow | ||
# passwordless sudo for the user. | ||
# Note: we chown /var/run/docker.sock to the non-root user | ||
# in the onCreateCommand script. Ideally you would add the | ||
# non-root user to the docker group, but in this scenario | ||
# this is a 'single-user' environment. It also avoids us | ||
# having to run `newgrp docker`. | ||
RUN useradd -m -s /bin/bash -G sudo coder && \ | ||
echo "coder ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/coder | ||
# Add our onCreateCommand script. | ||
ADD on-create.sh /on-create.sh | ||
# Switch to the non-root user. | ||
USER coder |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"build": { | ||
"dockerfile": "Dockerfile" | ||
} | ||
} | ||
}, | ||
"onCreateCommand": "/on-create.sh" | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
# Start Docker in the background | ||
sudo -u root /bin/sh -c 'nohup dockerd 2>&1 > /var/log/docker.log &' | ||
johnstcn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Wait for Docker to start | ||
johnstcn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for attempt in $(seq 1 10); do | ||
if [[ $attempt -eq 10 ]]; then | ||
echo "Failed to start Docker" | ||
exit 1 | ||
fi | ||
if [[ ! -e /var/run/docker.sock ]]; then | ||
sleep 1 | ||
else | ||
break | ||
fi | ||
done | ||
# Change the owner of the Docker socket so that the coder user can use it. | ||
# Using `newgrp docker` is kind of annoying. | ||
johnstcn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sudo chown coder:coder /var/run/docker.sock | ||
johnstcn marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
FROM ubuntu:noble | ||
ADD entrypoint.sh /entrypoint.sh | ||
ENTRYPOINT ["/entrypoint.sh"] | ||
# Install some dependencies such as curl and sudo. | ||
# Also set up passwordless sudo for the ubuntu user. | ||
RUN apt-get update && \ | ||
DEBIAN_FRONTEND=noninteractive apt-get install -y \ | ||
curl \ | ||
sudo \ | ||
apt-transport-https && \ | ||
echo "ubuntu ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/ubuntu | ||
# Add our onCreateCommand script. | ||
ADD on-create.sh /on-create.sh | ||
# Switch to the non-root user. | ||
USER ubuntu | ||
# The devcontainer feature provides /usr/local/share/docker-init.sh | ||
# which will handle most of the steps of setting up Docker. | ||
# We can't put this in the entrypoint as it gets overridden, so | ||
# we call it in the on-create script. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we not support setting entrypoint in the Dockerfile at all? Maybe we should in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My observation is that whatever entrypoint you set gets overridden by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a Coder workspace we need to have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filed #351 to follow up on this. |
||
ENTRYPOINT ["bash"] |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
# Run the devcontainer init script. This needs to be | ||
# run as root. | ||
sudo /usr/local/share/docker-init.sh |
Uh oh!
There was an error while loading. Please reload this page.