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
Start running a docker image
docker run ubuntu echo 'hello'
Warning: Every time you use the
run command it creates a new container, so if you type
run ubuntu three times you will have three
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
Tip: You can also specify the first 2 characters of its container ID if the name associated with the docker container is too verbose to type out in its entirety. You can’t, however, type just part of the containers name. This shortcut only applies to the container ID.