Skip to content

Instantly share code, notes, and snippets.

@ctufts
Last active July 13, 2021 18:41
Show Gist options
  • Save ctufts/0facd12e5c4ef91d8de205985c4b3b50 to your computer and use it in GitHub Desktop.
Save ctufts/0facd12e5c4ef91d8de205985c4b3b50 to your computer and use it in GitHub Desktop.
Notes on docker

Docker notes:

General

Images - Stopped containers Containers - running containers

Commands

  • docker version
    • client (local machine)
    • server (docker)
  • docker info
    • additional info (more than version)
    • system info, number of containers, status of containers, etc.
  • docker ps
    • list currently running containers
  • docker ps -a
    • see recently run containers, but are now done
  • docker run <name of image>
    • run image (checks local first, then checks docker hub if not found local)
  • docker images
    • all images on local machine
  • docker pull <name>:<version>
    • pulls docker image off of docker hub (version optional)
  • docker rmi <name>:<tag>
    • remove image
    • you can get the name and tag from 'docker images' command
  • docker run -d --name web <image name to use>
    • -d start container in detached mode
    • --name : a name for the container
    • -p 80:8080 (web server) - map port 80 on host to port 8080 inside the container
    • - docker hub image or local image name
  • docker stop <name>
    • stops a container from running
  • docker start<name>
    • restart container
  • docker run -it --name <name> ubuntu:lastest /bin/bash
    • -it don't run in background, open in this terminal
  • docker build <context>
    • builds and image from a Dockerfile and a context
    • context can be a directory (possibly somethings else?)
    • -f flag to point to a directory in the file system containing the dockerfile
    • -t to save the built image (specifies the directory to save it to)
      • can specify multiple locations to copy it to
  • docker rmi $(docker images -f “dangling=true” -q)
    • Remove all <none> images
  • docker container prune
    • Remove all exited containers

Dockerfile Syntax/Format

General


# comment INSTRUCTION arguments

  • must start with a FROM instruction
    • specifies the base image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment