Docker

Learning, please wait....

Docker

docs.docker.com

https://dominikbraun.io/blog/docker/dockerfile-run-vs-cmd-vs-entrypoint/

Terms

  • image - the application we want to run

  • container - an instance of that image running as a process

  • registry - image registry, hub.docker.com by default

Basic

  • docker version - get version, make sure it works

  • docker info - extended info

  • old: docker <command> (options)

  • new: docker <command> <sub-command> (options)

  • docker container --help get full help for command

  • docker container ls - list running containers

  • docker container ls -a - list containers (even stopped)

  • docker container stop $CONTAINER_ID - stop a running container, can use the first few chars of the container ID or the container name

  • docker container logs $CONTAINER_ID - get logs for container

  • docker container rm $CONTAINER_ID - remove the container entirely. Use multipe args to remove multiple containers rm 0e3 49f d94 …

  • docker container rm -f $CONTAINER_ID - force rm

  • docker container top $CONTAINER_ID - run a basic top in the container

  • docker start $CONTAINER_ID - restart a stopped container

  • —detach or -d to run a container in the background

  • —publish or -p to open ports

  • If you do not add -—publish it will not forward ports

  • docker container inspect mysql - outputs JSON describing how container was started

  • docker container stats - display CPU/MEM/NET info for all containers (can specify container name)

  • docker container run -it --name ubuntu ubuntu - run with -it = interactive shell with TTY (takes you straight to the container’s shell)

  • docker container start -ai ubuntu - ???

  • docker container exec - exec some thing in the container

  • docker container exec -it mysql bash - exec bash in the mysql container (that’s already running)

  • docker pull alpine - pull images down

  • docker container run -it alpine bash - alpine doesn’t have bash, error

  • docker container run -it alpine sh - but sh is

  • docker container port $NAME - show port mappings

  • docker container inspect --format "{{ .NetworkSettings.IPAddress }}" webhost - use —format with some funk to get inspect properties

Getting into local Docker VM on Mac

Docker for Mac Commands for Getting Into The Local Docker VM docker run -it —rm —privileged —pid=host justincormack/nsenter1

TODO: ALIAS THIS!

nginx web server

  • docker run --publish 80:80 nginx - start an nginx container in the foreground

  • BACKGROUND: docker run --publish 80:80 —detach nginx - in the background

  • docker container run --publish 80:80 --detach --name webhost nginx - assign a custom name instead of random name

MySql

~ ❯❯❯ docker container run --publish 3306:3306 -d -e MYSQL_RANDOM_ROOT_PASSWORD=yes mysql docker container logs $CONTAINER_ID to get root password

Last updated