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πŸ”—

attach

Connect to a session on a running container Zacker: 279

docker attach $CONTID

build

                                        t            

Build a Docker image from a Dockerfile in the present working directory PluralSight

docker build -t web .

commit

Save changes made to a modified container to a new image Zacker: 279

docker commit $CONTID $USER/$CONT

compose

up 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 docker CLI
  • intended for use in developer workflows to avoid shell scripts that would typically be used to facilitate long command-line docker invocations
  • 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 -d

Bring everything down

docker-compose down -v

container

commit diff ls

image

build tag

Create docker image named "hello" with tag "v0.1" from contents of current directory

docker image build -t hello:v0.1 . | 

network

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 $NETWORKNAME

Create a transparent network with static IP addresses

docker network create -d transparent --subnet=10.0.0.0/24 --gateway=10.0.0.1 $NETWORK

ps

Display a list of all running containers Zacker: 278

docker ps -a

rm

Remove a container completely (must be stopped, unless -f is used) Zacker: 279

docker rm $CONTID

rmi

Can be used to remove extraneous tags

run

        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 powershell

Bind port 80 of the container to port 8080 of the host Zacker: 284

docker run -it -p 8080:80 microsoft/windowsservercore powershell

Create 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 powershell

To detach from a running container use the keyboard shortcuts CtrlPCtrlQ

start

Start a stopped container Zacker: 278

docker start $CONTID

stop

Stop a container Zacker: 278

docker stop $CONTID

tag

docker 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:$TAG

volume

Docker 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.
  • tmpfs mounts are stored in the host system's memory only, and are available only on Linux.

Display data volumes PluralSight

docker volume ls

Dockerfile

A 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 powershell

PluralSight

FROM microsoft/windowsservercore
MAINTAINER @mike_pfeiffer
RUN powershell.exe -Command Install-WindowsFeature Web-Server
COPY ./websrc c:/inetpub/wwwroot
CMD [ "powershell" ]
⚠️ **GitHub.com Fallback** ⚠️