发布于 2015-09-10 16:22:58 | 446 次阅读 | 评论: 0 | 来源: 网络整理
This guide assumes you have a working installation of Docker. To check your Docker install, run the following command:
# Check that you have a working install docker info
If you get docker: command not found or something like /var/lib/docker/repositories: permission denied you may have an incomplete Docker installation or insufficient privileges to access docker on your machine.
Please refer to 安装 for installation instructions.
注解
This is the most basic example available for using Docker.
Download the base image which is named ubuntu:
# Download an ubuntu image sudo docker pull ubuntu
Alternatively to the ubuntu image, you can select busybox, a bare minimal Linux system. The images are retrieved from the Docker repository.
sudo docker run ubuntu /bin/echo hello world
This command will run a simple echo command, that will echo hello world back to the console over standard out.
Explanation:
Video:
See the example in action
注解
And now for the most boring daemon ever written!
We will use the Ubuntu image to run a simple hello world daemon that will just print hello world to standard out every second. It will continue to do this until we stop it.
Steps:
CONTAINER_ID=$(sudo docker run -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done")
We are going to run a simple hello world daemon in a new container made from the ubuntu image.
sudo docker logs $CONTAINER_ID
Check the logs make sure it is working correctly.
sudo docker attach -sig-proxy=false $CONTAINER_ID
Attach to the container to see the results in real-time.
Exit from the container attachment by pressing Control-C.
sudo docker ps
Check the process list to make sure it is running.
sudo docker stop $CONTAINER_ID
Stop the container, since we don’t need it anymore.
sudo docker ps
Make sure it is really stopped.
Video:
See the example in action
The next example in the series is a Python Web应用 example, or you could skip to any of the other examples: