Common docker commands on ubuntu based systems.
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)
Version:
$ 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 app.py
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 app.py. This launches our web application.
Show running conatiners:
$ docker ps
Run with port option:
$ docker run -d -p 80:5000 training/webapp python app.py
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
192.168.99.100
To install docker-machine:
$ sudo chown -R $(whoami) /usr/local/bin
$ curl -L https://github.com/docker/machine/releases/download/v0.7.0/docker-machine-`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
0.0.0.0:49155
Top command for the vm:
$ docker top nostalgic_morse
PID USER COMMAND
854 root python app.py
Inspect the vm:
$ docker inspect nostalgic_morse
[{
"ID": "bc533791f3f500b280a9626688bc79e342e3ea0d528efe3a86a51ecb28ea20",
"Created": "2014-05-26T05:52:40.808952951Z",
"Path": "python",
"Args": [
"app.py"
],
"Config": {
"Hostname": "bc533791f3f5",
"Domainname": "",
"User": "",
. . .
Start, stop, remove:
$ docker stop nostalgic_morse
$ docker start nostalgic_morse
$ docker rm nostalgic_morse
Process management: http://stackoverflow.com/a/33119321/1600523