16 Feb 2017

Docker Cheat Sheet

Install docker on a debian-based system: apt-get install docker.io

Download an Ubuntu 14.04 image: docker pull ubuntu:14.04

Download many Ubuntu-based images: docker pull ubuntu

Run bash in Ubuntu: docker run -it ubuntu /bin/bash

View running containers: docker ps

Attach to a running container: docker attach b80939864b33

root@Docker:~# docker run -it ubuntu:14.04 /bin/bash
root@01a82e993d47:/# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@01a82e993d47:/# touch TEST
root@01a82e993d47:/# ls
TEST  bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@Docker:~# docker commit -m "Test" -a "ztg" 01a82e993d47 foobar/ubuntu:v2
10a437b18b7f5aa3ee657b536505ff4bb5dd956a8611cb2324b24b03b9800f4c
root@Docker:~# docker run -it foobar/ubuntu:v2
root@0233b5a1119a:/# ls
TEST  bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

View available docker images:

root@Docker:~# docker images
REPOSITORY          TAG                   IMAGE ID            CREATED             VIRTUAL SIZE
foobar/ubuntu       v2                    10a437b18b7f        3 minutes ago       188.3 MB
ubuntu              14.04                 d0955f21bf24        13 days ago         188.3 MB

Mount a local directory inside a docker image:

# docker run -v ~/localtest:/app:r -it foobar/ubuntu:v2
root@137dcc5900ad:/# ls
TEST.TXT  app  bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@137dcc5900ad:/# cd app/
root@137dcc5900ad:/app# ls
foobar.txt
View docker build history:

# docker history 0e9d632aab9a
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
0e9d632aab9a        14 minutes ago      /bin/sh -c #(nop)  CMD ["/bin/sh" "-c" "/bin/   0 B
6b5be40614f7        14 minutes ago      /bin/sh -c #(nop)  WORKDIR /changeme            0 B
70102c5d45b8        14 minutes ago      /bin/sh -c #(nop)  ENV PS1=\033[00;34mchangem   0 B
eaf7a13c1b8b        14 minutes ago      /bin/sh -c #(nop)  ENV HOME=/changeme           0 B
c664856bbbc1        14 minutes ago      /bin/sh -c apk add --no-cache --virtual .chan   60.35 MB
a7345fb8356b        16 minutes ago      /bin/sh -c #(nop) COPY dir:5a1f21cc7aea7bc6f7   285.5 kB
0d90024fd3ee        6 hours ago         /bin/sh -c mkdir /changeme                      0 B
5a520b42e52a        6 hours ago         /bin/sh -c #(nop)  MAINTAINER Zach Grace (@zt   0 B
baa5d63471ea        8 weeks ago         /bin/sh -c #(nop) ADD file:7afbc23fda8b0b3872   4.803 MB
Export a container's filesystem

# docker export -o /tmp/df06d94702ff.tar df06d94702ff

echo -e “GET /containers/0a6be72239e2/changes HTTP/1.1\r\nHost: 127.0.0.1\r\n” | ncat -U /var/run/docker.sock

Tags:
comments powered by Disqus