Docker
Docker is a really cool technology. If you need a video tutorial to jump in and get started, Peter McKee, a senior software engineer at Docker made a great video to help you get started with Docker. To learn more, watch Michael Irwin's talk at DockerCon 2019, "Containers for Beginners" the first installment of Docker's "Docker 101" series on YouTube.
Liz Rice's talk on creating Docker containers from scratch
Getting Started
Installing Docker on macOS
brew cask install dockersudo -i curl -fsSL https://get.docker.com | bash -Optionally, add the docker completion script for zsh
Open the application in the menu bar to have Docker run its initial configurations, and then log in to the docker hub. From here, you're all set up and can proceed to use Docker from the command line.
Command Line Operations
Logging into Docker
docker loginLogging out of Docker
docker logoutPulling an image named IMAGE from Docker Hub
docker pull IMAGEList currently installed images
docker imagesStart running a docker image IMAGE and execute the command
echodocker run IMAGE echo 'hello'
See if any processes are running
docker psView all processes, whether active or finished
docker ps --allStart a docker container named CONTAINER based on the image named IMAGE, specifying a name for the container
docker run \ --name CONTAINER \ --interactive \ --tty IMAGE \ /bin/bashContinue running the container named CONTAINER that you previously exited
docker start CONTAINERExecute a command on a currently running docker container named CONTAINER
docker exec --interactive --tty CONTAINER '/bin/bash'Stop a container named CONTAINER
docker stop CONTAINERcontainer_id='384bf99f07c8' docker container kill ${container_id}List the currently running containers
# [ Short Form ] docker ps # [ Long Form ] docker container lsList all containers
docker ps -aRemove a container named CONTAINER (not the image that created it)
docker rm CONTAINERRemoving an image named IMAGE from the local machine
docker rmi IMAGEBuilding an image named IMAGE from a Dockerfile
docker build . \ --tag 'USERNAME/IMAGE' \ --squash
Publication
Publishing an image named IMAGE to the Docker Hub container registry
docker publish USERNAME/IMAGE
A few additional steps are required to publishing a container to GitHub's container registry.
SSH Connections
- As represented in a
compose.yamlfile
version: '3'
services:
my_service_name:
build: .
environment:
- SSH_AUTH_SOCK="${SSH_AUTH_SOCK}"
volumes:
- ${SSH_AUTH_SOCK}:${SSH_AUTH_SOCK}
- As a call to
docker
docker run \
--rm \
--tty \
--interactive \
-v ${SSH_AUTH_SOCK}:${SSH_AUTH_SOCK} \
--env SSH_AUTH_SOCK=${SSH_AUTH_SOCK} \
CONTAINER_TAG
Docker Run
Run Ubuntu on M1 Mac emulating the
x86_64architecturedocker run --platform 'linux/x86_64' -it 'ubuntu:latest'
Podman
Me: "Mom, can we get Docker containers?" open-source
Mom: "No honey, we already have containers at home."
*containers at home*:

Setting up AWS Elastic Container Registry
Stole this from a question on Stack Overflow
Getting the AWS account & region:
AWS_PROFILE='default'
AWS_ACCOUNT=$(
aws sts get-caller-identity \
--query 'Account' \
--output 'text'
)
AWS_REGION=$(aws configure get region)
Authenticating to Amazon Elastic Container Registry (ECR):
aws \
--region AWS_REGION \
ecr get-login-password \
| podman login \
--password-stdin \
--username 'AWS' \
AWS_ACCOUNT.dkr.ecr.AWS_REGION.amazonaws.com
Creating a Podman machine:
podman machine init --cpus=0 --memory=4096 --now
Starting a Podman machine:
podman machine init
podman machine start
Stopping a Podman machine:
podman machine stop
Removing a Podman machine:
podman machine rm
Adding the AWS CLI to a Docker image
The hard part about it is getting it to be architecture agnostic, so that it works regardless of whether you are running on an x86_64 or arm64 architecture.
FROM public.ecr.aws/docker/library/python:3.10
RUN \
curl "https://awscli.amazonaws.com/awscli-exe-linux-$(arch).zip" -o "awscliv2.zip" \
&& unzip awscliv2.zip \
&& ./aws/install --install-dir /opt/awscli --bin-dir /usr/local/bin \
&& rm -rf awscliv2.zip
ENTRYPOINT ["/bin/bash"]
You can build this image for multiple architectures, and push it to a remote registry, all in a single step:
docker buildx build \
--platform='linux/amd64,linux/arm64' \
--tag 'USERNAME/IMAGE' \
--file='Dockerfile' \
--push .