Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
docker:start [2015/03/03 11:34]
vondra
docker:start [2015/03/04 16:44] (current)
vondra
Line 1: Line 1:
 +======Docker======
 +  * best source of docker wisdom: https://​github.com/​wsargent/​docker-cheat-sheet
 +
 +===== Building a docker image =====
 +  - Create Dockerfile or clone docker repository
 +  - Run:<​code>​docker build -t YourImage /​path/​to/​dir/​with/​dockerfile</​code>​
 +
 ===== Running docker container ===== ===== Running docker container =====
 <​code>​docker run -v /​srv/​elgoog:/​mnt -d algoo</​code>​ <​code>​docker run -v /​srv/​elgoog:/​mnt -d algoo</​code>​
Line 6: Line 13:
   * -c   cpu limit   * -c   cpu limit
  
-===== Attach to the running container =====+===== Attach to the running container ​(docker >= 1.3) ===== 
 +<​code>​docker exec -it <​containerIdOrName>​ bash</​code>​ 
 + 
 +===== Attach to the running container (docker < 1.3) =====
   * first discover all running containers on host <​code>​   * first discover all running containers on host <​code>​
 docker ps </​code>​ docker ps </​code>​
Line 14: Line 24:
 d5e31d1cbe9c ​       algoo:​latest ​       supervisord -n      3 seconds ago       Up 2 seconds ​       80/​tcp ​             furious_hopper ​       d5e31d1cbe9c ​       algoo:​latest ​       supervisord -n      3 seconds ago       Up 2 seconds ​       80/​tcp ​             furious_hopper ​      
 ec704ed40100 ​       algoo:​latest ​       supervisord -n      4 seconds ago       Up 3 seconds ​       80/​tcp ​             distracted_babbage </​code>​ ec704ed40100 ​       algoo:​latest ​       supervisord -n      4 seconds ago       Up 3 seconds ​       80/​tcp ​             distracted_babbage </​code>​
-  * attach to the container ​ by id<​code>​+  * attach to the container ​ by id (works only if COMMAND = bash)<​code>​
 docker attach d5e31d1cbe9c docker attach d5e31d1cbe9c
 </​code>​ </​code>​
Line 20: Line 30:
   * The cleanest way how to copy files between host and container is to mount an image to the container <​code>​docker run -v /​path/​to/​hostdir:/​mnt $container   * The cleanest way how to copy files between host and container is to mount an image to the container <​code>​docker run -v /​path/​to/​hostdir:/​mnt $container
 cp /​mnt/​sourcefile /​path/​to/​destfile</​code>​ cp /​mnt/​sourcefile /​path/​to/​destfile</​code>​
 +
 +===== Delete old docker images and keep the running ones =====
 +  * remove images from docker<​code>​docker ps -a | grep '​Exited'​ | awk '​{print $1}' | xargs --no-run-if-empty docker rm </​code>​
 +  * delete them physically<​code>​docker images --no-trunc| grep none | awk '​{print $3}' | xargs -r docker rmi </​code>​
 +
 +====== Docker networking ======
 +  * http://​blog.oddbit.com/​2014/​08/​11/​four-ways-to-connect-a-docker/​
 
docker/start.1425378894.txt.gz · Last modified: 2015/03/03 11:34 (external edit)