10/12/2016 - 1:09 PM

Common docker commands on ubuntu based systems.

Common docker commands on ubuntu based systems.

[Install by following instructions here](

If there is a warning like: Cannot connect to the Docker daemon. Is the docker daemon running on this host?

Just type:

$ sudo usermod -aG docker $(whoami)


$ docker version -- Show version

Create Image from DockerFile (. is the path to the DockerFile):

docker build -t mordorapi3 .

Delete Image (cd20 is image id):

 docker rmi cd20 -f

Show images

 docker images

Interactive run without start the container:

docker run -it mordorapi3 //bin//bash

Run as a daemon:

$ docker run -d -P training/webapp python
  • Review what the command did. You’ve specified two flags: -d and -P. You’ve already seen the -d flag which tells Docker to run the container in the background. The -P flag is new and tells Docker to map any required network ports inside our container to our host. This lets us view our web application.

  • You’ve specified an image: training/webapp. This image is a pre-built image you’ve created that contains a simple Python Flask web application.

  • Lastly, you’ve specified a command for our container to run: python This launches our web application.

Show running conatiners:

$ docker ps
  • with option -l : show the last container started
  • with option -a : show running and stopped containers.

Run with port option:

$ docker run -d -p 80:5000 training/webapp python

This would map port 5000 inside our container to port 80 on our local host.

To show the docker machine ip:

$ docker-machine ip my-docker-vm

To install docker-machine:

$ sudo chown -R $(whoami) /usr/local/bin
$ curl -L`uname -s`-`uname -m` > /usr/local/bin/docker-machine && \
chmod +x /usr/local/bin/docker-machine

To see what is the corresponding port on host:

$ docker port nostalgic_morse 5000

Top command for the vm:

$ docker top nostalgic_morse
PID                 USER                COMMAND
854                 root                python

Inspect the vm:

$ docker inspect nostalgic_morse
    "ID": "bc533791f3f500b280a9626688bc79e342e3ea0d528efe3a86a51ecb28ea20",
    "Created": "2014-05-26T05:52:40.808952951Z",
    "Path": "python",
    "Args": [
    "Config": {
       "Hostname": "bc533791f3f5",
       "Domainname": "",
       "User": "",
. . .

Start, stop, remove:

$ docker stop nostalgic_morse
$ docker start nostalgic_morse
$ docker rm nostalgic_morse

Process management: