mirror of
https://gitea.com/mcereda/oam.git
synced 2026-02-09 05:44:23 +00:00
Improved docker notes
This commit is contained in:
@@ -3,11 +3,25 @@
|
||||
## TL;DR
|
||||
|
||||
```shell
|
||||
# Show locally available images.
|
||||
docker images -a
|
||||
|
||||
# Search for images.
|
||||
docker search boinc
|
||||
|
||||
# Pull images.
|
||||
docker pull alpine:3.14
|
||||
docker pull boinc/client:latest
|
||||
|
||||
# Login to registries.
|
||||
docker login
|
||||
|
||||
# Create containers.
|
||||
docker create -h alpine-test --name alpine-test alpine
|
||||
|
||||
# Start containers.
|
||||
docker start alpine-test
|
||||
docker start bdbe3f45
|
||||
|
||||
# Create and start containers.
|
||||
docker run hello-world
|
||||
@@ -18,17 +32,23 @@ docker run -d --name boinc --network=host --pid=host -v "boinc:/var/lib/boinc" \
|
||||
|
||||
# Gracefully stop containers.
|
||||
docker stop alpine-test
|
||||
docker stop bdbe3f45
|
||||
|
||||
# Kill containers.
|
||||
docker kill alpine-test
|
||||
|
||||
# Restart containers.
|
||||
docker restart alpine-test
|
||||
docker restart bdbe3f45
|
||||
|
||||
# Show containers' status.
|
||||
docker ps
|
||||
docker ps --all
|
||||
|
||||
# Execute commands inside *running* containers.
|
||||
docker exec app_web_1 tail logs/development.log
|
||||
docker exec -ti alpine-test sh
|
||||
|
||||
# Show containers' output.
|
||||
docker log alpine-test
|
||||
|
||||
@@ -38,9 +58,30 @@ docker top alpine-test
|
||||
# Show information on containers.
|
||||
docker inspect alpine-test
|
||||
|
||||
# Build a docker image.
|
||||
docker build -t private/alpine:3.14 .
|
||||
|
||||
# Tag images.
|
||||
docker tag alpine:3.14 private/alpine:3.14
|
||||
|
||||
# Push images.
|
||||
docker push private/alpine:3.14
|
||||
|
||||
# Export images to tarballs.
|
||||
docker save alpine:3.14 -o alpine.tar
|
||||
docker save hello-world > hw.tar
|
||||
|
||||
# Load images from tarballs.
|
||||
docker load -i hw.tar
|
||||
|
||||
# Delete containers.
|
||||
docker rm alpine-test
|
||||
docker rm -f 87b27
|
||||
|
||||
# Cleanup.
|
||||
docker rm -f alpine-test
|
||||
docker logout
|
||||
docker rmi alpine
|
||||
docker image prune -a
|
||||
docker system prune -a
|
||||
```
|
||||
|
||||
@@ -70,6 +111,40 @@ Docker mounts specific system files in all containers to forward its settings:
|
||||
|
||||
Those files come from the volume the docker container is using for its root, and are modified on the container's startup with the information from the CLI, the daemon itself and, when missing, the host.
|
||||
|
||||
## Gotchas
|
||||
|
||||
- Containers created with no specified name will be assigned one automatically:
|
||||
|
||||
```shell
|
||||
$ docker create hello-world
|
||||
8eaaae8c0c720ac220abac763ad4b477d807be4522d58e334337b1b74a14d0bd
|
||||
|
||||
$ docker create --name alpine alpine
|
||||
63b1a0a3e557094eba7f18424fd50d49b36cacbc21f1df60b918b375b857f809
|
||||
|
||||
$ docker ps -a
|
||||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||||
63b1a0a3e557 alpine "/bin/sh" 24 seconds ago Created alpine
|
||||
8eaaae8c0c72 hello-world "/hello" 21 seconds ago Created sleepy_brown
|
||||
```
|
||||
|
||||
- When referring to a container or image using their ID, you just need to use as many characters you need to uniquely specify a single one of them:
|
||||
|
||||
```shell
|
||||
$ docker ps -a
|
||||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||||
63b1a0a3e557 alpine "/bin/sh" 34 seconds ago Created alpine
|
||||
8eaaae8c0c72 hello-world "/hello" 31 seconds ago Created sleepy_brown
|
||||
|
||||
$ docker start 8
|
||||
8
|
||||
|
||||
$ docker ps -a
|
||||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||||
63b1a0a3e557 alpine "/bin/sh" 48 seconds ago Created alpine
|
||||
8eaaae8c0c72 hello-world "/hello" 45 seconds ago Exited (0) 10 seconds ago sleepy_brown
|
||||
```
|
||||
|
||||
## Sources
|
||||
|
||||
- [Archlinux Wiki]
|
||||
|
||||
Reference in New Issue
Block a user