Docker - jasper-zanjani/dotfiles GitHub Wiki
Docker repositories are associated with a single image, various versions of which can be specified with a tag.
Docker Desktop is Docker's runtime for Windows which Docker integrates with WSL 2 since June 2019. Docker traditionally distributed its own Linux kernel to use with Docker Desktop.
attachπ buildπ builderπ checkpointπ commitπ configπ containerπ contextπ cpπ createπ diffπ eventsπ execπ exportπ historyπ imageπ imagesπ importπ infoπ inspectπ killπ loadπ loginπ logoutπ logsπ manifestπ networkπ nodeπ pauseπ pluginπ portπ psπ pullπ pushπ renameπ restartπ rmπ rmiπ runπ saveπ searchπ secretπ serviceπ stackπ startπ statsπ stopπ swarmπ systemπ tagπ topπ trustπ unpauseπ updateπ versionπ volumeπ waitπ
Connect to a session on a running container Zacker: 279
docker attach $CONTIDBuild a Docker image from a Dockerfile in the present working directory PluralSight
docker build -t web .Save changes made to a modified container to a new image Zacker: 279
docker commit $CONTID $USER/$CONTup
down
-d
-v
- separate binary coded in Python, available through
pip - can be used from the CLI as well as from YAML files ("compose file")
- can be used as a replacement for the normal
dockerCLI - intended for use in developer workflows to avoid shell scripts that would typically be used to facilitate long command-line
dockerinvocations - not intended for production, for which Docker Swarm is preferable
- v2 is focused on development or testing with a single node
- v3 is focused on multi-node orchestration features
Simple Docker compose file
version: '2.0'
services:
web:
image: sample-01
build: .
ports:
- '3000:3000'docker-compose up -dBring everything down
docker-compose down -vCreate docker image named "hello" with tag "v0.1" from contents of current directory
docker image build -t hello:v0.1 . |
connect create disconnect inspect ls prune rm
Container networks can use various drivers, which are associated with specific key-value pairs in daemon.json:
-
NAT: containers reside in their own network and the host acts as gateway and set with
{ "fixed-cidr" : "10.0.0.0/24" }. -
Transparent: containers are assigned IP addresses on the same physical network to which the host belongs (similar to External virtual switches in Hyper-V), set with
{ "bridge": "none" }.
Create a new network using the transparent driver Zacker: 285
docker network create -d transparent $NETWORKNAMECreate a transparent network with static IP addresses
docker network create -d transparent --subnet=10.0.0.0/24 --gateway=10.0.0.1 $NETWORKDisplay a list of all running containers Zacker: 278
docker ps -aRemove a container completely (must be stopped, unless -f is used) Zacker: 279
docker rm $CONTIDCan be used to remove extraneous tags
d i m p t v
cpu-percent
network
volumes-from
Create a Hyper-V container Zacker: 275
docker run -it --isolation=hyperv microsoft/windowsservercore powershellBind port 80 of the container to port 8080 of the host Zacker: 284
docker run -it -p 8080:80 microsoft/windowsservercore powershellCreate a container with a static IP address on the network you created
docker run -it --network=$NETWORK --ip=10.0.0.16 --dns=10.0.0.10 microsoft/windowsservercore powershellTo detach from a running container use the keyboard shortcuts CtrlPCtrlQ
Start a stopped container Zacker: 278
docker start $CONTIDStop a container Zacker: 278
docker stop $CONTIDdocker tag can be used to rename images and to prepare them to be pushed to a repository.
Tag an image on local container host Zacker: 272
docker tag $USERNAME/$IMAGENAME:$TAGDocker has several options for containers to store files in a persistent manner:
- Volumes are stored in a part of the host filesystem which is managed by Docker (/var/lib/docker/volumes/ on Docker).
- Bind mounts may be stored anywhere on the host system and are specified by docker run --volume.
-
tmpfsmounts are stored in the host system's memory only, and are available only on Linux.
Display data volumes PluralSight
docker volume lsA Docker image consists of read-only layers, each of which represents an instruction that incrementally the changes the image being built up.
Using docker build, Dockerfiles can be used to construct new images.
The build process can be optimized by placing multiple commands in the same RUN instruction.
Dockerfiles are named simply "Dockerfile" with no extension or variation.
FROM alpine
RUN apk update && apk add nodejs
COPY . /app
WORKDIR /app
CMD ["node","index.js"]Zacker: 289
FROM microsoft/windowsservercore
RUN powershell -command install-windowsfeature dhcp -includemanagementtools
RUN powershell -configurationname microsoft.powershell -command add-dhcpserverv4scope -state active -activatepolicies $true -name scopetest -startrange 10.0.0.100 -endrange 10.0.0.200 -subnetmask 255.255.255.0
RUN md boot
COPY ./bootfile.wim c:/boot/
CMD powershellFROM microsoft/windowsservercore
MAINTAINER @mike_pfeiffer
RUN powershell.exe -Command Install-WindowsFeature Web-Server
COPY ./websrc c:/inetpub/wwwroot
CMD [ "powershell" ]