Docker Commands

Docker

Images

Build

docker build -t <name>:<version> /path/to/directory_with_Dockerfile

List

docker images

Remove

docker image rm <id>

Container Start

Interactive Terminal in Container

docker run -it -p 8080:80 --name <name> <imagename> /bin/bash

Map port from host to container

docker run -it -p 8080:80 --name <name> <imagename>

Delete container after exit

docker run --rm -it --name <name> <imagename> <cmd>

Background / Detached Container

docker run -d --name <name> <imagename> <cmd>

Pipe data into container process

echo test | docker run -i --name <name> <imagename> cat

Bind-Mount Volume from Host

docker run -it -v </src>:</dst> --name <name> <imagename>

Bind-Mount Volume from Host - Readonly

docker run -it -v </src>:</dst>:ro --name <name> <imagename>

Bind-Mount Volume from Host - Modern way

docker run -it --mount type=bind,src=</src>,dst=</dst> --name <name> <imagename>

Bind-Mount Volume from Host - Readonly - Modern way

docker run -it --mount type=bind,src=</src>,dst=</dst>,readonly --name <name> <imagename>

Set ENV for Container

export VAR1=muh1
docker run -it -e VAR1 --env VAR2=muh2  --name <name> <imagename> /bin/bash

Container List

docker ps -a
docker container ls -a

Container stop

docker stop <name_or_id>

Container remove

docker rm <name_or_id>

Container Logs

docker logs <name_or_id>

System

Cleanup

Removes anything that is not in use.

docker system prune -a

Docker-Compose

Create Deployment

docker-compose up -d 

Stop Deployment

docker-compose stop

Remove Deployment

Removes containers, networks, … but NO volumes!

docker-compose down 

Remove Deployment - WITH VOLUMES

Removes containers, networks, … AND volumes!

docker-compose down --volumes