refactor: split docker install with env

This commit is contained in:
Danny Avila 2024-06-30 17:22:53 -04:00
parent 104dc9a08e
commit a950f57ee6
No known key found for this signature in database
GPG key ID: 2DD9CC89B9B50364
4 changed files with 33 additions and 21 deletions

View file

@ -0,0 +1,2 @@
# When running devcontainers, you can specify if docker & docker-compose should be installed in your environment
INSTALL_DOCKER=false

View file

@ -1,16 +1,22 @@
FROM node:18-bullseye
RUN apt-get update && apt-get install -y sudo
RUN useradd -m -s /bin/bash vscode && echo "vscode ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/vscode
RUN mkdir -p /workspaces && chown -R vscode:vscode /workspaces
WORKDIR /workspaces
ARG INSTALL_DOCKER="false"
ENV INSTALL_DOCKER=${INSTALL_DOCKER}
# Install Docker and Docker Compose
RUN apt-get update && \
apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release && \
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg && \
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null && \
apt-get update && \
apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
# Install Docker and Docker Compose only if INSTALL_DOCKER is "true"
RUN if [ "$INSTALL_DOCKER" = "true" ]; then \
apt-get update && \
apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release && \
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg && \
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null && \
apt-get update && \
apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin; \
fi
# Set up non-root user
RUN useradd -m -s /bin/bash vscode
RUN if [ "$INSTALL_DOCKER" = "true" ]; then usermod -aG docker vscode; fi
USER vscode
WORKDIR /workspaces

View file

@ -5,17 +5,19 @@
"workspaceFolder": "/workspaces",
"customizations": {
"vscode": {
"extensions": ["ms-azuretools.vscode-docker"],
"settings": {
"terminal.integrated.defaultProfile.linux": "bash"
}
"extensions": ["ms-azuretools.vscode-docker"]
}
},
"postCreateCommand": "sudo apt-get update && sudo apt-get install -y docker.io docker-compose",
"features": {
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"version": "latest",
"moby": true,
"dockerDashComposeVersion": "v2"
}
},
"remoteUser": "vscode",
"forwardPorts": [3080, 27017, 7700]
"postCreateCommand": "sudo chown -R vscode:vscode /workspaces && if [ \"$CODESPACES\" = \"true\" ]; then sudo apt-get update && sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin; fi",
"remoteEnv": {
"INSTALL_DOCKER": "${localEnv:INSTALL_DOCKER:false}"
}
}

View file

@ -2,9 +2,11 @@ version: "3.8"
services:
app:
build:
build:
context: ..
dockerfile: .devcontainer/Dockerfile
args:
- INSTALL_DOCKER=${INSTALL_DOCKER:-false}
# restart: always
links:
- mongodb
@ -37,7 +39,7 @@ services:
user: vscode
# Overrides default command so things don't shut down after the process ends.
command: /bin/sh -c "while sleep 1000; do :; done"
command: /bin/sh -c "while sleep 1000; do :; done"
mongodb:
container_name: chat-mongodb