Skip to content

Instantly share code, notes, and snippets.

@akochepasov
Last active February 26, 2025 18:37
Show Gist options
  • Save akochepasov/755764417b011b780d4cff43c7731c7c to your computer and use it in GitHub Desktop.
Save akochepasov/755764417b011b780d4cff43c7731c7c to your computer and use it in GitHub Desktop.
Docker commands

List docker containers running

docker ps docker container ls # same

Attach to a working container (Name555 is NAME)

docker exec -it Name555 bash

Create a docker image

docker build -t Tag123:v2 . # Uses local Dockerfile docker build -f Dockerfile22 -t Tag123:v2 .

Start the image as container

docker run Tag123:v2 --name ContName4 docker run -it -v /host/dir:/docker/dir2 Tag123:v4 /bin/sh docker run -it -v /host/dir:/docker/dir2:ro Tag446:v7 /bin/sh # Read-only mapping

Read last 50 lines and follow logs

docker logs -f -n 50 ContName4

Read and follow logs, dump into a file

docker logs -f -n50 ContName4 2>&1 | tee ContName4.log

See running containers

docker ps docker ps -a # Show all and dead ones

Copy from docker

docker cp ContName:/dir1/dir2 ~/src/ docker cp /src/scripts ContName:/dir1/dir2/

Export FS

docker export -o postmortem.tar Name555

See container spec

docker inspect ContName4 docker inspect 590ba28c2ec3 | grep LogPath

Download the image from the storage

docker image pull python:3.11-slim-bookworm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment