Libnetwork implements Container Network Model (CNM) which formalizes the steps required to provide networking for containers while providing an abstraction that can be used to support multiple network drivers.
Dockerfile - text file with instructions to build Docker images
each instruction results in an image layer
used in CI/CD to build the docker image artifact, pushed to Docker (remote or local) repositories
each image is based on another base image (FROM <image>)
Dockerfile
FROM<image># CommentINSTRUCTIONarguments# e.g.ENVSOME_ENV=value# run commands inside the containerRUNmkdir-p/home/appRUN...# copy files from host to containerCOPY./home/app# entrypoint commandCMD ["command","arguments"]
Image naming in Docker - registryDomain/imageName:tag
# e.g. DockerHubdockerpulldocker.io/library/ubuntu# default# same asdockerpullubuntu# e.g. Push image to private my-repo# Login to private my-repodockertag<my-repo/my-app:version>dockerpush<my-repo/my-app:version>
# Install Docker Engine via APT repositoryfor pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
sudoaptupdate-y&&sudoaptinstall-yca-certificatescurlgnupgsudosh-c' curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg sudo chmod a+r /usr/share/keyrings/docker.gpg echo "deb [arch="$(dpkg --print-architecture)" signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt update && sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
'sudosystemctlenabledocker--nowsudogpasswd-a"${USER}"docker# On Debian and Ubuntu, the Docker service starts on boot by default, if not runsudosystemctlenabledocker.servicesudosystemctlenablecontainerd.service# Reboot and Testrebootdockerrunhello-world
Commands
dockerpull<image># e.g.dockerpullpostgresdockerpullubuntudockerpullalpinedockerpullredis# without tag, the latest version is downloadeddockerrun<image># detached modedockerrun-d<image># use containersdockerstart<container_id>dockerstop<container_id>dockerimagesdockerps# list running and exited containersdockerps-a# e.g. with image:tagdockerrunredis:4.0# Map a free port on HOST machinedockerrun-p6000:6379-dredisdockerrun-p6001:6379-dredis:4.0# fetch logsdockerlogs<container_id>dockerlogs<container_id>-fdockerlogs<container_name># name a containerdockerrun-p6000:6379-d--nameredis-latestredis# new bash session in the containerdockerexec-it<container_id>/bin/bashdockerexec-it<container_id>/bin/sh