Skip to content

Commit

Permalink
Merge pull request #1069 from mstanleyjones/examples_to_cli_temporary…
Browse files Browse the repository at this point in the history
…_fix

Add examples to CLI generation templates
  • Loading branch information
Misty Stanley-Jones authored Jan 13, 2017
2 parents cd50e23 + b028938 commit 3fc38dc
Show file tree
Hide file tree
Showing 48 changed files with 3,901 additions and 0 deletions.
31 changes: 31 additions & 0 deletions engine/reference/commandline/container_attach.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,34 @@ https://www.github.com/docker/docker
-->

{% include cli.md %}

## Examples

### Attaching to a container

In this example the top command is run inside a container, from an image called
fedora, in detached mode. The ID from the container is passed into the **docker
attach** command:

```bash
$ ID=$(sudo docker run -d fedora /usr/bin/top -b)

$ sudo docker attach $ID
top - 02:05:52 up 3:05, 0 users, load average: 0.01, 0.02, 0.05
Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.1%us, 0.2%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 373572k total, 355560k used, 18012k free, 27872k buffers
Swap: 786428k total, 0k used, 786428k free, 221740k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 17200 1116 912 R 0 0.3 0:00.03 top

top - 02:05:55 up 3:05, 0 users, load average: 0.01, 0.02, 0.05
Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.0%us, 0.2%sy, 0.0%ni, 99.8%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 373572k total, 355244k used, 18328k free, 27872k buffers
Swap: 786428k total, 0k used, 786428k free, 221776k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 17208 1144 932 R 0 0.3 0:00.03 top
```
25 changes: 25 additions & 0 deletions engine/reference/commandline/container_commit.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,28 @@ https://www.github.com/docker/docker
-->

{% include cli.md %}

## Examples

### Creating a new image from an existing container
An existing Fedora based container has had Apache installed while running
in interactive mode with the bash shell. Apache is also running. To
create a new image run `docker ps` to find the container's ID and then run:

```bash
$ docker commit -m="Added Apache to Fedora base image" \
-a="A D Ministrator" 98bd7fc99854 fedora/fedora_httpd:20
```

Note that only `a-z0-9-_.` are allowed when naming images from an
existing container.

### Apply specified Dockerfile instructions while committing the image
If an existing container was created without the DEBUG environment
variable set to "true", you can create a new image based on that
container by first getting the container's ID with `docker ps` and
then running:

```bash
$ docker container commit -c="ENV DEBUG true" 98bd7fc99854 debug-image
```
67 changes: 67 additions & 0 deletions engine/reference/commandline/container_cp.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,70 @@ https://www.github.com/docker/docker
-->

{% include cli.md %}

## Examples

Suppose a container has finished producing some output as a file it saves
to somewhere in its filesystem. This could be the output of a build job or
some other computation. You can copy these outputs from the container to a
location on your local host.

If you want to copy the `/tmp/foo` directory from a container to the
existing `/tmp` directory on your host. If you run `docker container cp` in your `~`
(home) directory on the local host:

$ docker container cp compassionate_darwin:tmp/foo /tmp

Docker creates a `/tmp/foo` directory on your host. Alternatively, you can omit
the leading slash in the command. If you execute this command from your home
directory:

$ docker container cp compassionate_darwin:tmp/foo tmp

If `~/tmp` does not exist, Docker will create it and copy the contents of
`/tmp/foo` from the container into this new directory. If `~/tmp` already
exists as a directory, then Docker will copy the contents of `/tmp/foo` from
the container into a directory at `~/tmp/foo`.

When copying a single file to an existing `LOCALPATH`, the `docker container cp` command
will either overwrite the contents of `LOCALPATH` if it is a file or place it
into `LOCALPATH` if it is a directory, overwriting an existing file of the same
name if one exists. For example, this command:

$ docker container cp sharp_ptolemy:/tmp/foo/myfile.txt /test

If `/test` does not exist on the local machine, it will be created as a file
with the contents of `/tmp/foo/myfile.txt` from the container. If `/test`
exists as a file, it will be overwritten. Lastly, if `/test` exists as a
directory, the file will be copied to `/test/myfile.txt`.

