Skip to content

Instantly share code, notes, and snippets.

@PercyODI
Last active September 27, 2021 01:33
Show Gist options
  • Save PercyODI/cd2034e59c5de234c3baabf489536522 to your computer and use it in GitHub Desktop.
Save PercyODI/cd2034e59c5de234c3baabf489536522 to your computer and use it in GitHub Desktop.
Podman Development Environment

Dev Environment Testing

This is for building a development environment using Podman in WSL2 and connecting it with VS Code. This particular dev environment installs Go. Could be generalized, and used as a base image for more specific dev environments.

Setup

Build and run development container:

sudo podman build -t devenv:latest -f ./.devenv/Dockerfile --build-arg USER_ID=$(id -u ${USER}) --build-arg GROUP_ID=$(id -g ${USER}) .

sudo podman run -dit -p 2278:22 -v ./:/usr/dev --name devenv devenv:latest

Then connect using Visual Studo Code

Remote-SSH: Connect to Host Configure new host

ssh dev@localhost -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 2278 devcontainer

Resources

FROM ubuntu:bionic
ARG USER_ID=1000
ARG GROUP_ID=1000
RUN apt update -y \
&& apt install openssh-server sudo curl -y
# Download and install Go
WORKDIR /tmp
RUN curl -O https://dl.google.com/go/go1.17.1.linux-amd64.tar.gz
RUN tar -C /usr/local -xvzf go1.17.1.linux-amd64.tar.gz
RUN PATH=$PATH:/usr/local/go/bin \
&& echo "export PATH=$PATH" > /etc/environment
# Create dev user and src directory
RUN groupadd -g ${GROUP_ID} devgroup
RUN useradd -l -u ${USER_ID} --create-home -s /bin/bash -g devgroup -G sudo dev
RUN echo 'dev:dev' | chpasswd
# Start SSH Service
EXPOSE 22
RUN service ssh start
CMD ["/usr/sbin/sshd","-D"]
@PercyODI
Copy link
Author

Depends on a password for the dev account, which makes it weird to ssh as dev but be your host user.

Could be updated to generate an SSH key that is shared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment