
Docker
Description
This article gives common docker command syntax examples on a Mac with Docker Toolbox (VirtualBox) installed.
Prerequisites
- Docker Toolbox for Mac Installed
- Open Docker CLI
Images
List Images
1 |
docker images |
1 2 3 4 5 |
REPOSITORY TAG IMAGE ID CREATED SIZE <none> <none> 88c75ebcd6e9 9 hours ago 291.6 MB <none> <none> 44e83afd49db 11 hours ago 291.6 MB centos centos7 40dae1fe8777 9 days ago 196.7 MB kitematic/hello-world-nginx latest 04b455fad7b9 13 months ago 7.913 MB |
Import Tarball to Create Image
1 |
docker import </path/to/tar | URL> <name> |
Export Image to Tarball
1 |
docker export -o </path/to/file.tar> <container name> |
Remove Image
1 |
docker rmi <image name> |
Containers
List Containers
List running containers
1 |
docker ps |
1 2 |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5c1f53e43598 88c75ebcd6e9 "/usr/sbin/sshd -D -o" 4 minutes ago Up 4 minutes 0.0.0.0:32770->22/tcp kitchen-base-centos72 |
List All Containers
List running and stopped containers
1 |
docker ps -a |
List Lastest Container
List latest created container
1 |
docker ps -l |
Create Container from Docker Hub Image
Create a new container from a Docker Hub Image.
1 |
docker create <imagename> --name <name to give container> |
Run Command on a Container
1 |
docker exec [OPTIONS] <container name> <command> [ARGS] |
Login to a Container
1 |
docker exec -i -t <container name> /bin/bash |
Copy Files to a Container
Copy files from local system to a container.
1 |
docker cp [OPTIONS] <container name>:<source path> <destination path> |
Fetch Logs of a Container
1 |
docker logs <container name> |
Start, Stop, Restart and Kill a Container
1 |
docker start <name> |
1 |
docker stop <name> |
1 |
docker restart <name> |
1 |
docker kill <name> |
Remove a Container
1 |
docker rm <name> |
Server
List Current Docker Server Information
List information about the Docker Server that is currently configured in the Shell with environment variables.
1 |
docker info |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 34 Server Version: 1.12.0 Storage Driver: aufs Root Dir: /mnt/sda1/var/lib/docker/aufs Backing Filesystem: extfs Dirs: 45 Dirperm1 Supported: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: host bridge null overlay Kernel Version: 4.4.16-boot2docker Operating System: Boot2Docker 1.12.0 (TCL 7.2); HEAD : e030bab - Fri Jul 29 00:29:14 UTC 2016 OSType: linux Architecture: x86_64 CPUs: 1 Total Memory: 1.955 GiB Name: default ID: HBGP:2HDA:CVJV:XZ3E:WPOF:7SI4:EBVP:EVQN:BMCV:WETL:LS3E:UNB5 Docker Root Dir: /mnt/sda1/var/lib/docker Debug mode (client): false Debug mode (server): true File Descriptors: 13 Goroutines: 24 System Time: 2016-07-29T15:07:54.676584538Z EventsListeners: 0 Registry: https://index.docker.io/v1/ Labels: provider=virtualbox |
List Docker Servers
List all Docker Servers that the containers are spun up on.
1 |
docker-machine ls |
1 2 |
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS default * virtualbox Running tcp://192.168.99.100:2376 v1.12.0 |
Start, Stop & Restart a Docker Server
1 |
docker-machine start <name> |
1 |
docker-machine stop <name> |
1 |
docker-machine restart <name> |
List Docker Server Environment
List a Docker Server environment.
1 |
docker-machine env <docker machine name> |
Switch Default Docker Server in Shell
To switch the environment variables to point to another Docker Server (machine) temporarily in a shell we can use the eval command and Docker machine name.
1 |
eval $(docker-machine env <docker machine name>) |
Upgrade Docker Server
Upgrade a Docker Server to the latest Docker version.
1 |
docker-machine upgrade <name> |
Upgrade Docker Server
Upgrade a Docker Server to the latest Docker version.
1 |
docker-machine upgrade <name> |