Getting Started

brew cask install docker

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.

Logging in/out to Docker

docker login
docker logout

Pulling an image from Docker Hub

docker pull ubuntu

List currently installed images

docker images

Start running a docker image

docker run ubuntu echo 'hello'

Start running the container in interactive mode, establishing a connection to the container with a console

docker run -it ubuntu /bin/zsh

Start a docker container, specifying a name for the container

docker run --name example -it ubuntu /bin/bash

Continue running the container that you previously exited

docker start example

Execute a command on a currently running docker container

docker exec -it example '/bin/bash'

Stop a container

docker stop example

List the currently running containers

# [ Short Form ]
docker ps

# [ Long Form ]
docker container ls

List all containers

docker ps -a

Remove a container (not the image that created it)

docker rm example

Remove an image from docker

docker rmi ubuntu

Posted on: Feb 4, 2020
Last modified: Sep 16, 2020