Docker Cheetsheet

Common Commands

List all running images
docker ps -a

Start a container
docker start [instance_name]

Run a command shell in an already running image:
docker exec -i -t [instance_name] /bin/bash

Run a command shell in an already running images as a different user:
docker exec -i -t --user root [instance_name] /bin/bash

Create Image

docker commit <CONTAINER_ID> <image/name>

Building Custom Images

Building your own docker image is easy. Its pretty much all controlled with a Dockerfile. To build the image run: docker build -t [image_name] [path/to/Dockerfile]

Create an instance
docker run --name [instance_name] [image_name]

Dockerfile

FROM jenkins:latest

USER root  
RUN apt-get update  
RUN apt-get install -y \  
automake \  
bison \  
file \  
flex \  
git \  
g++ \  
make \  
mingw-w64 \  
lib32stdc++6 \  
lib32z1 \  
python3

COPY ninja-build_1.6.0-1.deb .  
RUN dpkg -i ninja-build_1.6.0-1.deb && rm ninja-build_1.6.0-1.deb

COPY meson_0.26.0-1_amd64.deb /  
RUN dpkg -i meson_0.26.0-1_amd64.deb && rm meson_0.26.0-1_amd64.deb

USER jenkins  
env PATH /var/android-sdk/tools:$PATH  

Paul Soucy

Read more posts by this author.