Docker Cheatsheet

  • #docker

Images

Dockerfile

FROM alpine

RUN apk add --update --no-cache -q bash

CMD ["echo", "my.Dockerfile"]

Build

docker build -t my_image my.Dockerfile

List

docker image ls

Remove

docker image rm my_image

Containers

Run

docker run -d --name my_container my_image

Execute

docker run -it --rm my_image /bin/bash

List

docker ps

Logs

docker logs -f my_image

Remove

docker container rm -f my_container

Docker Compose

version: '3'
services:
  my_service:
    build:
      context: .
      dockerfile: my.Dockerfile
    image: my_image

Build

docker-compose build my_service

Run

docker-compose run -d my_service

Execute

docker-compose run -d my_service /bin/bash

Logs

docker-compose logs -f my_service

List

docker-compose ps

Remove

docker-compose rm -f my_service