5.0 KiB
5.0 KiB
title | sidebar | showTitle | hideAnchor |
---|---|---|---|
Our Notes On Docker | Handbook | true | true |
Docker Nomenclature and Notes
Docker Image
- the actual package, artifact which can be shared with others, docker images are built in layers via DockerfileDocker Container
- a running instance of a docker image, file system is virtual, contains a port for communication- Docker run - command which executes pull and start (only pulls images we do not have locally)
- Docker vs Virtual Machine
- Operating System = Hardware > OS Kernel (layer 1) > Applications (layer 2)
- Docker = Virtualization of applications (layer 2)
- Virtual Image = Virtualization of OS (layer 1)
- Benefits of Docker = images are much smaller, runs faster
- Benefits of VM = you can run different OS (Windows on Linux) since it has it's own OS Kernel
- Docker Port vs Host Port
- Multiple containers may use the same port
- Bind host port to docker port, i.e. host 3000 -> docker 3000, host 3001 -> docker 3000
Docker Compose
- Configuration file specifying docker commands to make it easier to work with
- Automatically handles creating a common docker network
- Docker compose is usually installed with docker so you already have it
Docker Volumes
- Provides data persistence between host machine and docker containers
- The data between volumes is replicated between the host and docker container volumes
- 3 docker volume types: specified, anonymous, and named volumes, named volumes on the host are managed by docker
- Production should use named volumes
- Container Mongodb = /data/db
- Container MySQL = /var/lib/myself
- Container Postgres = /var/lib/postgres/data
- Host Windows = C:\ProgramData\docker\volumes
- Host Linux = /var/lib/docker/volumes/[hash]/_data
- Host Mac = /var/lib/docker/volumes/[hash]/_data
screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
add access linux VM on mac where data is stored,ctrl + a + k
to exit screen session
Basic commands
docker pull
downloads a docker image locallydocker images
shows a list of local docker images and their sizesdocker run
run a docker container, it's two commands in one docker pull and docker startdocker run -d
runs the docker container in detach modedocker run -p
binds the container to host port i.e. -p6000:6370, -p [host]:[container]docker run --name
give the container a name so that you do not need to use the SHAdocker run -d -it python
runs python images in interactive terminal modedocker run -e
runs an image with an environment variabledocker run -net
specify a docker network to run withindocker start
start a container, retains the settings from the run commanddocker stop
- stops a containerdocker ps
shows running containersdocker ps -a
shows running and not-running containersdocker logs
shows the standard output of the running containerdocker logs -f
follow the standard output, similar to tail -fdocker exec -it
runs the container with interactive terminaldocker network ls
shows a list of the internal docker networkdocker network create
create a docker networkdocker build -t my-app:1.0 .
builds an image from a Dockerfile in the current directorydocker rm
removes a docker container which you need to do before docker rmidocker rmi
removes a docker image, i.e. docker rmi my-app:1.0docker run -v
mounts host filesystem to docker container filesystem
Docker Compose
docker-compose -f mongo.yaml up
pulls, starts, and creates container networkdocker-compose -f mongo.yaml up -d
runs containers in detached modedocker-compose -f mongo.yaml down
stops container, removes container, and stops container network
First Dockerfile
FROM python:3.9-alpine3.13
RUN apk add bash nodejs
COPY hello.* /
CMD ["bash"]
First commands
docker build .
builds the containerdocker run --name [name] [sha]
installs the containerdocker run -it --name [name] [sha]
installs the container and starts in interactive modedocker ps
shows all the running containersdocker ps -a
shows all the running and exited containersdocker stop [name]
stop containerdocker start -ai [name]
start container interactivelydocker rm [name]
removes container
Resources
- Creating your first Dockerfile, image and container great place to start
- Docker Tutorial for Beginners [FULL COURSE in 3 Hours] most helpful
- Docker For Beginners: From Docker Desktop to Deployment
Related Resources
- Kubernetes Tutorial for Beginners FULL COURSE in 4 Hours To manage distribution of contains across many servers