Docker

Docker #

List all docker images/containes #

  • docker image list
  • “docker ps” SAME AS “docker container list “

Build a new docker image #

  • docker build -t myImages/web-server .
    (-t is for tag)

  • docker build . -t my-web-app -f subfolder/Dockerfile
    Build using context from another directory

Expose network port on a docker container #

docker run --name local-redis -p 6379:6379 -d redis
Important! the ‘-d redis’ should be at the end of the command
-d stands for detached mode

Start a docker container and keep it running #

docker run -td <image>

Run normally #

docker run -d <image>

Start a docker container and inspect it #

docker run -it --entrypoint=sh test_image

Inspect a running docker container #

docker exec -it <containerIdOrName> bash
OR
docker exec -it <containerIdOrName> sh

View docker container logs #

docker logs fe8a513ec656

Remove all stopped containers #

docker container prune
Docker system prune

Delete docker unused images #

docker system prune -a

Build an image and stop at a specific stage (in a mult-stage build) #

docker build . --target <STAGE> -t <TAG>

Reclaim docker disk size on windows #

Volume: %AppData%\..\Local\Docker\wsl\data\ext4.vhdx

View docker storage size #

docker system df

View docker memory usge #

docker stats

Where does docker store its files? #

  • Windows c:\ProgramData\DockerDesktop\%AppData%\..\Local\Docker\wsl
  • macOS: ~/Library/Containers/com.docker.docker/Data/vms/0/
  • Linux: /var/lib/docker/

Using AWS Cloudwatch with docker containers that are running on AWS ECS #

The “ECS, docker, cloudwatch log driver” splits each cloudwatch record on new line.

To keep a single log entry for multiline logs, then use the awslogs-multiline-pattern cloudwatch driver option to specify a string for the multiline statements i.e.
(^access:)|(^info:)|(^debug:)|(^log:)|(^error:)|(^warn:)

Docker is not starting on windows #

Delete %appdata%\Docker\settings.json and let Docker to create a new one