mirror of https://github.com/docker/cli.git
Consistently use 'sudo docker' in examples
Docker-DCO-1.1-Signed-off-by: Sven Dowideit <SvenDowideit@docker.com> (github: SvenDowideit)
This commit is contained in:
parent
b7cb370393
commit
3ca630d381
|
@ -57,7 +57,7 @@ instructions.
|
|||
Whenever possible, Docker will re-use the intermediate images,
|
||||
accelerating `docker build` significantly (indicated by `Using cache`):
|
||||
|
||||
$ docker build -t SvenDowideit/ambassador .
|
||||
$ sudo docker build -t SvenDowideit/ambassador .
|
||||
Uploading context 10.24 kB
|
||||
Uploading context
|
||||
Step 1 : FROM docker-ut
|
||||
|
@ -109,7 +109,7 @@ The following example shows the use of the `.dockerignore` file to exclude the
|
|||
`.git` directory from the context. Its effect can be seen in the changed size of
|
||||
the uploaded context.
|
||||
|
||||
$ docker build .
|
||||
$ sudo docker build .
|
||||
Uploading context 18.829 MB
|
||||
Uploading context
|
||||
Step 0 : FROM busybox
|
||||
|
@ -119,7 +119,7 @@ the uploaded context.
|
|||
---> 99cc1ad10469
|
||||
Successfully built 99cc1ad10469
|
||||
$ echo ".git" > .dockerignore
|
||||
$ docker build .
|
||||
$ sudo docker build .
|
||||
Uploading context 6.76 MB
|
||||
Uploading context
|
||||
Step 0 : FROM busybox
|
||||
|
|
|
@ -35,11 +35,11 @@ will set the value to the opposite of the default value.
|
|||
|
||||
Options like `-a=[]` indicate they can be specified multiple times:
|
||||
|
||||
$ docker run -a stdin -a stdout -a stderr -i -t ubuntu /bin/bash
|
||||
$ sudo docker run -a stdin -a stdout -a stderr -i -t ubuntu /bin/bash
|
||||
|
||||
Sometimes this can use a more complex value string, as for `-v`:
|
||||
|
||||
$ docker run -v /host:/container example/mysql
|
||||
$ sudo docker run -v /host:/container example/mysql
|
||||
|
||||
### Strings and Integers
|
||||
|
||||
|
@ -104,10 +104,10 @@ To use lxc as the execution driver, use `docker -d -e lxc`.
|
|||
The docker client will also honor the `DOCKER_HOST` environment variable to set
|
||||
the `-H` flag for the client.
|
||||
|
||||
$ docker -H tcp://0.0.0.0:2375 ps
|
||||
$ sudo docker -H tcp://0.0.0.0:2375 ps
|
||||
# or
|
||||
$ export DOCKER_HOST="tcp://0.0.0.0:2375"
|
||||
$ docker ps
|
||||
$ sudo docker ps
|
||||
# both are equal
|
||||
|
||||
To run the daemon with [systemd socket activation](
|
||||
|
@ -271,7 +271,7 @@ If you wish to keep the intermediate containers after the build is
|
|||
complete, you must use `--rm=false`. This does not
|
||||
affect the build cache.
|
||||
|
||||
$ docker build .
|
||||
$ sudo docker build .
|
||||
Uploading context 18.829 MB
|
||||
Uploading context
|
||||
Step 0 : FROM busybox
|
||||
|
@ -281,7 +281,7 @@ affect the build cache.
|
|||
---> 99cc1ad10469
|
||||
Successfully built 99cc1ad10469
|
||||
$ echo ".git" > .dockerignore
|
||||
$ docker build .
|
||||
$ sudo docker build .
|
||||
Uploading context 6.76 MB
|
||||
Uploading context
|
||||
Step 0 : FROM busybox
|
||||
|
@ -355,9 +355,9 @@ If this behavior is undesired, set the 'p' option to false.
|
|||
ID IMAGE COMMAND CREATED STATUS PORTS
|
||||
c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours
|
||||
197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours
|
||||
$ docker commit c3f279d17e0a SvenDowideit/testimage:version3
|
||||
$ sudo docker commit c3f279d17e0a SvenDowideit/testimage:version3
|
||||
f5283438590d
|
||||
$ docker images | head
|
||||
$ sudo docker images | head
|
||||
REPOSITORY TAG ID CREATED VIRTUAL SIZE
|
||||
SvenDowideit/testimage version3 f5283438590d 16 seconds ago 335.7 MB
|
||||
|
||||
|
@ -464,7 +464,7 @@ For example:
|
|||
|
||||
To see how the `docker:latest` image was built:
|
||||
|
||||
$ docker history docker
|
||||
$ sudo docker history docker
|
||||
IMAGE CREATED CREATED BY SIZE
|
||||
3e23a5875458790b7a806f95f7ec0d0b2a5c1659bfc899c89f939f6d5b8f7094 8 days ago /bin/sh -c #(nop) ENV LC_ALL=C.UTF-8 0 B
|
||||
8578938dd17054dce7993d21de79e96a037400e8d28e15e7290fea4f65128a36 8 days ago /bin/sh -c dpkg-reconfigure locales && locale-gen C.UTF-8 && /usr/sbin/update-locale LANG=C.UTF-8 1.245 MB
|
||||
|
@ -729,7 +729,7 @@ If you want to login to a self-hosted registry you can
|
|||
specify this by adding the server name.
|
||||
|
||||
example:
|
||||
$ docker login localhost:8080
|
||||
$ sudo docker login localhost:8080
|
||||
|
||||
## logout
|
||||
|
||||
|
@ -739,7 +739,7 @@ specify this by adding the server name.
|
|||
|
||||
For example:
|
||||
|
||||
$ docker logout localhost:8080
|
||||
$ sudo docker logout localhost:8080
|
||||
|
||||
## logs
|
||||
|
||||
|
@ -772,17 +772,17 @@ log entry.
|
|||
You can find out all the ports mapped by not specifying a `PRIVATE_PORT`, or
|
||||
just a specific mapping:
|
||||
|
||||
$ docker ps test
|
||||
$ sudo docker ps test
|
||||
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
|
||||
$ docker port test
|
||||
$ sudo docker port test
|
||||
7890/tcp -> 0.0.0.0:4321
|
||||
9876/tcp -> 0.0.0.0:1234
|
||||
$ docker port test 7890/tcp
|
||||
$ sudo docker port test 7890/tcp
|
||||
0.0.0.0:4321
|
||||
$ docker port test 7890/udp
|
||||
$ sudo docker port test 7890/udp
|
||||
2014/06/24 11:53:36 Error: No public port '7890/udp' published for test
|
||||
$ docker port test 7890
|
||||
$ sudo docker port test 7890
|
||||
0.0.0.0:4321
|
||||
|
||||
## pause
|
||||
|
@ -820,7 +820,7 @@ further details.
|
|||
|
||||
Running `docker ps` showing 2 linked containers.
|
||||
|
||||
$ docker ps
|
||||
$ sudo docker ps
|
||||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||||
4c01db0b339c ubuntu:12.04 bash 17 seconds ago Up 16 seconds webapp
|
||||
d7886598dbe2 crosbymichael/redis:latest /redis-server --dir 33 minutes ago Up 33 minutes 6379/tcp redis,webapp/db
|
||||
|
@ -869,15 +869,15 @@ a protocol specifier (https://, for example).
|
|||
To download a particular image, or set of images (i.e., a repository),
|
||||
use `docker pull`:
|
||||
|
||||
$ docker pull debian
|
||||
$ sudo docker pull debian
|
||||
# will pull only the debian:latest image and its intermediate layers
|
||||
$ docker pull debian:testing
|
||||
$ sudo docker pull debian:testing
|
||||
# will pull only the image named debian:testing and any intermediate layers
|
||||
# it is based on. (Typically the empty `scratch` image, a MAINTAINER layer,
|
||||
# and the un-tarred base).
|
||||
$ docker pull --all-tags centos
|
||||
$ sudo docker pull --all-tags centos
|
||||
# will pull all the images from the centos repository
|
||||
$ docker pull registry.hub.docker.com/debian
|
||||
$ sudo docker pull registry.hub.docker.com/debian
|
||||
# manually specifies the path to the default Docker registry. This could
|
||||
# be replaced with the path to a local registry to pull from another source.
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ other `docker` command.
|
|||
|
||||
The basic `docker run` command takes this form:
|
||||
|
||||
$ docker run [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG...]
|
||||
$ sudo docker run [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG...]
|
||||
|
||||
To learn how to interpret the types of `[OPTIONS]`,
|
||||
see [*Option types*](/reference/commandline/cli/#option-types).
|
||||
|
@ -91,7 +91,7 @@ streams]( https://github.com/docker/docker/blob/
|
|||
specify to which of the three standard streams (`STDIN`, `STDOUT`,
|
||||
`STDERR`) you'd like to connect instead, as in:
|
||||
|
||||
$ docker run -a stdin -a stdout -i -t ubuntu /bin/bash
|
||||
$ sudo docker run -a stdin -a stdout -i -t ubuntu /bin/bash
|
||||
|
||||
For interactive processes (like a shell) you will typically want a tty
|
||||
as well as persistent standard input (`STDIN`), so you'll use `-i -t`
|
||||
|
@ -192,9 +192,9 @@ Example running a Redis container with Redis binding to `localhost` then
|
|||
running the `redis-cli` command and connecting to the Redis server over the
|
||||
`localhost` interface.
|
||||
|
||||
$ docker run -d --name redis example/redis --bind 127.0.0.1
|
||||
$ sudo docker run -d --name redis example/redis --bind 127.0.0.1
|
||||
$ # use the redis container's network stack to access localhost
|
||||
$ docker run --rm -ti --net container:redis example/redis-cli -h 127.0.0.1
|
||||
$ sudo docker run --rm -ti --net container:redis example/redis-cli -h 127.0.0.1
|
||||
|
||||
## Clean Up (–-rm)
|
||||
|
||||
|
@ -253,14 +253,14 @@ If you want to limit access to a specific device or devices you can use
|
|||
the `--device` flag. It allows you to specify one or more devices that
|
||||
will be accessible within the container.
|
||||
|
||||
$ docker run --device=/dev/snd:/dev/snd ...
|
||||
$ sudo docker run --device=/dev/snd:/dev/snd ...
|
||||
|
||||
In addition to `--privileged`, the operator can have fine grain control over the
|
||||
capabilities using `--cap-add` and `--cap-drop`. By default, Docker has a default
|
||||
list of capabilities that are kept. Both flags support the value `all`, so if the
|
||||
operator wants to have all capabilities but `MKNOD` they could use:
|
||||
|
||||
$ docker run --cap-add=ALL --cap-drop=MKNOD ...
|
||||
$ sudo docker run --cap-add=ALL --cap-drop=MKNOD ...
|
||||
|
||||
For interacting with the network stack, instead of using `--privileged` they
|
||||
should use `--cap-add=NET_ADMIN` to modify the network interfaces.
|
||||
|
@ -299,7 +299,7 @@ Dockerfile instruction and how the operator can override that setting.
|
|||
Recall the optional `COMMAND` in the Docker
|
||||
commandline:
|
||||
|
||||
$ docker run [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG...]
|
||||
$ sudo docker run [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG...]
|
||||
|
||||
This command is optional because the person who created the `IMAGE` may
|
||||
have already provided a default `COMMAND` using the Dockerfile `CMD`
|
||||
|
@ -326,12 +326,12 @@ runtime by using a string to specify the new `ENTRYPOINT`. Here is an
|
|||
example of how to run a shell in a container that has been set up to
|
||||
automatically run something else (like `/usr/bin/redis-server`):
|
||||
|
||||
$ docker run -i -t --entrypoint /bin/bash example/redis
|
||||
$ sudo docker run -i -t --entrypoint /bin/bash example/redis
|
||||
|
||||
or two examples of how to pass more parameters to that ENTRYPOINT:
|
||||
|
||||
$ docker run -i -t --entrypoint /bin/bash example/redis -c ls -l
|
||||
$ docker run -i -t --entrypoint /usr/bin/redis-cli example/redis --help
|
||||
$ sudo docker run -i -t --entrypoint /bin/bash example/redis -c ls -l
|
||||
$ sudo docker run -i -t --entrypoint /usr/bin/redis-cli example/redis --help
|
||||
|
||||
## EXPOSE (Incoming Ports)
|
||||
|
||||
|
@ -378,7 +378,7 @@ The operator can **set any environment variable** in the container by
|
|||
using one or more `-e` flags, even overriding those already defined by
|
||||
the developer with a Dockerfile `ENV`:
|
||||
|
||||
$ docker run -e "deep=purple" --rm ubuntu /bin/bash -c export
|
||||
$ sudo docker run -e "deep=purple" --rm ubuntu /bin/bash -c export
|
||||
declare -x HOME="/"
|
||||
declare -x HOSTNAME="85bc26a0e200"
|
||||
declare -x OLDPWD
|
||||
|
@ -396,23 +396,23 @@ information for connecting to the service container. Let's imagine we have a
|
|||
container running Redis:
|
||||
|
||||
# Start the service container, named redis-name
|
||||
$ docker run -d --name redis-name dockerfiles/redis
|
||||
$ sudo docker run -d --name redis-name dockerfiles/redis
|
||||
4241164edf6f5aca5b0e9e4c9eccd899b0b8080c64c0cd26efe02166c73208f3
|
||||
|
||||
# The redis-name container exposed port 6379
|
||||
$ docker ps
|
||||
$ sudo docker ps
|
||||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||||
4241164edf6f $ dockerfiles/redis:latest /redis-stable/src/re 5 seconds ago Up 4 seconds 6379/tcp redis-name
|
||||
|
||||
# Note that there are no public ports exposed since we didn᾿t use -p or -P
|
||||
$ docker port 4241164edf6f 6379
|
||||
$ sudo docker port 4241164edf6f 6379
|
||||
2014/01/25 00:55:38 Error: No public port '6379' published for 4241164edf6f
|
||||
|
||||
Yet we can get information about the Redis container's exposed ports
|
||||
with `--link`. Choose an alias that will form a
|
||||
valid environment variable!
|
||||
|
||||
$ docker run --rm --link redis-name:redis_alias --entrypoint /bin/bash dockerfiles/redis -c export
|
||||
$ sudo docker run --rm --link redis-name:redis_alias --entrypoint /bin/bash dockerfiles/redis -c export
|
||||
declare -x HOME="/"
|
||||
declare -x HOSTNAME="acda7f7b1cdc"
|
||||
declare -x OLDPWD
|
||||
|
@ -429,15 +429,15 @@ valid environment variable!
|
|||
|
||||
And we can use that information to connect from another container as a client:
|
||||
|
||||
$ docker run -i -t --rm --link redis-name:redis_alias --entrypoint /bin/bash dockerfiles/redis -c '/redis-stable/src/redis-cli -h $REDIS_ALIAS_PORT_6379_TCP_ADDR -p $REDIS_ALIAS_PORT_6379_TCP_PORT'
|
||||
$ sudo docker run -i -t --rm --link redis-name:redis_alias --entrypoint /bin/bash dockerfiles/redis -c '/redis-stable/src/redis-cli -h $REDIS_ALIAS_PORT_6379_TCP_ADDR -p $REDIS_ALIAS_PORT_6379_TCP_PORT'
|
||||
172.17.0.32:6379>
|
||||
|
||||
Docker will also map the private IP address to the alias of a linked
|
||||
container by inserting an entry into `/etc/hosts`. You can use this
|
||||
mechanism to communicate with a linked container by its alias:
|
||||
|
||||
$ docker run -d --name servicename busybox sleep 30
|
||||
$ docker run -i -t --link servicename:servicealias busybox ping -c 1 servicealias
|
||||
$ sudo docker run -d --name servicename busybox sleep 30
|
||||
$ sudo docker run -i -t --link servicename:servicealias busybox ping -c 1 servicealias
|
||||
|
||||
If you restart the source container (`servicename` in this case), the recipient
|
||||
container's `/etc/hosts` entry will be automatically updated.
|
||||
|
|
Loading…
Reference in New Issue