Getting Started

Basic Commands

Info command

This command gives information about the docker setup on your machine/vm

$ docker info

Output of the command will look similar to the listing below

Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 1.12.2
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 0
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge null host overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options: apparmor seccomp
Kernel Version: 4.4.0-42-generic
Operating System: Ubuntu 16.04.1 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 992.3 MiB
Name: ubuntu-xenial
ID: ENYQ:LFJK:3PPI:BMPQ:HAOE:GVQS:WASE:OVXR:O4KZ:HEPX:KHSM:7X7K
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: No swap limit support
Insecure Registries:
 127.0.0.0/8

Create a Container and enter its shell

$ sudo docker run -i -t debian /bin/bash

This should give you a new command prompt inside the container, very similar to if you had ssh‘ed into a remote machine. In this case the flags -i and -t tell Docker we want an interactive session with a tty attached. The command /bin/bash gives a bash shell. When you exit the shell the container will stop — containers only run as long as their main process

$ docker run debian echo hello-world
hello-world

Create a container with a name

You can use -h command line parameter to specify a container name.

$ docker run -h CONTAINER1 -i -t debian /bin/bash

Output of the command above will open a tty inside the container

root@CONTAINER1:/#

Create a container with a Networking mode

Container mode can be specified using the flag :code:`-net=<NETWORK_MODE> where

$ docker run -h CONTAINER2 -i -t --net="bridge" debian /bin/bash

List of docker containers running

$ docker ps -a

Inspect a Container

$ docker inspect CONTAINER_NAME

Output will be a JSON file.

Start a Stopped Container

$ docker start [CONTAINER_NAME]

where [CONTAINER_NAME] is the container name.

Enter the Shell of a Started Container

$ docker attach CONTAINER_NAME

where CONTAINER_NAME is the container name.

Delete a Container

docker rm CONTAINER_NAME

Detach from a Container

docker run -t -i → can be detached with ^P^Q and reattached with docker attach
docker run -i    → cannot be detached with ^P^Q; will disrupt stdin
docker run       → cannot be detached with ^P^Q;
                   can SIGKILL client; can reattach with docker attach

Docker Logs

If you run this command with the name of your container, you should get a list of commands executed in the container.

$ docker logs CONTAINER_NAME

where hopeful_pare is the container name.

Pause a Container

$ docker pause CONTAINER_NAME

Note : Container needs to be in the Started Phase

UnPaise a Paused Container

$ docker unpause CONTAINER_NAME

Removing all the Containers

$ docker rm `docker ps --no-trunc -aq`

List Docker Networks

$ docker network ls

Output will be similar to listing below

NETWORK ID          NAME                DRIVER              SCOPE
5f6a5825b13d        bridge              bridge              local
79d049082795        host                host                local
afe5e4412073        none                null                local

Rename a Docker Container

$ docker rename big_hamilton big_hamilton_v1