Docker Commands

Resources

Basic Commands

  • start a container: docker start kafka

  • follow log of a container: docker logs -f kafka

  • SSH into a Container: https://phase2.github.io/devtools/common-tasks/ssh-into-a-container/

    • docker exec -it zookeeper /bin/sh

  • docker image inspect mongo

  • docker run -d centos tail -f /dev/null ==> avoid the centos container to terminate

  • docker run --entrypoint "/bin/ls" debian -al /root ==> override entrypoint

  • docker run -it --entrypoint "/bin/bash" 16ae4fa4bfe5 -i ==> override entrypoint and keep container running

  • docker run --rm -p 8080:8080 base-image ==> run and image and automatically remove remove the container when it exits

Docker Compose Commands

Basic docker commands: https://phoenixnap.com/kb/how-to-list-start-stop-docker-containers

  • start all docker compose: docker-compose up -d --build

    • stop all docker compose: docker-compose stop

    • remove all docker compose: docker-compose rm -f

After starting docker composer you should be able to access Confluent Console at http://localhost:9021/clusters

Ho to build a docker file

From the directory of the Dockerfile run:

docker build [-t <tag name>] [--no-cache] .

Docker house keeping

Cleaning up containers

  • docker kill $(docker ps -q) ==> Kill all running docker container

  • docker rm $(docker ps -a -q) ==> delete all stopped docker containers

    Clean up images

  • docker rmi <image name> .

  • docker rmi $(docker images -q -f dangling=true) . ==> remove untagged (dangling) images (-q is the quite option (gives a list of container_ids only) and -f if the filter option)

  • docker rmi $(docker images -q) . ==> delete all images

    Cleaning up volumes

  • docker volumes rm $(docker volume ls -f dangling=true -q) ==> remove all the dangling volumes

Docker push

(resources: https://ropenscilabs.github.io/r-docker-tutorial/04-Dockerhub.html)

docker login --username=yourhubusername
docker images
docker tag bb38976d03cf [yourhubusername]/[repo_name]:[tag]
docker push [yourhubusername]/[repo_name]

Inspect

inspect ARG values after an image is built

docker history

inspect the default ENV variable values before the container is started:

$ docker images $ docker inspect <image-id>

Last updated