Skip to content

Commit 7697fd0

Browse files
authored
Merge branch 'master' into patch-1
2 parents e63df17 + 8070973 commit 7697fd0

File tree

2 files changed

+331
-232
lines changed

2 files changed

+331
-232
lines changed

README.md

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The 3.10.x kernel is [the minimum requirement](https://docs.docker.com/engine/in
3939

4040
### MacOS
4141

42-
10.8 “Mountain Lion” or newer is required.
42+
10.8 “Mountain Lion” or newer is required.
4343

4444
## Installation
4545

@@ -56,9 +56,10 @@ If you're not willing to run a random shell script, please see the [installation
5656
If you are a complete Docker newbie, you should follow the [series of tutorials](https://docs.docker.com/engine/getstarted/) now.
5757

5858
### macOS
59+
5960
Download and install [Docker Community Edition](https://www.docker.com/community-edition). if you have Homebrew-Cask, just type `brew cask install docker`. Or Download and install [Docker Toolbox](https://docs.docker.com/toolbox/overview/). [Docker For Mac](https://docs.docker.com/docker-for-mac/) is nice, but it's not quite as finished as the VirtualBox install. [See the comparison](https://docs.docker.com/docker-for-mac/docker-toolbox/).
6061

61-
> **NOTE** Docker Toolbox is legacy. you should to use Docker Community Edition, See (Docker Toolbox)[https://docs.docker.com/toolbox/overview/]
62+
> **NOTE** Docker Toolbox is legacy. You should to use Docker Community Edition, See [Docker Toolbox](https://docs.docker.com/toolbox/overview/).
6263
6364
Once you've installed Docker Community Edition, click the docker icon in Launchpad. Then start up a container:
6465

@@ -70,6 +71,28 @@ That's it, you have a running Docker container.
7071

7172
If you are a complete Docker newbie, you should probably follow the [series of tutorials](https://docs.docker.com/engine/getstarted/) now.
7273

74+
### Check Version
75+
76+
It is very important that you always know the current version of Docker you are currently running on at any point in time. This is very helpful because you get to know what features are compatible with what you have running. This is also important because you know what containers to run from the docker store when you are trying to get template containers. That said let see how to know which version of docker we have running currently.
77+
78+
* [`docker version`](https://docs.docker.com/engine/reference/commandline/version/) shows which version of docker you have running.
79+
80+
Get the server version:
81+
82+
```
83+
$ docker version --format '{{.Server.Version}}'
84+
85+
1.8.0
86+
```
87+
88+
You can also dump raw JSON data:
89+
90+
```
91+
$ docker version --format '{{json .}}'
92+
93+
{"Client":{"Version":"1.8.0","ApiVersion":"1.20","GitCommit":"f5bae0a","GoVersion":"go1.4.2","Os":"linux","Arch":"am"}
94+
```
95+
7396
## Containers
7497

7598
[Your basic isolated Docker process](http://etherealmind.com/basics-docker-containers-hypervisors-coreos/). Containers are to Virtual Machines as threads are to processes. Or you can think of them as chroots on steroids.
@@ -116,19 +139,19 @@ Restart policies on crashed docker instances are [covered here](http://container
116139

117140
You can limit CPU, either using a percentage of all CPUs, or by using specific cores.
118141

119-
For example, you can tell the [`cpu-shares`](https://docs.docker.com/engine/reference/run/#/cpu-share-constraint) setting. The setting is a bit strange -- 1024 means 100% of the CPU, so if you want the container to take 50% of all CPU cores, you should specify 512. See https://goldmann.pl/blog/2014/09/11/resource-management-in-docker/#_cpu for more:
142+
For example, you can tell the [`cpu-shares`](https://docs.docker.com/engine/reference/run/#/cpu-share-constraint) setting. The setting is a bit strange -- 1024 means 100% of the CPU, so if you want the container to take 50% of all CPU cores, you should specify 512. See <https://goldmann.pl/blog/2014/09/11/resource-management-in-docker/#_cpu> for more:
120143

121144
```
122145
docker run -ti -c 512 agileek/cpuset-test
123146
```
124147

125-
You can also only use some CPU cores using [`cpuset-cpus`](https://docs.docker.com/engine/reference/run/#/cpuset-constraint). See https://agileek.github.io/docker/2014/08/06/docker-cpuset/ for details and some nice videos:
148+
You can also only use some CPU cores using [`cpuset-cpus`](https://docs.docker.com/engine/reference/run/#/cpuset-constraint). See <https://agileek.github.io/docker/2014/08/06/docker-cpuset/> for details and some nice videos:
126149

127150
```
128151
docker run -ti --cpuset-cpus=0,4,6 agileek/cpuset-test
129152
```
130153

131-
Note that Docker can still **see** all of the CPUs inside the container -- it just isn't using all of them. See https://github.com/docker/docker/issues/20770 for more details.
154+
Note that Docker can still **see** all of the CPUs inside the container -- it just isn't using all of them. See <https://github.com/docker/docker/issues/20770> for more details.
132155

133156
#### Memory Constraints
134157

@@ -140,7 +163,7 @@ docker run -it -m 300M ubuntu:14.04 /bin/bash
140163

141164
#### Capabilities
142165

143-
Linux capabilities can be set by using `cap-add` and `cap-drop`. See https://docs.docker.com/engine/reference/run/#/runtime-privilege-and-linux-capabilities for details. This should be used for greater security.
166+
Linux capabilities can be set by using `cap-add` and `cap-drop`. See <https://docs.docker.com/engine/reference/run/#/runtime-privilege-and-linux-capabilities> for details. This should be used for greater security.
144167

145168
To mount a FUSE based filesystem, you need to combine both --cap-add and --device:
146169

@@ -160,9 +183,8 @@ Give access to all devices:
160183
docker run -it --privileged -v /dev/bus/usb:/dev/bus/usb debian bash
161184
```
162185

163-
more info about privileged containers [here](
164-
https://docs.docker.com/engine/reference/run/#/runtime-privilege-and-linux-capabilities)
165-
186+
More info about privileged containers [here](
187+
https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities).
166188

167189
### Info
168190

@@ -177,7 +199,7 @@ https://docs.docker.com/engine/reference/run/#/runtime-privilege-and-linux-capab
177199

178200
`docker ps -a` shows running and stopped containers.
179201

180-
`docker stats --all` shows a running list of containers.
202+
`docker stats --all` shows a list of all containers, default shows just running.
181203

182204
### Import / Export
183205

@@ -209,25 +231,9 @@ Images are just [templates for docker containers](https://docs.docker.com/engine
209231
* [`docker history`](https://docs.docker.com/engine/reference/commandline/history) shows history of image.
210232
* [`docker tag`](https://docs.docker.com/engine/reference/commandline/tag) tags an image to a name (local or registry).
211233

212-
## Checking Docker Version
213-
214-
It is very important that you always know the current version of Docker you are currently running on at any point in time.This is very helpful because you get to know what features are compatible with what you have running. This is also important because you know what containers to run from the docker store when you are trying to get template containers. That said let see how to know what version of docker we have running currently
215-
216-
* ['docker version'](https://docs.docker.com/engine/reference/commandline/version/) check what version of docker you have running
217-
* [docker version [OPTIONS]]
218-
219-
Get the server version
220-
$ docker version --format '{{.Server.Version}}'
221-
222-
1.8.0
223-
Dump raw JSON data
224-
$ docker version --format '{{json .}}'
225-
226-
{"Client":{"Version":"1.8.0","ApiVersion":"1.20","GitCommit":"f5bae0a","GoVersion":"go1.4.2","Os":"linux","Arch":"am"}
227-
228234
### Cleaning up
229235

230-
While you can use the `docker rmi` command to remove specific images, there's a tool called [docker-gc](https://github.com/spotify/docker-gc) that will safely clean up images that are no longer used by any containers.
236+
While you can use the `docker rmi` command to remove specific images, there's a tool called [docker-gc](https://github.com/spotify/docker-gc) that will safely clean up images that are no longer used by any containers. As of docker 1.13, `docker image prune` is also available for removing unused images. See [Prune](#prune).
231237

232238
### Load/Save image
233239

@@ -334,15 +340,15 @@ Here are some common text editors and their syntax highlighting modules you coul
334340
* [EXPOSE](https://docs.docker.com/engine/reference/builder/#expose) informs Docker that the container listens on the specified network ports at runtime. NOTE: does not actually make ports accessible.
335341
* [ENV](https://docs.docker.com/engine/reference/builder/#env) sets environment variable.
336342
* [ADD](https://docs.docker.com/engine/reference/builder/#add) copies new files, directories or remote file to container. Invalidates caches. Avoid `ADD` and use `COPY` instead.
337-
* [COPY](https://docs.docker.com/engine/reference/builder/#copy) copies new files or directories to container. Note that this only copies as root, so you have to chown manually regardless of your USER / WORKDIR setting. See https://github.com/moby/moby/issues/30110
343+
* [COPY](https://docs.docker.com/engine/reference/builder/#copy) copies new files or directories to container. Note that this only copies as root, so you have to chown manually regardless of your USER / WORKDIR setting, as same as `ADD`. See <https://github.com/moby/moby/issues/30110>
338344
* [ENTRYPOINT](https://docs.docker.com/engine/reference/builder/#entrypoint) configures a container that will run as an executable.
339345
* [VOLUME](https://docs.docker.com/engine/reference/builder/#volume) creates a mount point for externally mounted volumes or other containers.
340346
* [USER](https://docs.docker.com/engine/reference/builder/#user) sets the user name for following RUN / CMD / ENTRYPOINT commands.
341347
* [WORKDIR](https://docs.docker.com/engine/reference/builder/#workdir) sets the working directory.
342348
* [ARG](https://docs.docker.com/engine/reference/builder/#arg) defines a build-time variable.
343349
* [ONBUILD](https://docs.docker.com/engine/reference/builder/#onbuild) adds a trigger instruction when the image is used as the base for another build.
344350
* [STOPSIGNAL](https://docs.docker.com/engine/reference/builder/#stopsignal) sets the system call signal that will be sent to the container to exit.
345-
* [LABEL](https://docs.docker.com/engine/userguide/labels-custom-metadata/) apply key/value metadata to your images, containers, or daemons.
351+
* [LABEL](https://docs.docker.com/config/labels-custom-metadata/) apply key/value metadata to your images, containers, or daemons.
346352

347353
### Tutorial
348354

@@ -363,9 +369,9 @@ The versioned filesystem in Docker is based on layers. They're like [git commits
363369

364370
## Links
365371

366-
Links are how Docker containers talk to each other [through TCP/IP ports](https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/). [Linking into Redis](https://docs.docker.com/engine/examples/running_redis_service/) and [Atlassian](https://blogs.atlassian.com/2013/11/docker-all-the-things-at-atlassian-automation-and-wiring/) show worked examples. You can also resolve [links by hostname](https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/#/updating-the-etchosts-file).
372+
Links are how Docker containers talk to each other [through TCP/IP ports](https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/). [Atlassian](https://blogs.atlassian.com/2013/11/docker-all-the-things-at-atlassian-automation-and-wiring/) show worked examples. You can also resolve [links by hostname](https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/#/updating-the-etchosts-file).
367373

368-
This has been deprected to some extent by [user-defined networks](https://docs.docker.com/engine/userguide/networking/#user-defined-networks).
374+
This has been deprecated to some extent by [user-defined networks](https://docs.docker.com/network/).
369375

370376
NOTE: If you want containers to ONLY communicate with each other through links, start the docker daemon with `-icc=false` to disable inter process communication.
371377

@@ -396,7 +402,7 @@ Generally, linking between docker services is a subset of "service discovery", a
396402

397403
## Volumes
398404

399-
Docker volumes are [free-floating filesystems](https://docs.docker.com/engine/tutorials/dockervolumes/). They don't have to be connected to a particular container. You should use volumes mounted from [data-only containers](https://medium.com/@ramangupta/why-docker-data-containers-are-good-589b3c6c749e) for portability.
405+
Docker volumes are [free-floating filesystems](https://docs.docker.com/engine/tutorials/dockervolumes/). They don't have to be connected to a particular container. You can use volumes mounted from [data-only containers](https://medium.com/@ramangupta/why-docker-data-containers-are-good-589b3c6c749e) for portability. As of Docker 1.9.0, Docker has named volumes which replace data-only containers. Consider using named volumes to implement it rather than data containers.
400406

401407
### Lifecycle
402408

@@ -414,7 +420,7 @@ You can mount them in several docker containers at once, using `docker run --vol
414420

415421
Because volumes are isolated filesystems, they are often used to store state from computations between transient containers. That is, you can have a stateless and transient container run from a recipe, blow it away, and then have a second instance of the transient container pick up from where the last one left off.
416422

417-
See [advanced volumes](http://crosbymichael.com/advanced-docker-volumes.html) for more details. Container42 is [also helpful](http://container42.com/2014/11/03/docker-indepth-volumes/).
423+
See [advanced volumes](http://crosbymichael.com/advanced-docker-volumes.html) for more details. [Container42](http://container42.com/2014/11/03/docker-indepth-volumes/) is also helpful.
418424

419425
You can [map MacOS host directories as docker volumes](https://docs.docker.com/engine/tutorials/dockervolumes/#mount-a-host-directory-as-a-data-volume):
420426

@@ -426,7 +432,7 @@ You can use remote NFS volumes if you're [feeling brave](https://docs.docker.com
426432

427433
You may also consider running data-only containers as described [here](http://container42.com/2013/12/16/persistent-volumes-with-docker-container-as-volume-pattern/) to provide some data portability.
428434

429-
[Be aware that you can mount files as volumes.](#volumes-can-be-files)
435+
Be aware that you can [mount files as volumes](#volumes-can-be-files).
430436

431437
## Exposing ports
432438

@@ -484,7 +490,7 @@ This is where general Docker best practices and war stories go:
484490

485491
This is where security tips about Docker go. The Docker [security](https://docs.docker.com/engine/security/security/) page goes into more detail.
486492

487-
First things first: Docker runs as root. If you are in the `docker` group, you effectively [have root access](http://reventlov.com/advisories/using-the-docker-command-to-root-the-host). If you expose the docker unix socket to a container, you are giving the container [root access to the host](https://www.lvh.io/posts/dont-expose-the-docker-socket-not-even-to-a-container.html).
493+
First things first: Docker runs as root. If you are in the `docker` group, you effectively [have root access](https://web.archive.org/web/20161226211755/http://reventlov.com/advisories/using-the-docker-command-to-root-the-host). If you expose the docker unix socket to a container, you are giving the container [root access to the host](https://www.lvh.io/posts/dont-expose-the-docker-socket-not-even-to-a-container.html).
488494

489495
Docker should not be your only defense. You should secure and harden it.
490496

@@ -498,7 +504,7 @@ Docker image ids are [sensitive information](https://medium.com/@quayio/your-doc
498504

499505
See the [Docker Security Cheat Sheet](https://github.com/konstruktoid/Docker/blob/master/Security/CheatSheet.adoc) by [Thomas Sjögren](https://github.com/konstruktoid): some good stuff about container hardening in there.
500506

501-
Check out the [docker bench security script](https://github.com/docker/docker-bench-security), download the [white papers](https://blog.docker.com/2015/05/understanding-docker-security-and-best-practices/) and subscribe to the [mailing lists](https://www.docker.com/docker-security) (unfortunately Docker does not have a unique mailing list, only dev / user).
507+
Check out the [docker bench security script](https://github.com/docker/docker-bench-security), download the [white papers](https://blog.docker.com/2015/05/understanding-docker-security-and-best-practices/).
502508

503509
You should start off by using a kernel with unstable patches for grsecurity / pax compiled in, such as [Alpine Linux](https://en.wikipedia.org/wiki/Alpine_Linux). If you are using grsecurity in production, you should spring for [commercial support](https://grsecurity.net/business_support.php) for the [stable patches](https://grsecurity.net/announce.php), same as you would do for RedHat. It's $200 a month, which is nothing to your devops budget.
504510

@@ -582,7 +588,7 @@ The new [Data Management Commands](https://github.com/docker/docker/pull/26108)
582588
* `docker container prune`
583589
* `docker image prune`
584590

585-
### df
591+
### df
586592

587593
`docker system df` presents a summary of the space currently used by different docker objects.
588594

@@ -615,7 +621,7 @@ docker commit -run='{"Cmd":["postgres", "-too -many -opts"]}' $(dl) postgres
615621
docker inspect $(dl) | grep -wm1 IPAddress | cut -d '"' -f 4
616622
```
617623

618-
or install [jq](https://stedolan.github.io/jq/):
624+
or with [jq](https://stedolan.github.io/jq/) installed:
619625

620626
```
621627
docker inspect $(dl) | jq -r '.[0].NetworkSettings.IPAddress'
@@ -636,7 +642,7 @@ docker build \
636642
--build-arg ARTIFACTORY_ADDRESS=$DOCKER_HOST_IP
637643
-t sometag \
638644
some-directory/
639-
```
645+
```
640646

641647
### Get port mapping
642648

@@ -723,8 +729,8 @@ Otherwise, the previous layers still persist the original information and your i
723729

724730
```
725731
RUN {apt commands} \
726-
&& apt-get clean \
727-
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
732+
&& apt-get clean \
733+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
728734
```
729735

730736
- Flatten an image
@@ -743,39 +749,36 @@ gzip -dc image.tgz | docker import - flat-image-name
743749
### Monitor system resource utilization for running containers
744750

745751
To check the CPU, memory, and network I/O usage of a single container, you can use:
746-
747752
```
748753
docker stats <container>
749754
```
750755

751756
For all containers listed by id:
752-
753757
```
754758
docker stats $(docker ps -q)
755759
```
756760

757761
For all containers listed by name:
758-
759762
```
760763
docker stats $(docker ps --format '{{.Names}}')
761764
```
762765

763766
For all containers listed by image:
764-
765767
```
766768
docker ps -a -f ancestor=ubuntu
767769
```
768770

769-
Remove all untagged images
771+
Remove all untagged images:
770772
```
771773
docker rmi $(docker images | grep “^” | awk '{split($0,a," "); print a[3]}')
772774
```
773775

774-
Remove container by a regular expression
776+
Remove container by a regular expression:
775777
```
776778
docker ps -a | grep wildfly | awk '{print $1}' | xargs docker rm -f
777779
```
778-
Remove all exited containers
780+
781+
Remove all exited containers:
779782
```
780783
docker rm -f $(docker ps -a | grep Exit | awk '{ print $1 }')
781784
```

0 commit comments

Comments
 (0)