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 docker
-
sudo -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 login
-
Logging out of Docker
docker logout
-
Pulling an image named IMAGE from Docker Hub
docker pull IMAGE
-
List currently installed images
docker images
-
Start running a docker image IMAGE and execute the command
echo
docker run IMAGE echo 'hello'
-
See if any processes are running
docker ps
-
View all processes, whether active or finished
docker ps --all
-
Start 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/bash
-
Continue running the container named CONTAINER that you previously exited
docker start CONTAINER
-
Execute a command on a currently running docker container named CONTAINER
docker exec --interactive --tty CONTAINER '/bin/bash'
-
Stop a container named CONTAINER
docker stop CONTAINER
-
container_id='384bf99f07c8' docker container kill ${container_id}
-
List the currently running containers
# [ Short Form ] docker ps # [ Long Form ] docker container ls
-
List all containers
docker ps -a
-
Remove a container named CONTAINER (not the image that created it)
docker rm CONTAINER
-
Removing an image named IMAGE from the local machine
docker rmi IMAGE
-
Building 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.yaml
file
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