Docker commands #
docker build -t <image-name> .
builds an image from theDockerfile
located in the current directory and names it afterimage-name
docker run
to create a container form an image and run it. See incomplete!, see parameters below!-p <port-internal>:<port-external>
map anEXPOSE
d port to a local port, so you can communicate with the service in the container-v <dir or volume>:<dir-in-container>:[rw|ro]
mount a local directory or volume into the container at the specified path with either read/write or read-only-it
open an interactive terminal-session on the container.<image-name>
to run the default command of the image or<executable> <parameters-for-exec>
spawns a new container to run the executable in it, with the given parameters.- Example:
docker run test/image ls
lists the files of the default work-dir in the image.
- Example:
docker ps
list all running docker-containers-a
show all containers (includes stopped ones!)
docker logs <container>
to see the output of the given container.-f
to follow the output
docker stop <container-name or id>
stops the specified containerdocker images
lists all local imagesdocker exec -it <container-name or id> <program>
runs he specifiedprogram
on the currently running container.bash
as theprogram
-parameter starts an interactive shell on the container
docker kill <container-name or id>
kills the specified container (stop is preferred!)docker rmi <image-name or id>
delete a docker imagedocker rm <container-name or id>
delete a docker containerdocker volume create --name="<name>"
create a new named data-volumedocker volume ls
list all data-volumesdocker volume rm <name or id>
remove a data-volume
Helpers #
Small one-line helpers to do common Docker tasks:
docker rm $(docker ps -a -q)
Deletes all stopped Containersdocker rmi $(docker images -f "dangling=true" -q)
Deletes all dangling Images (named<none>
in Image-list).
Docker machine #
Runs a virtual machine on Windows/Mac OSX which runs docker (not on Linux, docker runs nativly there). Also enables communication with a hosted remote-machine (such as a server or AWS instance).
docker-machine ls
list all machinesdocker-machine create --driver [hyperv|virtualbox] <name>
creates a new machine with the specified driver. The name can bedefault
to make it the default machinedocker-machine start <name>
start the named machinedocker-machine stop <name>
stop the named machinedocker-machine env <name>
display the environment-configuration for the named machine.- Execute these commands (or use the provided instrucitons) to configure your lokal docker-commands to send orders to the given docker-machine.
Comments
No comment section here 😄
You can reach me over at @knuth_dev or send me an Email.