Skip to main content

Docker CLI

container

  • docker ps shows all running container

    • docker ps -a shows all existing container
  • docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]

    • --name <container-name> gives the created container a custom name
    • --rm removes the container after stoping
    • -d detached mode - stops the container after main process exits usually not desired
    • -it for 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

best practice

  • use user flag: --user $(id -u):$(id -g) to avoid problems on creating and accessing files