Docker
Containerization has been around for awhile. Docker helped make it easy to use. My collection of things for Docker are stored here for reference in the future.
Formatting
Using docker ps --format '{{.ID}}'
will output all the IDs of the output from the ps
command. Other fields available are:
.ID
.Image
.Command
.CreatedAt
.RunningFor
.Ports
.Status
.Size
.Names
.Labels
.Label
.Mounts
.Networks
Stop or/and Removing
To stop containers allows for halting a running container. If you did not use the --rm
command, it still remains in the list of containers under management by Docker. To see this list, you need to use the docker ps -a
command.
Thus to stop and remove a docker container, you really have two options:
- start the container with
--rm
to remove the container automatically - use a script to stop and remove the container in one go
Here is the simple script I use to stop and remove containers in one go:
for id in $(docker ps --format '{{.ID}}')
do
docker stop $id
docker rm $id
done
docker-compose.yml
plain simple template
https://docs.docker.com/compose/compose-file/compose-file-v3/
version: "3.9"
services:
webapp:
build:
context: ./dir
dockerfile: Dockerfile-alternate
args:
buildno: 1
labels:
- "com.example.description=Accounting webapp"
- "com.example.department=Finance"
- "com.example.label-with-empty-value"
depends_on:
- db
- redis
redis:
image: redis
db:
image: postgres