Docker CLI
container
-
docker psshows all running container-
docker ps -ashows all existing container
-
-
docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]-
--name <container-name>gives the created container a custom name -
--rmremoves the container after stoping -
usually not desired-ddetached mode - stops the container after main process exits -
-itfor interactive processes - keep STDIN open (i), allocate a pseudo-tty (t)
-
-
typical example for testing:
docker run -it --rm --name test php:7.4 bash -
use bash in running container:
docker exec -it containerName bash
network
- list networks
docker network ls - add a network connection
docker network connect [OPTIONS] NETWORK CONTAINER
logs
docker logs --follow <container ID>
-
--followstreams logs until command is killed (^c) -
--until=3sstreams logs for 3 seconds -
--since 2019-03-02show logs since specific date
build dockerfile
docker build .
-
arguments
-
.build context (configs, mounts, ...) -
-f dockerfilespecifiy a custom dockerfile (independend from the build context) -
-t vendor/image-name:versionspecify a name (and a version) for the build image -
--no-cachebuild image without using caches -
--build-arg var_name=testset ARG
-
-
most used:
docker build -t draab/image-name:latest .
best practice
- use user flag:
--user $(id -u):$(id -g)to avoid problems on creating and accessing files