Docker: commands

/Notebook/Notes

Introduction

An application has a set of dependencies and OS compatibility. Some projects often constitutes of different applications. Multiple applications presents problems to the project with OS and dependency contradictions among these applications. Docker solves this issue by separating the applications into different environments and deliver them as images/containers.

This blog only covers a summary of the commands. See full documentation here.

Summary

Command Description
docker version identify the docker version running on the host
docker run attach [container_id / container_name] attach back to a running container
docker run --name=[container_name] [image] assign a name when running a container
docker run --link [app_var]:[container_name] links an application by mapping a variable of that app to a docker container
docker run -i [prompt_application] runs prompt application in an interactive mode
docker run -it [prompt_application] runs prompt application in an interactive mode on pseudo-terminal
docker run -p 80:5000 [image] map port 80 of localhost to port 5000 of docker container
docker run -v [dir1]:[dir2] [image] map docker host directory dir1 to docker container directory dir2 to preserve data
docker run -e [var]=[value] [image] run an image defined by environment variable var=value
docker run [image] --network=host run docker image on local host port
docker run --cpu=[percentage] [image] makes sure that running an image will not take up a percentage, in decimal formt, threshold of the cpu
docker run --memory=[size]m [image] makes sure that running an image will not take up a size threshold of the memory
docker ps lists all running containers and some basic information about them
docker ps -a lists all containers be it running, stopped, or exited
docker stop [container_id / container_name] stop a running container
docker images lists available images and their sizes
docker rm [container_id / container_name] remove a stopped/exited container permanently
docker rmi removes an image (make sure to have stopped and removed containers from this image)
docker exec [container_id / container_name] [???] [???] execute a command on a docker container
docker inspect [container_id / container_name] returns all details of a container in a json format
docker push [tag_name] push your image into docker hub
docker pull [image] pulls an image but doesn't run a container unlike docker run command
docker logs [container_id / container_name] view the logs of container running in background or detached mode
docker build [docker_file] -t [tag_name] build an image from docker file locally on your system
docker-compose up bring up an entire application stack
docker network create --driver bridge subnet [subnet] custom-isolated-network create a bridge network
docker network ls list all docker networks
docker volume create [volume_name] creates a volumee