Next, suppose you want to copy a file or folder into a container. For example,
this could be a configuration file or some other input to a long running
computation that you would like to place into a created container before it
starts. This is useful because it does not require the configuration file or
other input to exist in the container image.

If you have a file, `config.yml`, in the current directory on your local host
and wish to copy it to an existing directory at `/etc/my-app.d` in a container,
this command can be used:

$ docker container cp config.yml myappcontainer:/etc/my-app.d

If you have several files in a local directory `/config` which you need to copy
to a directory `/etc/my-app.d` in a container:

$ docker container cp /config/. myappcontainer:/etc/my-app.d

The above command will copy the contents of the local `/config` directory into
the directory `/etc/my-app.d` in the container.

Finally, if you want to copy a symbolic link into a container, you typically
want to copy the linked target and not the link itself. To copy the target, use
the `-L` option, for example:

$ ln -s /tmp/somefile /tmp/somefile.ln
$ docker container cp -L /tmp/somefile.ln myappcontainer:/tmp/

This command copies content of the local `/tmp/somefile` into the file
`/tmp/somefile.ln` in the container. Without `-L` option, the `/tmp/somefile.ln`
preserves its symbolic link but not its content.
15 changes: 15 additions & 0 deletions engine/reference/commandline/container_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,18 @@ https://www.github.com/docker/docker
-->

{% include cli.md %}

## Examples

### Specify isolation technology for container (--isolation)

This option is useful in situations where you are running Docker containers on
Windows. The `--isolation=<value>` option sets a container's isolation
technology. On Linux, the only supported is the `default` option which uses
Linux namespaces. On Microsoft Windows, you can specify these values:

* `default`: Use the value specified by the Docker daemon's `--exec-opt` . If the `daemon` does not specify an isolation technology, Microsoft Windows uses `process` as its default value.
* `process`: Namespace isolation only.
* `hyperv`: Hyper-V hypervisor partition-based isolation.

Specifying the `--isolation` flag without a value is the same as setting `--isolation="default"`.
28 changes: 28 additions & 0 deletions engine/reference/commandline/container_diff.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,31 @@ https://www.github.com/docker/docker
-->

{% include cli.md %}

## Examples

Inspect the changes to an `nginx` container:

```bash
$ docker diff 1fdfd1f54c1b

C /dev
C /dev/console
C /dev/core
C /dev/stdout
C /dev/fd
C /dev/ptmx
C /dev/stderr
C /dev/stdin
C /run
A /run/nginx.pid
C /var/lib/nginx/tmp
A /var/lib/nginx/tmp/client_body
A /var/lib/nginx/tmp/fastcgi
A /var/lib/nginx/tmp/proxy
A /var/lib/nginx/tmp/scgi
A /var/lib/nginx/tmp/uwsgi
C /var/log/nginx
A /var/log/nginx/access.log
A /var/log/nginx/error.log
```
15 changes: 15 additions & 0 deletions engine/reference/commandline/container_exec.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,18 @@ https://www.github.com/docker/docker
-->

{% include cli.md %}

## Examples

$ docker run --name ubuntu_bash --rm -i -t ubuntu bash

This will create a container named `ubuntu_bash` and start a Bash session.

$ docker exec -d ubuntu_bash touch /tmp/execWorks

This will create a new file `/tmp/execWorks` inside the running container
`ubuntu_bash`, in the background.

$ docker exec -it ubuntu_bash bash

This will create a new Bash session in the container `ubuntu_bash`.
19 changes: 19 additions & 0 deletions engine/reference/commandline/container_export.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,22 @@ https://www.github.com/docker/docker
-->

{% include cli.md %}

## Examples

Export the contents of the container called angry_bell to a tar file
called angry_bell.tar:

