Skip to content

Instantly share code, notes, and snippets.

@youngzhao-xyz
Last active February 7, 2019 18:46
Show Gist options
  • Save youngzhao-xyz/3fe1143e8377c8d2ffb862df828d0ca8 to your computer and use it in GitHub Desktop.
Save youngzhao-xyz/3fe1143e8377c8d2ffb862df828d0ca8 to your computer and use it in GitHub Desktop.
Docker

Steps to build an image and start a container from that image

# Build an image from a Dockerfile
> docker build -t <image_name> .

# List images
> docker images 
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<image_name>       latest             47da5935a6e9        11 minutes ago      910MB
...

# Run a command in a new container
> docker run <image_name>
# OR in interactive mode
> docker run -i -t <image_name> /bin/bash

You can use other ways to specify an image
<REPOSITORY> docker will automatically run image with 'latest' tag
<REPOSITORY>:<TAG>
<IMAGE ID>

Purging all Images, Containers, Volumes, and Networks

# clean up any resources — images, containers, volumes, and networks — that are dangling
> docker system prune

# To additionally remove any stopped containers and all unused images
> docker system prune -a

# delete container
> docker stop <container_id>
> docker rm <container_id>

# delete image
> docker rmi <image_id>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment