Skip to content

Commit 87c8419

Browse files
committed
initial copy of docker for cpp project
1 parent 1ac9951 commit 87c8419

6 files changed

Lines changed: 125 additions & 0 deletions

File tree

docker/Dockerfile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
FROM ubuntu:20.04
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
5+
RUN apt-get update && apt-get -y dist-upgrade && apt-get -y install --fix-missing \
6+
binutils \
7+
build-essential \
8+
bzip2 \
9+
ccache \
10+
clang-format \
11+
cmake \
12+
curl \
13+
gdb \
14+
gdbserver \
15+
git \
16+
locales \
17+
python \
18+
python3-pip \
19+
rsync \
20+
ruby \
21+
shellcheck \
22+
ssh \
23+
sudo \
24+
tar \
25+
valgrind \
26+
vim \
27+
&& apt-get autoremove -y && apt-get clean
28+
29+
RUN locale-gen en_US.utf8 en_GB.utf8 de_DE.utf8 && update-locale
30+
31+
RUN groupadd -g 1000 dev && \
32+
useradd -m -u 1000 -g 1000 -d /home/dev -s /bin/bash dev && \
33+
usermod -a -G adm,cdrom,sudo,dip,plugdev dev && \
34+
echo 'dev:dev' | chpasswd && \
35+
echo "dev ALL=(ALL:ALL) ALL" >> /etc/sudoers
36+
37+
# fix "Missing privilege separation directory" error in SSHD
38+
# see: https://bugs.launchpad.net/ubuntu/+source/openssh/+bug/45234
39+
RUN mkdir /var/run/sshd && chmod 0755 /var/run/sshd
40+
41+
COPY ccache.conf /etc/.
42+
43+
USER dev
44+
WORKDIR /home/dev
45+
46+
RUN sed -i 's/\\h/docker/;s/01;32m/01;33m/' /home/dev/.bashrc
47+
48+
RUN mkdir /home/dev/git

docker/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
:bangbang: Very much work in progress!
2+
3+
# The container
4+
5+
## Building
6+
7+
`./build-image.sh`
8+
9+
## Starting
10+
11+
`docker-compose up -d`
12+
13+
## Entering
14+
15+
- Via ssh: `ssh dev@localhost -p 2222` , password is `dev`
16+
- Via docker exec: `docker exec -i -t -u dev:dev cpp_docker_env bash`
17+
18+
## Stopping
19+
20+
`docker-compose down`
21+
22+
23+
# Working on projects
24+
25+
The user for the Docker container is `dev`.
26+
The compose file maps `~/git` on the host machine to `/home/dev/git` in the contianer, so I suggest that you check out your project there.
27+
28+
29+
30+
31+
32+

docker/build-image.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash -e
2+
3+
DOCKER_BUILDKIT=1 docker build -t cppenv:latest .

docker/ccache.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
max_size = 20.0G

docker/cpp-docker

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#! /bin/bash
2+
CONTAINER=cpp_docker_env
3+
WORKDIR=$(pwd)
4+
5+
if ! /usr/bin/docker ps | grep "${CONTAINER}" > /dev/null; then
6+
docker-compose up -d
7+
fi
8+
9+
if [ $# -ne 0 ]; then
10+
docker exec -i -t -u dev:dev "${CONTAINER}" bash -c "if [ -d \"${WORKDIR}\" ]; then cd ${WORKDIR}; fi; $*"
11+
else
12+
# (The shell is interactive if bash is called without arguments :)
13+
docker exec -i -t -u dev:dev "${CONTAINER}" bash
14+
fi

docker/docker-compose.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
version: '3'
2+
3+
services:
4+
ssh:
5+
security_opt: # options needed for gdb debugging
6+
- seccomp:unconfined
7+
- apparmor:unconfined
8+
cap_add:
9+
- SYS_PTRACE
10+
container_name: cpp_docker_env
11+
image: cppenv:latest
12+
environment:
13+
- TERM=xterm-256color # For a colored Terminal
14+
- SSH_AUTH_SOCK=/ssh-agent
15+
volumes:
16+
- ${SSH_AUTH_SOCK}:/ssh-agent # Forward local machine SSH to docker
17+
- ${HOME}/.ssh/known_hosts:/home/dev/.ssh/known_hosts # If the host trusts, we shall trust as well.
18+
- ${HOME}/.ssh/config:/home/dev/.ssh/config
19+
- ${HOME}/.gitconfig:/home/dev/.gitconfig
20+
- ${HOME}/git:/home/dev/git
21+
command: /usr/sbin/sshd -D
22+
user: root
23+
network_mode: "bridge"
24+
ports:
25+
- "2222:22"
26+
privileged: true
27+
hostname: cpp_docker_env

0 commit comments

Comments
 (0)