portfolio/app/writing/docker-cheat-sheet/page.mdx

50 lines
2.2 KiB
Plaintext
Raw Normal View History

2023-02-11 23:18:01 +00:00
import Image from 'next/image'
2023-07-29 22:40:36 +00:00
import {ArticleLayout} from '../../../components/layouts/ArticleLayout'
import {createSlug} from '../../../lib/createSlug'
2023-02-11 23:18:01 +00:00
import cargoShipImage from './ian-taylor-jOqJbvo1P9g-unsplash.jpg'
2023-07-29 22:40:36 +00:00
export const metadata = {
2023-02-11 23:18:01 +00:00
author: 'Ryan Freeman',
date: '2023-02-11',
title: 'Docker cheat sheet',
description: 'This is a living document of useful commands for maintaining and using Docker, and should function as a handy reference for developers and DevOps engineers.',
2023-07-29 22:40:36 +00:00
ogImage: '/images/ian-taylor-jOqJbvo1P9g-unsplash.jpg'
2023-02-11 23:18:01 +00:00
}
export default (props) => <ArticleLayout
2023-07-29 22:40:36 +00:00
author={metadata.author}
date={metadata.date}
title={metadata.title}
description={metadata.description}
ogImage={metadata.ogImage}
slug={createSlug(metadata.title)}
2023-02-11 23:18:01 +00:00
{...props} />
This is a living document of useful commands for maintaining and using Docker, and should function as a handy reference for developers and DevOps engineers.
<Image
src={cargoShipImage}
alt="Image of a cargo ship by Ian Taylor on Unsplash"
placeholder="blur"
priority
/>
2023-02-14 22:09:21 +00:00
I'll kick off this Docker cheat sheet with cleaning up Docker images, let's get started.
2023-02-11 23:18:01 +00:00
## Cleaning up Docker images
If you update your Docker container images regularly using something like [watchtower](https://containrrr.dev/watchtower/), you might have dangling images which are out-of-date and no longer associated with some of your running containers.
2023-02-17 23:20:49 +00:00
So why not use `docker image prune` to reclaim that valuable disk space. For example, running this command on my Raspberry Pi shaved off about 9.66Gb of disk usage.
2023-02-11 23:18:01 +00:00
2023-02-17 23:20:49 +00:00
As a bonus, you can save some additional space using `docker image prune --all`, which removes all unused Docker images.
2023-02-11 23:18:01 +00:00
## Restarting all containers
Sometimes you want to restart all your containers at once, such as after you've pulled the latest images for your containers.
2023-02-19 21:41:25 +00:00
To do this, use `docker restart $(docker ps -q)`, this command instructs Docker to restart all containers using the container ids which are returned from `docker ps -q`.
## Stopping all containers
Need to stop all containers? Simply use `docker stop $(docker ps -q)`. As above, this uses the container ids from `docker ps` to stop each running container.