Notes & TILs
Search…
Docker πŸ‹ quick guide
Posted on 18 Oct, 2020
  1. 1.
    Remove docker image.
    1
    docker rmi <img-id>
    Copied!
  2. 2.
    Remove docker container.
    1
    docker rm <container-id>
    Copied!
  3. 3.
    Build a docker image with a name.
    1
    docker build -f <dockerfile-path> -t name .
    Copied!
  4. 4.
    Run a container.
    1
    docker run -p 3000:3000 <container-id>
    Copied!
  5. 5.
    Stop a container.
    1
    docker stop <container-id>
    Copied!
  6. 6.
    Run a container in detach mode (run in background).
    1
    docker run -d <container-id>
    Copied!
    For the love of God always add a -d while running a container. Speaking this from experience.
    If you don't run in detach mode, you won't be able to Ctrl+C (or exit), instead use Ctrl+PC (yes the P key and C key).
  7. 7.
    List docker volumes.
    1
    docker volume ls
    Copied!
  8. 8.
    Remove docker volume.
    1
    docker volume rm <volume-name>
    Copied!
  9. 9.
    Check port mapping.
    1
    docker port <name>
    Copied!
  10. 10.
    Starting a docker container
    1
    docker start <container>
    Copied!
    The first two letters of CONTAINER_ID can be provided as an argument too.
  11. 11.
    Run a command inside container.
    1
    docker container exec <CONTAINER> ls -la
    Copied!
  12. 12.
    Check history of an image.
    1
    docker history <IMAGE>
    Copied!

Docker Compose

Tip: Alias docker-compose to an alias like dc to make your life better
  1. 1.
    Build and run containers.
    1
    docker-compose up --build
    Copied!
  2. 2.
    Start compose in detached mode
    1
    docker-compose up -d
    Copied!
  3. 3.
    Stop containers.
    1
    docker-compose stop
    Copied!
  4. 4.
    Check logs/console messages.
    1
    docker-compose logs <image name>
    2
    # or better use docker
    3
    docker logs -f <image name>
    Copied!
    To clear log output, use cmd + k, or ctrl + k
  5. 5.
    List all containers.
    1
    docker-compose ps
    Copied!
Last modified 1mo ago
Copy link