Docker

Install & Configuration: https://docs.docker.com/engine/admin/configuring/

https://docs.docker.com/engine/tutorials/dockerizing/

Docker run a container
$ docker run ubuntu /bin/echo 'Hello world'
  • docker ps - Lists containers.
  • docker logs - Shows us the standard output of a container.
  • docker stop - Stops running containers.

By default, the docker ps command only shows information about running containers. If you want to see stopped containers too use the -a flag.

We can see the same details we saw when we first Dockerized a container with one important addition in the PORTS column.

PORTS 0.0.0.0:49155->5000/tcp 

When we passed the -P flag to the docker run command Docker mapped any ports exposed in our image to our host.

In this case Docker has exposed port 5000 (the default Python Flask port) on port 49155.
$ 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. 


$ docker port nostalgic_morse 5000 0.0.0.0:49155 

In this case you’ve looked up what port is mapped externally to port 5000 inside the container.

Viewing the web application’s logs

$ docker logs -f nostalgic_morse

* Running on http://0.0.0.0:5000/ 10.0.2.2 - - [23/May/2014 20:16:31] "GET / HTTP/1.1" 200 - 10.0.2.2 - - [23/May/2014 20:16:31] "GET /favicon.ico HTTP/1.1" 404 - 

This time though you’ve added a new flag, -f. This causes the docker logs command to act like the tail -f command and watch the container’s standard out. We can see here the logs from Flask showing the application running on port 5000 and the access log entries for it.
Looking at our web application container’s processes

$ docker top nostalgic_morse

PID USER COMMAND
854                 root                python app.py 


$ docker stop nostalgic_morse

nostalgic_morse

$ docker rm nostalgic_morse

nostalgic_morse 

Build your own images

Docker images are the basis of containers. Each time you’ve used docker run you told it which image you wanted. In the previous sections of the guide you used Docker images that already exist, for example the ubuntu image and the training/webapp image.

$ docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu 14.04 1d073211c498 3 days ago 187.9 MB
busybox             latest 2c5ac3f849df 5 days ago 1.113 MB
training/webapp     latest 54bb4e8718e8 5 months ago 348.7 MB 
		

So when you run a container you refer to a tagged image like so:

$ docker run -t -i ubuntu:14.04 /bin/bash 

If you don’t specify a variant, for example you just use ubuntu, then Docker will default to using the ubuntu:latest image.


请使用浏览器的分享功能分享到微信等