Skip to content

Instantly share code, notes, and snippets.

@sdkks sdkks/Dockerfile
Last active Jun 30, 2018

Embed
What would you like to do?
Dockerized Ubuntu Bionic Beaver (18.04 LTS) Workstation/Terminal (Can run Windows Docker commands)

Update: Moved into Github repo for various reasons, gist won't be updated anymore. Repo URL: https://github.com/sdkks/DockerizedUbuntuWS

HOW TO

You can use cmd or powershell to run compose.bat which sets a required environment variable then brings it up.

In my example, home is a volume managed by docker, that is where my all work stuff is. (Some is synced to private git repos, some to Dropbox, some are discardable etc.)

You can create a docker volume using docker volume create <volumeName>

I'm using cmder as terminal, which can be found here: https://github.com/cmderdev/cmder

My startup command for the terminal tabs is:

{cmd::sshShell} => ssh localhost -p 2222

If you download docker binary to a directory, you can add this to your .zshrc alias docker='sudo ~/.local/bin/docker'

Because docker.sock is mounted every time container runs fresh, permissions are 'root-only'.

Docker binary download URL: https://docs.docker.com/install/linux/docker-ce/binaries/

TODO

  • Less hacky way of adding user
  • Instructions for Windows SSH (cmd) client and public/private key setup
  • Make readme.md less crappy
set COMPOSE_CONVERT_WINDOWS_PATHS=1
docker-compose down && docker-compose up -d
version: '3.6'
services:
bionic:
build: .
privileged: true
container_name: ws
hostname: galileo
ports:
- "2222:22"
volumes:
- "home:/home"
- d:\\:/mnt/d
- /var/run/docker.sock:/var/run/docker.sock
restart: always
volumes:
home:
FROM ubuntu:bionic
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get -y install \
binutils \
bsdutils \
build-essential \
bzip2 \
coreutils \
cron \
curl \
dnsutils \
findutils \
git \
gzip \
less \
moreutils \
net-tools \
openssh-client \
openssh-server \
p7zip-full \
perl \
python \
python-pip \
python3 \
python3-pip \
rsync \
ruby \
sed \
sudo \
vim \
wget \
zsh \
dash
# This is the segment I drop in additional packages, so for above steps docker-cache can be used.
RUN apt-get install -y iproute2 man locales
# Generating locales. A must-have for my favourite theme `agnoster`
RUN sudo locale-gen "en_US.UTF-8"
RUN echo 'LANG="en_US.UTF-8"' > /etc/profile.d/locale.sh
RUN echo 'LANGUAGE="en_US.UTF-8"' >> /etc/profile.d/locale.sh
RUN echo 'LC_ALL="en_US.UTF-8"' >> /etc/profile.d/locale.sh
# Terminal support so you can use stuff like Vim at higher resolution
ENV TERM=xterm
# Need these dirs for sshd
RUN mkdir -p /var/run/sshd /run/sshd
# Setting root password. Don't do this at home
RUN echo 'root:<setRootPasswordHere>' | chpasswd
# Modify sshd_config to allow root login.
# Goes without saying, this and above can be removed if you figured out how to use ssh key within your environment
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# SSH login fix. Taken from here https://docs.docker.com/engine/examples/running_ssh_service/
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
# Creating my user, baking my password into login, giving sudo permission with no password prompt
RUN echo 'yourUsername:x:1000:1000::/home/yourUsername:/usr/bin/zsh' >> /etc/passwd
RUN echo 'yourUsername:x:1000:' >> /etc/group
RUN echo 'yourUsername:$6$scm9LOg4$<TRUNCATED salted password in shadow file>:17706:0:99999:7:::' >> /etc/shadow
RUN usermod -aG sudo yourUsername
RUN echo 'yourUsername ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
# Taken from here https://docs.docker.com/engine/examples/running_ssh_service/
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
@sdkks

This comment has been minimized.

Copy link
Owner Author

sdkks commented Jun 30, 2018

Made a repo here: https://github.com/sdkks/DockerizedUbuntuWS
Issues, changes, suggestions will be there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.