aboutsummaryrefslogtreecommitdiff
path: root/dotfiles/cheat/docker
blob: 86187f506e7a7955c13395ea924a7e8b9629a285 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Start docker daemon
docker -d

# start a container with an interactive shell
docker run -ti <image_name> /bin/bash

# exemple run container with python:3 and delete all created files
docker run -it --rm python:3 bash

# container with mounted volume in read-only
docker run -it -v "/source:/dest:ro" <image_name> bash

# "shell" into a running container (docker-1.3+)
docker exec -ti <container_name> bash

# inspect a running container
docker inspect <container_name> (or <container_id>)

# Get the process ID for a container
# Source: https://github.com/jpetazzo/nsenter
docker inspect --format {{.State.Pid}} <container_name_or_ID>

# List the current mounted volumes for a container (and pretty print)
# Source:
# http://nathanleclaire.com/blog/2014/07/12/10-docker-tips-and-tricks-that-will-make-you-sing-a-whale-song-of-joy/
docker inspect --format='{{json .Volumes}}' <container_id> | python -mjson.tool

# Copy files/folders between a container and your host
docker cp foo.txt mycontainer:/foo.txt

# list currently running containers
docker ps

# list all containers
docker ps -a

# list all images
docker images

IF: dpkg: error: error creating new backup file '/var/lib/dpkg/status-old': Invalid cross-device link E: Sub-process /usr/bin/dpkg returned an error code (2)
DO: echo N | sudo tee /sys/module/overlay/parameters/metacopy

# command for launch GUI soft, sometimes custom Dockerfile is needed
--user $UID -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix <container_name>