latentspace.

docker CLI Cheat Sheet


  • docker CLI cheat sheet

  • Docker Command Description
    docker build -t <image_name> Build an image from a Dockerfile
    docker images List local images
    docker rmi <image_name> Delete an image
    docker image prune Remove all unused images
    docker run --name <container_name> <image_name> Create and run a container from an image, with a custom name
    docker start|stop <container_name> (or <container_id>) Start or stop an existing container
    docker rm <container_name> Remove a stopped container
    docker exec -it <container_name> sh Open a shell inside a running container
    docker logs -f <container_name> Fetch and follow the logs of a container
    docker ps List currently running containers
    docker ps --all List all docker containers (running and stopped)
    docker stats View resource usage stats
    docker login -u <username> Log in to Docker Hub
    docker push <username>/<image_name> Publish an image to Docker Hub
    docker pull <image_name> Pull an image from a Docker Hub

  • docker run parameters
    • 
          docker run \
              --memory <MEMORY e.g. 4g> \                   # RAM size to allocate
              --cpus <CPU e.g. 2> \                         # Number of CPUs to allocate
              --gpus <GPU e.g. all > \                      # GPU access (e.g., all available GPUs) --gpus device=0,1 ...
              --shm-size <SHM e.g. 2g> \                    # Shared memory size
              --name <NAME e.g. my-container> \             # Custom name for the container
              -p <HOST_PORT:CONTAINER_PORT e.g. 8080:80> \  # Port mapping (host:container)
              <IMAGE e.g. my-image:latest> \                # Image name and tag
              <SHELL e.g. bash>                             # Command to run inside the container