Basic commands
目錄
Usage: [sudo] docker [command] [flags] [arguments] ..
Get information
The version of docker:
1 | example> docker version |
Show the information about docker status:
1 | example> docker info |
Basic operations
Download image file provided from Docker Hub:
1 | docker pull <image-name> |
Run specified cmd on this image:
1 | docker run <image-name> <cmd> |
Flags:
-t
flag assigns a terminal inside our new container.
-i
flag allows us to make an interactive connection by grabbing the standard in (STDIN
) of the container.
-d
flag tells Docker to run the container and put it in the background, to daemonize it.
-p
flag is new and tells Docker to map any required network ports inside our container to our host.
-P
flag, a shortcut for-p
, maps any required network ports exposed in our image to a high port (from the range 49153 to 65535) on the local Docker host.
-v
flag mount the host directory into container directory, ex-v <host-dir>:<container-dir>
or-v <container-dir>
--name
flag assigns a name to this container
<image-name>
: ubuntu:14.04
<cmd>
: /bin/echo “hello world”
View info of container:
1 | docker inspect <container-id-or-name> |
Lists containers:
1 | example> # To check which docker is running |
Stops running containers:
1 | docker stop <container-id-or-name> |
Commit a modified image:
1 | docker commit <container-id-or-name> <image-name> |
Flags:
-m
flag is used to give a comment to this commit.
-a
flag declare the maintainer’s name.
Remove the image:
1 | docker rmi <image-id> |
Login Docker Hub (before you push a image to repository):
1 | example> docker login |
Push image to the repository (usually on Docker Hub):
1 | docker push <image-name> |
Shows us the standard output of a container:
1 | docker logs |
Some advanced applications
Query the port mapping of a container:
1 | docker port <container-id-or-name> <port-exposed> |
Running a web application in docker:
1 | example> # we're going to run a Python Flask application with image: training/webapp |
Assign command to specific docker:
1 | example> # Return to docker again after exit |
To remove docker that you don’t need anymore:
1 | example> docker rm 0f83f1728262 |
To mount a host directory as a disk in docker:
1 | example> # Mount /myData into docker |