```bash
$ docker export angry_bell > angry_bell.tar

$ docker export --output=angry_bell-latest.tar angry_bell

$ ls -sh angry_bell.tar

321M angry_bell.tar

$ ls -sh angry_bell-latest.tar

321M angry_bell-latest.tar
```
96 changes: 96 additions & 0 deletions engine/reference/commandline/container_logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,99 @@ https://www.github.com/docker/docker
-->

{% include cli.md %}

## Examples

### Display all containers, including non-running

```bash
$ docker container ls -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a87ecb4f327c fedora:20 /bin/sh -c #(nop) MA 20 minutes ago Exit 0 desperate_brattain
01946d9d34d8 vpavlin/rhel7:latest /bin/sh -c #(nop) MA 33 minutes ago Exit 0 thirsty_bell
c1d3b0166030 acffc0358b9e /bin/sh -c yum -y up 2 weeks ago Exit 1 determined_torvalds
41d50ecd2f57 fedora:20 /bin/sh -c #(nop) MA 2 weeks ago Exit 0 drunk_pike
```

### Display only IDs of all containers, including non-running

```bash
$ docker container ls -a -q

a87ecb4f327c
01946d9d34d8
c1d3b0166030
41d50ecd2f57
```

# Display only IDs of all containers that have the name `determined_torvalds`

```bash
$ docker container ls -a -q --filter=name=determined_torvalds

c1d3b0166030
```

### Display containers with their commands

```bash
{% raw %}
$ docker container ls --format "{{.ID}}: {{.Command}}"

a87ecb4f327c: /bin/sh -c #(nop) MA
01946d9d34d8: /bin/sh -c #(nop) MA
c1d3b0166030: /bin/sh -c yum -y up
41d50ecd2f57: /bin/sh -c #(nop) MA
{% endraw %}
```

### Display containers with their labels in a table

```bash
{% raw %}
$ docker container ls --format "table {{.ID}}\t{{.Labels}}"

CONTAINER ID LABELS
a87ecb4f327c com.docker.swarm.node=ubuntu,com.docker.swarm.storage=ssd
01946d9d34d8
c1d3b0166030 com.docker.swarm.node=debian,com.docker.swarm.cpu=6
41d50ecd2f57 com.docker.swarm.node=fedora,com.docker.swarm.cpu=3,com.docker.swarm.storage=ssd
{% endraw %}
```

### Display containers with their node label in a table

```bash
{% raw %}
$ docker container ls --format 'table {{.ID}}\t{{(.Label "com.docker.swarm.node")}}'

CONTAINER ID NODE
a87ecb4f327c ubuntu
01946d9d34d8
c1d3b0166030 debian
41d50ecd2f57 fedora
{% endraw %}
```

### Display containers with `remote-volume` mounted

```bash
{% raw %}
$ docker container ls --filter volume=remote-volume --format "table {{.ID}}\t{{.Mounts}}"

CONTAINER ID MOUNTS
9c3527ed70ce remote-volume
{% endraw %}
```

### Display containers with a volume mounted in `/data`

```bash
{% raw %}
$ docker container ls --filter volume=/data --format "table {{.ID}}\t{{.Mounts}}"

CONTAINER ID MOUNTS
9c3527ed70ce remote-volume
{% endraw %}
```
40 changes: 40 additions & 0 deletions engine/reference/commandline/container_port.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,43 @@ https://www.github.com/docker/docker
-->

{% include cli.md %}

## Examples

```bash
$ docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b650456536c7 busybox:latest top 54 minutes ago Up 54 minutes 0.0.0.0:1234->9876/tcp, 0.0.0.0:4321->7890/tcp test
```

### Find out all the ports mapped

```bash
$ docker container port test

7890/tcp -> 0.0.0.0:4321
9876/tcp -> 0.0.0.0:1234
```

### Find out a specific mapping

```bash
$ docker container port test 7890/tcp

0.0.0.0:4321
```

```bash
$ docker container port test 7890

0.0.0.0:4321
```

### An example showing error for non-existent mapping

```bash
$ docker container port test 7890/udp

2014/06/24 11:53:36 Error: No public port '7890/udp' published for test
```
Loading

0 comments on commit 3fc38dc

Please sign in to comment.