Daily: Build a Development Environment with Docker and VS Code
Introduction
Working with different software (samples, compilers, demos) always requires an adequate environment.
Because i don’t want to pollute my normal environment (my running PC), i decided to use a virtual environment with Docker.
Luckily, VS Code supports this by using remote containers and working fully within these containers.
The Files
.devcontainer\devcontainer.json
.devcontainer\devcontainer.json
{
"name": "Prolog Environment",
"dockerComposeFile": [
"docker-compose.yml"
],
"service": "app",
"workspaceFolder": "/workspace",
"settings": {},
"extensions": []
}
{
"name": "Prolog Environment",
"dockerComposeFile": [
"docker-compose.yml"
],
"service": "app",
"workspaceFolder": "/workspace",
"settings": {},
"extensions": []
}
{ "name": "Prolog Environment", "dockerComposeFile": [ "docker-compose.yml" ], "service": "app", "workspaceFolder": "/workspace", "settings": {}, "extensions": [] }
.devcontainer\docker-compose.yml
version: '3.8'
services:
app:
build:
context: .
dockerfile: Dockerfile
container_name: pws_prolog
volumes:
- ../workspace:/workspace:cached
# Overrides default command so things don't shut down after the process ends.
command: /bin/sh -c "while sleep 1000; do :; done"
version: '3.8'
services:
app:
build:
context: .
dockerfile: Dockerfile
container_name: pws_prolog
volumes:
- ../workspace:/workspace:cached
# Overrides default command so things don't shut down after the process ends.
command: /bin/sh -c "while sleep 1000; do :; done"
version: '3.8' services: app: build: context: . dockerfile: Dockerfile container_name: pws_prolog volumes: - ../workspace:/workspace:cached # Overrides default command so things don't shut down after the process ends. command: /bin/sh -c "while sleep 1000; do :; done"
.devcontainer\Dockerfile
#------------------------------------------------------------------------------
# STAGE 1:
#------------------------------------------------------------------------------
FROM ubuntu:latest as base_nodejs
# Configure Timezone
ENV TZ 'Europe/Berlin'
RUN echo $TZ > /etc/timezone
RUN apt-get update \
&& apt-get install -y tzdata \
&& rm /etc/localtime \
&& ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
&& dpkg-reconfigure -f noninteractive tzdata \
&& apt-get clean
#
RUN apt-get install --yes build-essential curl sudo git vim
# Create user
RUN groupadd work -g 1000 \
&& adduser user --uid 1000 --gid 1000 --home /workspace --disabled-password --gecos User
# Setup sudo
RUN echo '
# Install Prolog
RUN apt-get -y install swi-prolog
#
USER user
VOLUME [ "/workspace" ]
WORKDIR /workspace
CMD ["/bin/bash"]
#------------------------------------------------------------------------------
# STAGE 1:
#------------------------------------------------------------------------------
FROM ubuntu:latest as base_nodejs
# Configure Timezone
ENV TZ 'Europe/Berlin'
RUN echo TZ > /etc/timezone
RUN apt-get update \
&& apt-get install -y tzdata \
&& rm /etc/localtime \
&& ln -snf /usr/share/zoneinfo/TZ /etc/localtime \ && dpkg-reconfigure -f noninteractive tzdata \ && apt-get clean # RUN apt-get install --yes build-essential curl sudo git vim # Create user RUN groupadd work -g 1000 \ && adduser user --uid 1000 --gid 1000 --home /workspace --disabled-password --gecos User # Setup sudo RUN echo ' # Install Prolog RUN apt-get -y install swi-prolog # USER user VOLUME [ "/workspace" ] WORKDIR /workspace CMD ["/bin/bash"]
RUN apt-get update \
&& apt-get install -y tzdata \
&& rm /etc/localtime \
&& ln -snf /usr/share/zoneinfo/TZ /etc/localtime \ && dpkg-reconfigure -f noninteractive tzdata \ && apt-get clean # RUN apt-get install --yes build-essential curl sudo git vim # Create user RUN groupadd work -g 1000 \ && adduser user --uid 1000 --gid 1000 --home /workspace --disabled-password --gecos User # Setup sudo RUN echo ' # Install Prolog RUN apt-get -y install swi-prolog # USER user VOLUME [ "/workspace" ] WORKDIR /workspace CMD ["/bin/bash"]
#------------------------------------------------------------------------------ # STAGE 1: #------------------------------------------------------------------------------ FROM ubuntu:latest as base_nodejs # Configure Timezone ENV TZ 'Europe/Berlin' RUN echo $TZ > /etc/timezone RUN apt-get update \ && apt-get install -y tzdata \ && rm /etc/localtime \ && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \ && dpkg-reconfigure -f noninteractive tzdata \ && apt-get clean # RUN apt-get install --yes build-essential curl sudo git vim # Create user RUN groupadd work -g 1000 \ && adduser user --uid 1000 --gid 1000 --home /workspace --disabled-password --gecos User # Setup sudo RUN echo ' # Install Prolog RUN apt-get -y install swi-prolog # USER user VOLUME [ "/workspace" ] WORKDIR /workspace CMD ["/bin/bash"]
Leave a Reply