This is a list of every docker command I find useful and a bit of info about it. It is not intended to be a tutorial of any kind, but maybe someone will find this list as useful as I consider it to be!
General
docker version
- if any error here, docker is probably not running. If on linux, do a sudodocker info
- a lot more info about the docker installation
Containers
docker container run IMAGE
- first it gets an image from local machine, if it doesn’t find one, tries to get one from docker hub. If not connected to the internet and one does not have the image locally, well you should not live in the cave ages. The docker container run always ends with the image name if no command is passed. The version of the image can be specified here, using image:version. It defaults to image:latest. It will give it a virtual IP on a private network, named bridge, inside docker engine. It will open up port 80 on host and will forward all traffic to port 80 in the container.docker container run --publish,-p xx:yy IMAGE
- it redirects routing from the port xx of your host to the port yy of the containerdocker container run --detach,-d IMAGE
- keeps the container running detaching it from the terminal sessiondocker container run --name CONTAINER IMAGE
- creates a container with the specified container_namedocker container run --rm IMAGE
- runs a container and deletes it afterwardsdocker container run --env,-e ENV_LIST IMAGE
- sets environment variables to pass to the containerdocker container run --network NETWORK IMAGE
- it will create the container on the specified network. It will default to the network bridgedocker container run --volume,-v NAMED_VOLUME:VOLUME IMAGE
- it will bind mount a volume with the specified name. if the named volume start with a forward slash, it will map to the specified path on the host. if $(pwd) is used, it will map to the current working directory
docker container run -it CONTAINER bash
- simulates a real terminal to interact with the container. This way, when we exit the bash, the container will stop because the container only runs as long as the command that it ran on startup runs.docker container exec -it CONTAINER bash
- simulates a real terminal to interact with the running container. This way, the container will keep running once this process is exiteddocker container stop CONTAINER \[CONTAINER...\]
- stops a running container
docker container ls (docker ps)
- lists all the running containersdocker container ls -a (docker ps -a)
- lists all existing containers, even the non-running onesdocker container rm CONTAINER \[CONTAINER...\]
- deletes the specified containers. Here, the full uid can be passed or the first 3 letters of the uid since it’s all it takes for it to be unique, or the container name. If no name was specified, it can be found doing a docker container ls -a. A running container cannot be deleted this way.docker container rm -f,--force CONTAINER \[CONTAINER...\]
- Since a running container cannot be deleted the usual way, the force option must be passeddocker container logs CONTAINER
- see the logs of the containerdocker container logs -f CONTAINER
- see the logs of the container and keeps following it. ctrl+c to exitdocker container top CONTAINER
- display the running processes of a containerdocker container inspect CONTAINER \[CONTAINER...\]
- shows detailed information of the containers specified. It doesn’t tell anything about the active container and what it’s doingdocker container stats
- shows a streaming view of live performance data about the running containers
docker container port CONTAINER
- checks the routing from the host to the container
Network
docker network ls
- The network bridge, docker0 on older versions, is the default network that bridges through the NAT firewall to the physical network the host is connected to. By default, all containers will be in this network. The network named host is a special network that skips the virtual networking of docker and attaches the container directly to the host interface. This way, it gain performance but sacrifices security of the container model. The network named none is the equivalent of having an interface on your computer that is not attached to anythingdocker network inspect NETWORK \[NETWORK...\]
- inspects the specified networks, displaying detailed information on them. This is how to find out which container are in which networkdocker network create NETWORK
- spawns a new network and allows to attach containers to itdocker network connect NETWORK CONTAINER
- connects the specified container to the specified network. A container may be connected to multiple networksdocker network disconnect NETWORK CONTAINER
- disconnects the specified container from the specified network
Images
docker image ls
- lists all the images in the hostdocker image rm IMAGE \[IMAGE...\]
- deletes the specified images. The full uid can be passed, or only the first 3 characters or the repository:tagdocker image tag SOURCE_IMAGE\[:TAG\] TARGET_IMAGE\[:TAG\]
- It defaults to latest if no tag is passed. The best name would be default instead of latest since latest is not always the latest version of the imagedocker image push IMAGE
- pushes the image to docker hubdocker image build -t,--tag TAG PATH | URL
- builds an image with the specified tags, latest if none is supplied. A path to a dockerfile must be supplied
Volumes
docker volume ls
- lists all existing volumesdocker volume rm VOLUME \[VOLUME...\]
- removes the specified volumedocker volume prune
- removes all non used volumesdocker volume inspect VOLUME \[VOLUME...\]
- the mount point is not accessible directly from the host if using a mac, since docker creates a tiny linux vm to run, so all this data will be stored there. there is a way to get there, but I haven’t figured it out yetdocker volume create VOLUME
-