5.0 KiB
5.0 KiB
title, sidebar, showTitle, hideAnchor
| 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/ttyadd access linux VM on mac where data is stored,ctrl + a + kto exit screen session
Basic commands
docker pulldownloads a docker image locallydocker imagesshows a list of local docker images and their sizesdocker runrun a docker container, it's two commands in one docker pull and docker startdocker run -druns the docker container in detach modedocker run -pbinds the container to host port i.e. -p6000:6370, -p [host]:[container]docker run --namegive the container a name so that you do not need to use the SHAdocker run -d -it pythonruns python images in interactive terminal modedocker run -eruns an image with an environment variabledocker run -netspecify a docker network to run withindocker startstart a container, retains the settings from the run commanddocker stop- stops a containerdocker psshows running containersdocker ps -ashows running and not-running containersdocker logsshows the standard output of the running containerdocker logs -ffollow the standard output, similar to tail -fdocker exec -itruns the container with interactive terminaldocker network lsshows a list of the internal docker networkdocker network createcreate a docker networkdocker build -t my-app:1.0 .builds an image from a Dockerfile in the current directorydocker rmremoves a docker container which you need to do before docker rmidocker rmiremoves a docker image, i.e. docker rmi my-app:1.0docker run -vmounts host filesystem to docker container filesystem
Docker Compose
docker-compose -f mongo.yaml uppulls, starts, and creates container networkdocker-compose -f mongo.yaml up -druns containers in detached modedocker-compose -f mongo.yaml downstops 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 psshows all the running containersdocker ps -ashows 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