Docker
Images
images— list local imagespull— download an image from hubsearch— search hub for imagesbuildrmi
Containers
-
create— create a container -
start— start a stopped container -
run— create and start a container -
stop— stop a running container -
ps -a— list all running and stopped containers -
rm— remove a container -
attach— connect to a running bash prompt (for example) -
logs -f— watch terminal output -
top— inspect processes in container -
exec— run a one-off process in an already-running container -
cp— copy files to/from the container
Cookbook
run -it [image] [command]- creates a container out of an image and runs a command in itrun -it [image] /bin/bash- creates a container out of an image and opens you a shell in itrun --name [new-container] [image]logs -f [container]exec -it [container] [command]- run a command in a running containerexec -it [container] /bin/bash- log you in to a running container
Run a temporary container:
Dockerfile in this folder:
docker run --rm -it -v $(pwd):/myapp $(docker build -q .)
docker build . - build an image from the Dockerfile in the current directory
-
-qoutput the built image hash -
$()insert that built image hash -
docker run- run a container -
--rm- remove the container when done -
-it- interactive terminal -
-vmount a volume -
$(pwd)- current directory -
/myapp- path within the container
Slapdash