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 worksdocker info
- extended infoold:
docker <command> (options)
new:
docker <command> <sub-command> (options)
docker container --help
get full help for commanddocker container ls
- list running containersdocker 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 namedocker container logs $CONTAINER_ID
- get logs for containerdocker container rm $CONTAINER_ID
- remove the container entirely. Use multipe args to remove multiple containersrm 0e3 49f d94 …
docker container rm -f $CONTAINER_ID
- force rmdocker container top $CONTAINER_ID
- run a basictop
in the containerdocker start $CONTAINER_ID
- restart a stopped container—detach
or-d
to run a container in the background—publish
or-p
to open portsIf you do not add
-—publish
it will not forward portsdocker container inspect mysql
- outputs JSON describing how container was starteddocker 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 containerdocker container exec -it mysql bash
- exec bash in the mysql container (that’s already running)docker pull alpine
- pull images downdocker container run -it alpine bash
- alpine doesn’t have bash, errordocker container run -it alpine sh
- but sh isdocker container port $NAME
- show port mappingsdocker 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 foregroundBACKGROUND:
docker run --publish 80:80 —detach nginx
- in the backgrounddocker 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