We now advise people to configure docker group and
add to sudo. Mac shouldn't use sudo. Removed sudo
from command examples. Left in installation to be removed
in installation doc sweep -- removing requires finer
grain control.
Signed-off-by: Mary Anthony <mary@docker.com>
| ... | ... |
@@ -31,7 +31,7 @@ A Dockerfile is similar to a Makefile. |
| 31 | 31 |
|
| 32 | 32 |
# USAGE |
| 33 | 33 |
|
| 34 |
- sudo docker build . |
|
| 34 |
+ docker build . |
|
| 35 | 35 |
|
| 36 | 36 |
-- Runs the steps and commits them, building a final image. |
| 37 | 37 |
The path to the source repository defines where to find the context of the |
| ... | ... |
@@ -41,7 +41,7 @@ A Dockerfile is similar to a Makefile. |
| 41 | 41 |
daemon. |
| 42 | 42 |
|
| 43 | 43 |
``` |
| 44 |
- sudo docker build -t repository/tag . |
|
| 44 |
+ docker build -t repository/tag . |
|
| 45 | 45 |
``` |
| 46 | 46 |
|
| 47 | 47 |
-- specifies a repository and tag at which to save the new image if the build |
| ... | ... |
@@ -26,7 +26,7 @@ Show the history of when and how an image was created. |
| 26 | 26 |
Only show numeric IDs. The default is *false*. |
| 27 | 27 |
|
| 28 | 28 |
# EXAMPLES |
| 29 |
- $ sudo docker history fedora |
|
| 29 |
+ $ docker history fedora |
|
| 30 | 30 |
IMAGE CREATED CREATED BY SIZE |
| 31 | 31 |
105182bb5e8b 5 days ago /bin/sh -c #(nop) ADD file:71356d2ad59aa3119d 372.7 MB |
| 32 | 32 |
73bd853d2ea5 13 days ago /bin/sh -c #(nop) MAINTAINER Lokesh Mandvekar 0 B |
| ... | ... |
@@ -24,11 +24,11 @@ Restores both images and tags. |
| 24 | 24 |
|
| 25 | 25 |
# EXAMPLES |
| 26 | 26 |
|
| 27 |
- $ sudo docker images |
|
| 27 |
+ $ docker images |
|
| 28 | 28 |
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE |
| 29 | 29 |
busybox latest 769b9341d937 7 weeks ago 2.489 MB |
| 30 |
- $ sudo docker load --input fedora.tar |
|
| 31 |
- $ sudo docker images |
|
| 30 |
+ $ docker load --input fedora.tar |
|
| 31 |
+ $ docker images |
|
| 32 | 32 |
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE |
| 33 | 33 |
busybox latest 769b9341d937 7 weeks ago 2.489 MB |
| 34 | 34 |
fedora rawhide 0d20aec6529d 7 weeks ago 387 MB |
| ... | ... |
@@ -29,7 +29,7 @@ It is also possible to specify a non-default registry to pull from. |
| 29 | 29 |
# Note that if the image is previously downloaded then the status would be |
| 30 | 30 |
# 'Status: Image is up to date for fedora' |
| 31 | 31 |
|
| 32 |
- $ sudo docker pull fedora |
|
| 32 |
+ $ docker pull fedora |
|
| 33 | 33 |
Pulling repository fedora |
| 34 | 34 |
ad57ef8d78d7: Download complete |
| 35 | 35 |
105182bb5e8b: Download complete |
| ... | ... |
@@ -38,7 +38,7 @@ It is also possible to specify a non-default registry to pull from. |
| 38 | 38 |
|
| 39 | 39 |
Status: Downloaded newer image for fedora |
| 40 | 40 |
|
| 41 |
- $ sudo docker images |
|
| 41 |
+ $ docker images |
|
| 42 | 42 |
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE |
| 43 | 43 |
fedora rawhide ad57ef8d78d7 5 days ago 359.3 MB |
| 44 | 44 |
fedora 20 105182bb5e8b 5 days ago 372.7 MB |
| ... | ... |
@@ -49,7 +49,7 @@ It is also possible to specify a non-default registry to pull from. |
| 49 | 49 |
# Note that if the image is previously downloaded then the status would be |
| 50 | 50 |
# 'Status: Image is up to date for registry.hub.docker.com/fedora:20' |
| 51 | 51 |
|
| 52 |
- $ sudo docker pull registry.hub.docker.com/fedora:20 |
|
| 52 |
+ $ docker pull registry.hub.docker.com/fedora:20 |
|
| 53 | 53 |
Pulling repository fedora |
| 54 | 54 |
3f2fed40e4b0: Download complete |
| 55 | 55 |
511136ea3c5a: Download complete |
| ... | ... |
@@ -57,7 +57,7 @@ It is also possible to specify a non-default registry to pull from. |
| 57 | 57 |
|
| 58 | 58 |
Status: Downloaded newer image for registry.hub.docker.com/fedora:20 |
| 59 | 59 |
|
| 60 |
- $ sudo docker images |
|
| 60 |
+ $ docker images |
|
| 61 | 61 |
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE |
| 62 | 62 |
fedora 20 3f2fed40e4b0 4 days ago 372.7 MB |
| 63 | 63 |
|
| ... | ... |
@@ -433,7 +433,7 @@ Host shows a shared memory segment with 7 pids attached, happens to be from http |
| 433 | 433 |
Now run a regular container, and it correctly does NOT see the shared memory segment from the host: |
| 434 | 434 |
|
| 435 | 435 |
``` |
| 436 |
- $ sudo docker run -it shm ipcs -m |
|
| 436 |
+ $ docker run -it shm ipcs -m |
|
| 437 | 437 |
|
| 438 | 438 |
------ Shared Memory Segments -------- |
| 439 | 439 |
key shmid owner perms bytes nattch status |
| ... | ... |
@@ -442,7 +442,7 @@ Now run a regular container, and it correctly does NOT see the shared memory seg |
| 442 | 442 |
Run a container with the new `--ipc=host` option, and it now sees the shared memory segment from the host httpd: |
| 443 | 443 |
|
| 444 | 444 |
``` |
| 445 |
- $ sudo docker run -it --ipc=host shm ipcs -m |
|
| 445 |
+ $ docker run -it --ipc=host shm ipcs -m |
|
| 446 | 446 |
|
| 447 | 447 |
------ Shared Memory Segments -------- |
| 448 | 448 |
key shmid owner perms bytes nattch status |
| ... | ... |
@@ -452,7 +452,7 @@ Testing `--ipc=container:CONTAINERID` mode: |
| 452 | 452 |
|
| 453 | 453 |
Start a container with a program to create a shared memory segment: |
| 454 | 454 |
``` |
| 455 |
- sudo docker run -it shm bash |
|
| 455 |
+ $ docker run -it shm bash |
|
| 456 | 456 |
$ sudo shm/shm_server & |
| 457 | 457 |
$ sudo ipcs -m |
| 458 | 458 |
|
| ... | ... |
@@ -462,7 +462,7 @@ Start a container with a program to create a shared memory segment: |
| 462 | 462 |
``` |
| 463 | 463 |
Create a 2nd container correctly shows no shared memory segment from 1st container: |
| 464 | 464 |
``` |
| 465 |
- $ sudo docker run shm ipcs -m |
|
| 465 |
+ $ docker run shm ipcs -m |
|
| 466 | 466 |
|
| 467 | 467 |
------ Shared Memory Segments -------- |
| 468 | 468 |
key shmid owner perms bytes nattch status |
| ... | ... |
@@ -471,7 +471,7 @@ Create a 2nd container correctly shows no shared memory segment from 1st contain |
| 471 | 471 |
Create a 3rd container using the new --ipc=container:CONTAINERID option, now it shows the shared memory segment from the first: |
| 472 | 472 |
|
| 473 | 473 |
``` |
| 474 |
- $ sudo docker run -it --ipc=container:ed735b2264ac shm ipcs -m |
|
| 474 |
+ $ docker run -it --ipc=container:ed735b2264ac shm ipcs -m |
|
| 475 | 475 |
$ sudo ipcs -m |
| 476 | 476 |
|
| 477 | 477 |
------ Shared Memory Segments -------- |
| ... | ... |
@@ -28,8 +28,8 @@ Stream to a file instead of STDOUT by using **-o**. |
| 28 | 28 |
Save all fedora repository images to a fedora-all.tar and save the latest |
| 29 | 29 |
fedora image to a fedora-latest.tar: |
| 30 | 30 |
|
| 31 |
- $ sudo docker save fedora > fedora-all.tar |
|
| 32 |
- $ sudo docker save --output=fedora-latest.tar fedora:latest |
|
| 31 |
+ $ docker save fedora > fedora-all.tar |
|
| 32 |
+ $ docker save --output=fedora-latest.tar fedora:latest |
|
| 33 | 33 |
$ ls -sh fedora-all.tar |
| 34 | 34 |
721M fedora-all.tar |
| 35 | 35 |
$ ls -sh fedora-latest.tar |
| ... | ... |
@@ -41,7 +41,7 @@ is automated. |
| 41 | 41 |
Search the registry for the term 'fedora' and only display those images |
| 42 | 42 |
ranked 3 or higher: |
| 43 | 43 |
|
| 44 |
- $ sudo docker search -s 3 fedora |
|
| 44 |
+ $ docker search -s 3 fedora |
|
| 45 | 45 |
NAME DESCRIPTION STARS OFFICIAL AUTOMATED |
| 46 | 46 |
mattdm/fedora A basic Fedora image corresponding roughly... 50 |
| 47 | 47 |
fedora (Semi) Official Fedora base image. 38 |
| ... | ... |
@@ -53,7 +53,7 @@ ranked 3 or higher: |
| 53 | 53 |
Search the registry for the term 'fedora' and only display automated images |
| 54 | 54 |
ranked 1 or higher: |
| 55 | 55 |
|
| 56 |
- $ sudo docker search -s 1 -t fedora |
|
| 56 |
+ $ docker search -s 1 -t fedora |
|
| 57 | 57 |
NAME DESCRIPTION STARS OFFICIAL AUTOMATED |
| 58 | 58 |
goldmann/wildfly A WildFly application server running on a ... 3 [OK] |
| 59 | 59 |
tutum/fedora-20 Fedora 20 image with SSH access. For the r... 1 [OK] |
| ... | ... |
@@ -21,7 +21,7 @@ Display a live stream of one or more containers' resource usage statistics |
| 21 | 21 |
|
| 22 | 22 |
Run **docker stats** with multiple containers. |
| 23 | 23 |
|
| 24 |
- $ sudo docker stats redis1 redis2 |
|
| 24 |
+ $ docker stats redis1 redis2 |
|
| 25 | 25 |
CONTAINER CPU % MEM USAGE/LIMIT MEM % NET I/O |
| 26 | 26 |
redis1 0.07% 796 KiB/64 MiB 1.21% 788 B/648 B |
| 27 | 27 |
redis2 0.07% 2.746 MiB/64 MiB 4.29% 1.266 KiB/648 B |
| ... | ... |
@@ -22,7 +22,7 @@ Look up the running process of the container. ps-OPTION can be any of the |
| 22 | 22 |
|
| 23 | 23 |
Run **docker top** with the ps option of -x: |
| 24 | 24 |
|
| 25 |
- $ sudo docker top 8601afda2b -x |
|
| 25 |
+ $ docker top 8601afda2b -x |
|
| 26 | 26 |
PID TTY STAT TIME COMMAND |
| 27 | 27 |
16623 ? Ss 0:00 sleep 99999 |
| 28 | 28 |
|
| ... | ... |
@@ -19,9 +19,9 @@ Block until a container stops, then print its exit code. |
| 19 | 19 |
|
| 20 | 20 |
# EXAMPLES |
| 21 | 21 |
|
| 22 |
- $ sudo docker run -d fedora sleep 99 |
|
| 22 |
+ $ docker run -d fedora sleep 99 |
|
| 23 | 23 |
079b83f558a2bc52ecad6b2a5de13622d584e6bb1aea058c11b36511e85e7622 |
| 24 |
- $ sudo docker wait 079b83f558a2bc |
|
| 24 |
+ $ docker wait 079b83f558a2bc |
|
| 25 | 25 |
0 |
| 26 | 26 |
|
| 27 | 27 |
# HISTORY |
| ... | ... |
@@ -34,23 +34,23 @@ controlled entirely from the `docker run` parameters. |
| 34 | 34 |
|
| 35 | 35 |
Start actual Redis server on one Docker host |
| 36 | 36 |
|
| 37 |
- big-server $ sudo docker run -d --name redis crosbymichael/redis |
|
| 37 |
+ big-server $ docker run -d --name redis crosbymichael/redis |
|
| 38 | 38 |
|
| 39 | 39 |
Then add an ambassador linked to the Redis server, mapping a port to the |
| 40 | 40 |
outside world |
| 41 | 41 |
|
| 42 |
- big-server $ sudo docker run -d --link redis:redis --name redis_ambassador -p 6379:6379 svendowideit/ambassador |
|
| 42 |
+ big-server $ docker run -d --link redis:redis --name redis_ambassador -p 6379:6379 svendowideit/ambassador |
|
| 43 | 43 |
|
| 44 | 44 |
On the other host, you can set up another ambassador setting environment |
| 45 | 45 |
variables for each remote port we want to proxy to the `big-server` |
| 46 | 46 |
|
| 47 |
- client-server $ sudo docker run -d --name redis_ambassador --expose 6379 -e REDIS_PORT_6379_TCP=tcp://192.168.1.52:6379 svendowideit/ambassador |
|
| 47 |
+ client-server $ docker run -d --name redis_ambassador --expose 6379 -e REDIS_PORT_6379_TCP=tcp://192.168.1.52:6379 svendowideit/ambassador |
|
| 48 | 48 |
|
| 49 | 49 |
Then on the `client-server` host, you can use a Redis client container |
| 50 | 50 |
to talk to the remote Redis server, just by linking to the local Redis |
| 51 | 51 |
ambassador. |
| 52 | 52 |
|
| 53 |
- client-server $ sudo docker run -i -t --rm --link redis_ambassador:redis relateiq/redis-cli |
|
| 53 |
+ client-server $ docker run -i -t --rm --link redis_ambassador:redis relateiq/redis-cli |
|
| 54 | 54 |
redis 172.17.0.160:6379> ping |
| 55 | 55 |
PONG |
| 56 | 56 |
|
| ... | ... |
@@ -62,19 +62,19 @@ does automatically (with a tiny amount of `sed`) |
| 62 | 62 |
On the Docker host (192.168.1.52) that Redis will run on: |
| 63 | 63 |
|
| 64 | 64 |
# start actual redis server |
| 65 |
- $ sudo docker run -d --name redis crosbymichael/redis |
|
| 65 |
+ $ docker run -d --name redis crosbymichael/redis |
|
| 66 | 66 |
|
| 67 | 67 |
# get a redis-cli container for connection testing |
| 68 |
- $ sudo docker pull relateiq/redis-cli |
|
| 68 |
+ $ docker pull relateiq/redis-cli |
|
| 69 | 69 |
|
| 70 | 70 |
# test the redis server by talking to it directly |
| 71 |
- $ sudo docker run -t -i --rm --link redis:redis relateiq/redis-cli |
|
| 71 |
+ $ docker run -t -i --rm --link redis:redis relateiq/redis-cli |
|
| 72 | 72 |
redis 172.17.0.136:6379> ping |
| 73 | 73 |
PONG |
| 74 | 74 |
^D |
| 75 | 75 |
|
| 76 | 76 |
# add redis ambassador |
| 77 |
- $ sudo docker run -t -i --link redis:redis --name redis_ambassador -p 6379:6379 busybox sh |
|
| 77 |
+ $ docker run -t -i --link redis:redis --name redis_ambassador -p 6379:6379 busybox sh |
|
| 78 | 78 |
|
| 79 | 79 |
In the `redis_ambassador` container, you can see the linked Redis |
| 80 | 80 |
containers `env`: |
| ... | ... |
@@ -96,9 +96,9 @@ containers `env`: |
| 96 | 96 |
This environment is used by the ambassador `socat` script to expose Redis |
| 97 | 97 |
to the world (via the `-p 6379:6379` port mapping): |
| 98 | 98 |
|
| 99 |
- $ sudo docker rm redis_ambassador |
|
| 99 |
+ $ docker rm redis_ambassador |
|
| 100 | 100 |
$ sudo ./contrib/mkimage-unittest.sh |
| 101 |
- $ sudo docker run -t -i --link redis:redis --name redis_ambassador -p 6379:6379 docker-ut sh |
|
| 101 |
+ $ docker run -t -i --link redis:redis --name redis_ambassador -p 6379:6379 docker-ut sh |
|
| 102 | 102 |
|
| 103 | 103 |
$ socat TCP4-LISTEN:6379,fork,reuseaddr TCP4:172.17.0.136:6379 |
| 104 | 104 |
|
| ... | ... |
@@ -107,14 +107,14 @@ Now ping the Redis server via the ambassador: |
| 107 | 107 |
Now go to a different server: |
| 108 | 108 |
|
| 109 | 109 |
$ sudo ./contrib/mkimage-unittest.sh |
| 110 |
- $ sudo docker run -t -i --expose 6379 --name redis_ambassador docker-ut sh |
|
| 110 |
+ $ docker run -t -i --expose 6379 --name redis_ambassador docker-ut sh |
|
| 111 | 111 |
|
| 112 | 112 |
$ socat TCP4-LISTEN:6379,fork,reuseaddr TCP4:192.168.1.52:6379 |
| 113 | 113 |
|
| 114 | 114 |
And get the `redis-cli` image so we can talk over the ambassador bridge. |
| 115 | 115 |
|
| 116 |
- $ sudo docker pull relateiq/redis-cli |
|
| 117 |
- $ sudo docker run -i -t --rm --link redis_ambassador:redis relateiq/redis-cli |
|
| 116 |
+ $ docker pull relateiq/redis-cli |
|
| 117 |
+ $ docker run -i -t --rm --link redis_ambassador:redis relateiq/redis-cli |
|
| 118 | 118 |
redis 172.17.0.160:6379> ping |
| 119 | 119 |
PONG |
| 120 | 120 |
|
| ... | ... |
@@ -22,9 +22,9 @@ use to build Ubuntu images. |
| 22 | 22 |
It can be as simple as this to create an Ubuntu base image: |
| 23 | 23 |
|
| 24 | 24 |
$ sudo debootstrap raring raring > /dev/null |
| 25 |
- $ sudo tar -C raring -c . | sudo docker import - raring |
|
| 25 |
+ $ sudo tar -C raring -c . | docker import - raring |
|
| 26 | 26 |
a29c15f1bf7a |
| 27 |
- $ sudo docker run raring cat /etc/lsb-release |
|
| 27 |
+ $ docker run raring cat /etc/lsb-release |
|
| 28 | 28 |
DISTRIB_ID=Ubuntu |
| 29 | 29 |
DISTRIB_RELEASE=13.04 |
| 30 | 30 |
DISTRIB_CODENAME=raring |
| ... | ... |
@@ -4,26 +4,30 @@ page_keywords: Examples, Usage, basic commands, docker, documentation, examples |
| 4 | 4 |
|
| 5 | 5 |
# First steps with Docker |
| 6 | 6 |
|
| 7 |
-## Check your Docker install |
|
| 8 |
- |
|
| 9 | 7 |
This guide assumes you have a working installation of Docker. To check |
| 10 | 8 |
your Docker install, run the following command: |
| 11 | 9 |
|
| 12 | 10 |
# Check that you have a working install |
| 13 |
- $ sudo docker info |
|
| 11 |
+ $ docker info |
|
| 14 | 12 |
|
| 15 | 13 |
If you get `docker: command not found` or something like |
| 16 | 14 |
`/var/lib/docker/repositories: permission denied` you may have an |
| 17 | 15 |
incomplete Docker installation or insufficient privileges to access |
| 18 |
-Docker on your machine. |
|
| 16 |
+Docker on your machine. Please |
|
| 17 |
+ |
|
| 18 |
+Additionally, depending on your Docker system configuration, you may be required |
|
| 19 |
+to preface each `docker` command with `sudo`. To avoid having to use `sudo` with |
|
| 20 |
+the `docker` command, your system administrator can create a Unix group called |
|
| 21 |
+`docker` and add users to it. |
|
| 22 |
+ |
|
| 23 |
+For more information about installing Docker or `sudo` configuration, refer to |
|
| 24 |
+the [installation](/installation) instructions for your operating system. |
|
| 19 | 25 |
|
| 20 |
-Please refer to [*Installation*](/installation) |
|
| 21 |
-for installation instructions. |
|
| 22 | 26 |
|
| 23 | 27 |
## Download a pre-built image |
| 24 | 28 |
|
| 25 | 29 |
# Download an ubuntu image |
| 26 |
- $ sudo docker pull ubuntu |
|
| 30 |
+ $ docker pull ubuntu |
|
| 27 | 31 |
|
| 28 | 32 |
This will find the `ubuntu` image by name on |
| 29 | 33 |
[*Docker Hub*](/userguide/dockerrepos/#searching-for-images) |
| ... | ... |
@@ -46,7 +50,7 @@ image cache. |
| 46 | 46 |
# To detach the tty without exiting the shell, |
| 47 | 47 |
# use the escape sequence Ctrl-p + Ctrl-q |
| 48 | 48 |
# note: This will continue to exist in a stopped state once exited (see "docker ps -a") |
| 49 |
- $ sudo docker run -i -t ubuntu /bin/bash |
|
| 49 |
+ $ docker run -i -t ubuntu /bin/bash |
|
| 50 | 50 |
|
| 51 | 51 |
## Bind Docker to another host/port or a Unix socket |
| 52 | 52 |
|
| ... | ... |
@@ -92,7 +96,7 @@ Run Docker in daemon mode: |
| 92 | 92 |
|
| 93 | 93 |
Download an `ubuntu` image: |
| 94 | 94 |
|
| 95 |
- $ sudo docker -H :5555 pull ubuntu |
|
| 95 |
+ $ docker -H :5555 pull ubuntu |
|
| 96 | 96 |
|
| 97 | 97 |
You can use multiple `-H`, for example, if you want to listen on both |
| 98 | 98 |
TCP and a Unix socket |
| ... | ... |
@@ -100,60 +104,60 @@ TCP and a Unix socket |
| 100 | 100 |
# Run docker in daemon mode |
| 101 | 101 |
$ sudo <path to>/docker -H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock -d & |
| 102 | 102 |
# Download an ubuntu image, use default Unix socket |
| 103 |
- $ sudo docker pull ubuntu |
|
| 103 |
+ $ docker pull ubuntu |
|
| 104 | 104 |
# OR use the TCP port |
| 105 |
- $ sudo docker -H tcp://127.0.0.1:2375 pull ubuntu |
|
| 105 |
+ $ docker -H tcp://127.0.0.1:2375 pull ubuntu |
|
| 106 | 106 |
|
| 107 | 107 |
## Starting a long-running worker process |
| 108 | 108 |
|
| 109 | 109 |
# Start a very useful long-running process |
| 110 |
- $ JOB=$(sudo docker run -d ubuntu /bin/sh -c "while true; do echo Hello world; sleep 1; done") |
|
| 110 |
+ $ JOB=$(docker run -d ubuntu /bin/sh -c "while true; do echo Hello world; sleep 1; done") |
|
| 111 | 111 |
|
| 112 | 112 |
# Collect the output of the job so far |
| 113 |
- $ sudo docker logs $JOB |
|
| 113 |
+ $ docker logs $JOB |
|
| 114 | 114 |
|
| 115 | 115 |
# Kill the job |
| 116 |
- $ sudo docker kill $JOB |
|
| 116 |
+ $ docker kill $JOB |
|
| 117 | 117 |
|
| 118 | 118 |
## Listing containers |
| 119 | 119 |
|
| 120 |
- $ sudo docker ps # Lists only running containers |
|
| 121 |
- $ sudo docker ps -a # Lists all containers |
|
| 120 |
+ $ docker ps # Lists only running containers |
|
| 121 |
+ $ docker ps -a # Lists all containers |
|
| 122 | 122 |
|
| 123 | 123 |
## Controlling containers |
| 124 | 124 |
|
| 125 | 125 |
# Start a new container |
| 126 |
- $ JOB=$(sudo docker run -d ubuntu /bin/sh -c "while true; do echo Hello world; sleep 1; done") |
|
| 126 |
+ $ JOB=$(docker run -d ubuntu /bin/sh -c "while true; do echo Hello world; sleep 1; done") |
|
| 127 | 127 |
|
| 128 | 128 |
# Stop the container |
| 129 |
- $ sudo docker stop $JOB |
|
| 129 |
+ $ docker stop $JOB |
|
| 130 | 130 |
|
| 131 | 131 |
# Start the container |
| 132 |
- $ sudo docker start $JOB |
|
| 132 |
+ $ docker start $JOB |
|
| 133 | 133 |
|
| 134 | 134 |
# Restart the container |
| 135 |
- $ sudo docker restart $JOB |
|
| 135 |
+ $ docker restart $JOB |
|
| 136 | 136 |
|
| 137 | 137 |
# SIGKILL a container |
| 138 |
- $ sudo docker kill $JOB |
|
| 138 |
+ $ docker kill $JOB |
|
| 139 | 139 |
|
| 140 | 140 |
# Remove a container |
| 141 |
- $ sudo docker stop $JOB # Container must be stopped to remove it |
|
| 142 |
- $ sudo docker rm $JOB |
|
| 141 |
+ $ docker stop $JOB # Container must be stopped to remove it |
|
| 142 |
+ $ docker rm $JOB |
|
| 143 | 143 |
|
| 144 | 144 |
## Bind a service on a TCP port |
| 145 | 145 |
|
| 146 | 146 |
# Bind port 4444 of this container, and tell netcat to listen on it |
| 147 |
- $ JOB=$(sudo docker run -d -p 4444 ubuntu:12.10 /bin/nc -l 4444) |
|
| 147 |
+ $ JOB=$(docker run -d -p 4444 ubuntu:12.10 /bin/nc -l 4444) |
|
| 148 | 148 |
|
| 149 | 149 |
# Which public port is NATed to my container? |
| 150 |
- $ PORT=$(sudo docker port $JOB 4444 | awk -F: '{ print $2 }')
|
|
| 150 |
+ $ PORT=$(docker port $JOB 4444 | awk -F: '{ print $2 }')
|
|
| 151 | 151 |
|
| 152 | 152 |
# Connect to the public port |
| 153 | 153 |
$ echo hello world | nc 127.0.0.1 $PORT |
| 154 | 154 |
|
| 155 | 155 |
# Verify that the network connection worked |
| 156 |
- $ echo "Daemon received: $(sudo docker logs $JOB)" |
|
| 156 |
+ $ echo "Daemon received: $(docker logs $JOB)" |
|
| 157 | 157 |
|
| 158 | 158 |
## Committing (saving) a container state |
| 159 | 159 |
|
| ... | ... |
@@ -166,10 +170,10 @@ will be stored (as a diff). See which images you already have using the |
| 166 | 166 |
`docker images` command. |
| 167 | 167 |
|
| 168 | 168 |
# Commit your container to a new named image |
| 169 |
- $ sudo docker commit <container_id> <some_name> |
|
| 169 |
+ $ docker commit <container_id> <some_name> |
|
| 170 | 170 |
|
| 171 | 171 |
# List your containers |
| 172 |
- $ sudo docker images |
|
| 172 |
+ $ docker images |
|
| 173 | 173 |
|
| 174 | 174 |
You now have an image state from which you can create new instances. |
| 175 | 175 |
|
| ... | ... |
@@ -94,7 +94,7 @@ your image with the docker build command, e.g., |
| 94 | 94 |
Start the container with `apache2` and `sshd` running and managed, forwarding |
| 95 | 95 |
a port to our SSH instance: |
| 96 | 96 |
|
| 97 |
- $ sudo docker run -p 127.0.0.1:222:22 -d managed_image "/usr/sbin/sshd" "/etc/init.d/apache2 start" |
|
| 97 |
+ $ docker run -p 127.0.0.1:222:22 -d managed_image "/usr/sbin/sshd" "/etc/init.d/apache2 start" |
|
| 98 | 98 |
|
| 99 | 99 |
We now clearly see one of the benefits of the cfe-docker integration: it |
| 100 | 100 |
allows to start several processes as part of a normal `docker run` command. |
| ... | ... |
@@ -43,7 +43,7 @@ The next step is to pull a Docker image. For this, we have a resource: |
| 43 | 43 |
|
| 44 | 44 |
This is equivalent to running: |
| 45 | 45 |
|
| 46 |
- $ sudo docker pull samalba/docker-registry |
|
| 46 |
+ $ docker pull samalba/docker-registry |
|
| 47 | 47 |
|
| 48 | 48 |
There are attributes available to control how long the cookbook will |
| 49 | 49 |
allow for downloading (5 minute default). |
| ... | ... |
@@ -68,7 +68,7 @@ managed by Docker. |
| 68 | 68 |
|
| 69 | 69 |
This is equivalent to running the following command, but under upstart: |
| 70 | 70 |
|
| 71 |
- $ sudo docker run --detach=true --publish='5000:5000' --env='SETTINGS_FLAVOR=local' --volume='/mnt/docker:/docker-storage' samalba/docker-registry |
|
| 71 |
+ $ docker run --detach=true --publish='5000:5000' --env='SETTINGS_FLAVOR=local' --volume='/mnt/docker:/docker-storage' samalba/docker-registry |
|
| 72 | 72 |
|
| 73 | 73 |
The resources will accept a single string or an array of values for any |
| 74 | 74 |
Docker flags that allow multiple values. |
| ... | ... |
@@ -723,7 +723,7 @@ the Internet. |
| 723 | 723 |
|
| 724 | 724 |
# The network, as seen from a container |
| 725 | 725 |
|
| 726 |
- $ sudo docker run -i -t --rm base /bin/bash |
|
| 726 |
+ $ docker run -i -t --rm base /bin/bash |
|
| 727 | 727 |
|
| 728 | 728 |
$$ ip addr show eth0 |
| 729 | 729 |
24: eth0: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 |
| ... | ... |
@@ -908,14 +908,14 @@ Docker do all of the configuration: |
| 908 | 908 |
# At one shell, start a container and |
| 909 | 909 |
# leave its shell idle and running |
| 910 | 910 |
|
| 911 |
- $ sudo docker run -i -t --rm --net=none base /bin/bash |
|
| 911 |
+ $ docker run -i -t --rm --net=none base /bin/bash |
|
| 912 | 912 |
root@63f36fc01b5f:/# |
| 913 | 913 |
|
| 914 | 914 |
# At another shell, learn the container process ID |
| 915 | 915 |
# and create its namespace entry in /var/run/netns/ |
| 916 | 916 |
# for the "ip netns" command we will be using below |
| 917 | 917 |
|
| 918 |
- $ sudo docker inspect -f '{{.State.Pid}}' 63f36fc01b5f
|
|
| 918 |
+ $ docker inspect -f '{{.State.Pid}}' 63f36fc01b5f
|
|
| 919 | 919 |
2778 |
| 920 | 920 |
$ pid=2778 |
| 921 | 921 |
$ sudo mkdir -p /var/run/netns |
| ... | ... |
@@ -1016,18 +1016,18 @@ the previous section to go something like this: |
| 1016 | 1016 |
|
| 1017 | 1017 |
# Start up two containers in two terminal windows |
| 1018 | 1018 |
|
| 1019 |
- $ sudo docker run -i -t --rm --net=none base /bin/bash |
|
| 1019 |
+ $ docker run -i -t --rm --net=none base /bin/bash |
|
| 1020 | 1020 |
root@1f1f4c1f931a:/# |
| 1021 | 1021 |
|
| 1022 |
- $ sudo docker run -i -t --rm --net=none base /bin/bash |
|
| 1022 |
+ $ docker run -i -t --rm --net=none base /bin/bash |
|
| 1023 | 1023 |
root@12e343489d2f:/# |
| 1024 | 1024 |
|
| 1025 | 1025 |
# Learn the container process IDs |
| 1026 | 1026 |
# and create their namespace entries |
| 1027 | 1027 |
|
| 1028 |
- $ sudo docker inspect -f '{{.State.Pid}}' 1f1f4c1f931a
|
|
| 1028 |
+ $ docker inspect -f '{{.State.Pid}}' 1f1f4c1f931a
|
|
| 1029 | 1029 |
2989 |
| 1030 |
- $ sudo docker inspect -f '{{.State.Pid}}' 12e343489d2f
|
|
| 1030 |
+ $ docker inspect -f '{{.State.Pid}}' 12e343489d2f
|
|
| 1031 | 1031 |
3004 |
| 1032 | 1032 |
$ sudo mkdir -p /var/run/netns |
| 1033 | 1033 |
$ sudo ln -s /proc/2989/ns/net /var/run/netns/2989 |
| ... | ... |
@@ -47,7 +47,7 @@ defined type which can be used like so: |
| 47 | 47 |
|
| 48 | 48 |
This is equivalent to running: |
| 49 | 49 |
|
| 50 |
- $ sudo docker pull ubuntu |
|
| 50 |
+ $ docker pull ubuntu |
|
| 51 | 51 |
|
| 52 | 52 |
Note that it will only be downloaded if an image of that name does not |
| 53 | 53 |
already exist. This is downloading a large binary so on first run can |
| ... | ... |
@@ -71,7 +71,7 @@ managed by Docker. |
| 71 | 71 |
|
| 72 | 72 |
This is equivalent to running the following command, but under upstart: |
| 73 | 73 |
|
| 74 |
- $ sudo docker run -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done" |
|
| 74 |
+ $ docker run -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done" |
|
| 75 | 75 |
|
| 76 | 76 |
Run also contains a number of optional parameters: |
| 77 | 77 |
|
| ... | ... |
@@ -29,11 +29,11 @@ There are two steps to set up and use a local registry mirror. |
| 29 | 29 |
You will need to pass the `--registry-mirror` option to your Docker daemon on |
| 30 | 30 |
startup: |
| 31 | 31 |
|
| 32 |
- sudo docker --registry-mirror=http://<my-docker-mirror-host> -d |
|
| 32 |
+ docker --registry-mirror=http://<my-docker-mirror-host> -d |
|
| 33 | 33 |
|
| 34 | 34 |
For example, if your mirror is serving on `http://10.0.0.2:5000`, you would run: |
| 35 | 35 |
|
| 36 |
- sudo docker --registry-mirror=http://10.0.0.2:5000 -d |
|
| 36 |
+ docker --registry-mirror=http://10.0.0.2:5000 -d |
|
| 37 | 37 |
|
| 38 | 38 |
**NOTE:** |
| 39 | 39 |
Depending on your local host setup, you may be able to add the |
| ... | ... |
@@ -47,7 +47,7 @@ You will need to start a local registry mirror service. The |
| 47 | 47 |
functionality. For example, to run a local registry mirror that serves on |
| 48 | 48 |
port `5000` and mirrors the content at `registry-1.docker.io`: |
| 49 | 49 |
|
| 50 |
- sudo docker run -p 5000:5000 \ |
|
| 50 |
+ docker run -p 5000:5000 \ |
|
| 51 | 51 |
-e STANDALONE=false \ |
| 52 | 52 |
-e MIRROR_SOURCE=https://registry-1.docker.io \ |
| 53 | 53 |
-e MIRROR_SOURCE_INDEX=https://index.docker.io \ |
| ... | ... |
@@ -58,7 +58,7 @@ port `5000` and mirrors the content at `registry-1.docker.io`: |
| 58 | 58 |
With your mirror running, pull an image that you haven't pulled before (using |
| 59 | 59 |
`time` to time it): |
| 60 | 60 |
|
| 61 |
- $ time sudo docker pull node:latest |
|
| 61 |
+ $ time docker pull node:latest |
|
| 62 | 62 |
Pulling repository node |
| 63 | 63 |
[...] |
| 64 | 64 |
|
| ... | ... |
@@ -68,11 +68,11 @@ With your mirror running, pull an image that you haven't pulled before (using |
| 68 | 68 |
|
| 69 | 69 |
Now, remove the image from your local machine: |
| 70 | 70 |
|
| 71 |
- $ sudo docker rmi node:latest |
|
| 71 |
+ $ docker rmi node:latest |
|
| 72 | 72 |
|
| 73 | 73 |
Finally, re-pull the image: |
| 74 | 74 |
|
| 75 |
- $ time sudo docker pull node:latest |
|
| 75 |
+ $ time docker pull node:latest |
|
| 76 | 76 |
Pulling repository node |
| 77 | 77 |
[...] |
| 78 | 78 |
|
| ... | ... |
@@ -91,13 +91,13 @@ launches. |
| 91 | 91 |
|
| 92 | 92 |
We can now build our new image. |
| 93 | 93 |
|
| 94 |
- $ sudo docker build -t <yourname>/supervisord . |
|
| 94 |
+ $ docker build -t <yourname>/supervisord . |
|
| 95 | 95 |
|
| 96 | 96 |
## Running our Supervisor container |
| 97 | 97 |
|
| 98 | 98 |
Once We've got a built image we can launch a container from it. |
| 99 | 99 |
|
| 100 |
- $ sudo docker run -p 22 -p 80 -t -i <yourname>/supervisord |
|
| 100 |
+ $ docker run -p 22 -p 80 -t -i <yourname>/supervisord |
|
| 101 | 101 |
2013-11-25 18:53:22,312 CRIT Supervisor running as root (no user in config file) |
| 102 | 102 |
2013-11-25 18:53:22,312 WARN Included extra file "/etc/supervisor/conf.d/supervisord.conf" during parsing |
| 103 | 103 |
2013-11-25 18:53:22,342 INFO supervisord started with pid 1 |
| ... | ... |
@@ -11,7 +11,7 @@ page_keywords: Docker, docker, registry, accounts, plans, Dockerfile, Docker Hub |
| 11 | 11 |
You can `search` for all the publicly available repositories and images using |
| 12 | 12 |
Docker. |
| 13 | 13 |
|
| 14 |
- $ sudo docker search ubuntu |
|
| 14 |
+ $ docker search ubuntu |
|
| 15 | 15 |
|
| 16 | 16 |
This will show you a list of the currently available repositories on the |
| 17 | 17 |
Docker Hub which match the provided keyword. |
| ... | ... |
@@ -35,16 +35,16 @@ Use the following Dockerfile: |
| 35 | 35 |
|
| 36 | 36 |
To build the image using: |
| 37 | 37 |
|
| 38 |
- $ sudo docker build -t eg_apt_cacher_ng . |
|
| 38 |
+ $ docker build -t eg_apt_cacher_ng . |
|
| 39 | 39 |
|
| 40 | 40 |
Then run it, mapping the exposed port to one on the host |
| 41 | 41 |
|
| 42 |
- $ sudo docker run -d -p 3142:3142 --name test_apt_cacher_ng eg_apt_cacher_ng |
|
| 42 |
+ $ docker run -d -p 3142:3142 --name test_apt_cacher_ng eg_apt_cacher_ng |
|
| 43 | 43 |
|
| 44 | 44 |
To see the logfiles that are `tailed` in the default command, you can |
| 45 | 45 |
use: |
| 46 | 46 |
|
| 47 |
- $ sudo docker logs -f test_apt_cacher_ng |
|
| 47 |
+ $ docker logs -f test_apt_cacher_ng |
|
| 48 | 48 |
|
| 49 | 49 |
To get your Debian-based containers to use the proxy, you can do one of |
| 50 | 50 |
three things |
| ... | ... |
@@ -68,7 +68,7 @@ a local version of a common base: |
| 68 | 68 |
**Option 2** is good for testing, but will break other HTTP clients |
| 69 | 69 |
which obey `http_proxy`, such as `curl`, `wget` and others: |
| 70 | 70 |
|
| 71 |
- $ sudo docker run --rm -t -i -e http_proxy=http://dockerhost:3142/ debian bash |
|
| 71 |
+ $ docker run --rm -t -i -e http_proxy=http://dockerhost:3142/ debian bash |
|
| 72 | 72 |
|
| 73 | 73 |
**Option 3** is the least portable, but there will be times when you |
| 74 | 74 |
might need to do it and you can do it from your `Dockerfile` |
| ... | ... |
@@ -78,7 +78,7 @@ Apt-cacher-ng has some tools that allow you to manage the repository, |
| 78 | 78 |
and they can be used by leveraging the `VOLUME` |
| 79 | 79 |
instruction, and the image we built to run the service: |
| 80 | 80 |
|
| 81 |
- $ sudo docker run --rm -t -i --volumes-from test_apt_cacher_ng eg_apt_cacher_ng bash |
|
| 81 |
+ $ docker run --rm -t -i --volumes-from test_apt_cacher_ng eg_apt_cacher_ng bash |
|
| 82 | 82 |
|
| 83 | 83 |
$$ /usr/lib/apt-cacher-ng/distkill.pl |
| 84 | 84 |
Scanning /var/cache/apt-cacher-ng, please wait... |
| ... | ... |
@@ -102,6 +102,6 @@ instruction, and the image we built to run the service: |
| 102 | 102 |
Finally, clean up after your test by stopping and removing the |
| 103 | 103 |
container, and then removing the image. |
| 104 | 104 |
|
| 105 |
- $ sudo docker stop test_apt_cacher_ng |
|
| 106 |
- $ sudo docker rm test_apt_cacher_ng |
|
| 107 |
- $ sudo docker rmi eg_apt_cacher_ng |
|
| 105 |
+ $ docker stop test_apt_cacher_ng |
|
| 106 |
+ $ docker rm test_apt_cacher_ng |
|
| 107 |
+ $ docker rmi eg_apt_cacher_ng |
| ... | ... |
@@ -16,7 +16,7 @@ different versions of CouchDB on the same data, etc. |
| 16 | 16 |
|
| 17 | 17 |
Note that we're marking `/var/lib/couchdb` as a data volume. |
| 18 | 18 |
|
| 19 |
- $ COUCH1=$(sudo docker run -d -p 5984 -v /var/lib/couchdb shykes/couchdb:2013-05-03) |
|
| 19 |
+ $ COUCH1=$(docker run -d -p 5984 -v /var/lib/couchdb shykes/couchdb:2013-05-03) |
|
| 20 | 20 |
|
| 21 | 21 |
## Add data to the first database |
| 22 | 22 |
|
| ... | ... |
@@ -24,19 +24,19 @@ We're assuming your Docker host is reachable at `localhost`. If not, |
| 24 | 24 |
replace `localhost` with the public IP of your Docker host. |
| 25 | 25 |
|
| 26 | 26 |
$ HOST=localhost |
| 27 |
- $ URL="http://$HOST:$(sudo docker port $COUCH1 5984 | grep -o '[1-9][0-9]*$')/_utils/" |
|
| 27 |
+ $ URL="http://$HOST:$(docker port $COUCH1 5984 | grep -o '[1-9][0-9]*$')/_utils/" |
|
| 28 | 28 |
$ echo "Navigate to $URL in your browser, and use the couch interface to add data" |
| 29 | 29 |
|
| 30 | 30 |
## Create second database |
| 31 | 31 |
|
| 32 | 32 |
This time, we're requesting shared access to `$COUCH1`'s volumes. |
| 33 | 33 |
|
| 34 |
- $ COUCH2=$(sudo docker run -d -p 5984 --volumes-from $COUCH1 shykes/couchdb:2013-05-03) |
|
| 34 |
+ $ COUCH2=$(docker run -d -p 5984 --volumes-from $COUCH1 shykes/couchdb:2013-05-03) |
|
| 35 | 35 |
|
| 36 | 36 |
## Browse data on the second database |
| 37 | 37 |
|
| 38 | 38 |
$ HOST=localhost |
| 39 |
- $ URL="http://$HOST:$(sudo docker port $COUCH2 5984 | grep -o '[1-9][0-9]*$')/_utils/" |
|
| 39 |
+ $ URL="http://$HOST:$(docker port $COUCH2 5984 | grep -o '[1-9][0-9]*$')/_utils/" |
|
| 40 | 40 |
$ echo "Navigate to $URL in your browser. You should see the same data as in the first database"'!' |
| 41 | 41 |
|
| 42 | 42 |
Congratulations, you are now running two Couchdb containers, completely |
| ... | ... |
@@ -100,9 +100,9 @@ With our `Dockerfile`, we can now build the MongoDB image using Docker. Unless |
| 100 | 100 |
experimenting, it is always a good practice to tag Docker images by passing the |
| 101 | 101 |
`--tag` option to `docker build` command. |
| 102 | 102 |
|
| 103 |
- # Format: sudo docker build --tag/-t <user-name>/<repository> . |
|
| 103 |
+ # Format: docker build --tag/-t <user-name>/<repository> . |
|
| 104 | 104 |
# Example: |
| 105 |
- $ sudo docker build --tag my/repo . |
|
| 105 |
+ $ docker build --tag my/repo . |
|
| 106 | 106 |
|
| 107 | 107 |
Once this command is issued, Docker will go through the `Dockerfile` and build |
| 108 | 108 |
the image. The final image will be tagged `my/repo`. |
| ... | ... |
@@ -114,13 +114,13 @@ All Docker image repositories can be hosted and shared on |
| 114 | 114 |
you need to be logged-in. |
| 115 | 115 |
|
| 116 | 116 |
# Log-in |
| 117 |
- $ sudo docker login |
|
| 117 |
+ $ docker login |
|
| 118 | 118 |
Username: |
| 119 | 119 |
.. |
| 120 | 120 |
|
| 121 | 121 |
# Push the image |
| 122 |
- # Format: sudo docker push <user-name>/<repository> |
|
| 123 |
- $ sudo docker push my/repo |
|
| 122 |
+ # Format: docker push <user-name>/<repository> |
|
| 123 |
+ $ docker push my/repo |
|
| 124 | 124 |
The push refers to a repository [my/repo] (len: 1) |
| 125 | 125 |
Sending image list |
| 126 | 126 |
Pushing repository my/repo (1 tags) |
| ... | ... |
@@ -132,16 +132,16 @@ Using the MongoDB image we created, we can run one or more MongoDB instances |
| 132 | 132 |
as daemon process(es). |
| 133 | 133 |
|
| 134 | 134 |
# Basic way |
| 135 |
- # Usage: sudo docker run --name <name for container> -d <user-name>/<repository> |
|
| 136 |
- $ sudo docker run --name mongo_instance_001 -d my/repo |
|
| 135 |
+ # Usage: docker run --name <name for container> -d <user-name>/<repository> |
|
| 136 |
+ $ docker run --name mongo_instance_001 -d my/repo |
|
| 137 | 137 |
|
| 138 | 138 |
# Dockerized MongoDB, lean and mean! |
| 139 |
- # Usage: sudo docker run --name <name for container> -d <user-name>/<repository> --noprealloc --smallfiles |
|
| 140 |
- $ sudo docker run --name mongo_instance_001 -d my/repo --noprealloc --smallfiles |
|
| 139 |
+ # Usage: docker run --name <name for container> -d <user-name>/<repository> --noprealloc --smallfiles |
|
| 140 |
+ $ docker run --name mongo_instance_001 -d my/repo --noprealloc --smallfiles |
|
| 141 | 141 |
|
| 142 | 142 |
# Checking out the logs of a MongoDB container |
| 143 |
- # Usage: sudo docker logs <name for container> |
|
| 144 |
- $ sudo docker logs mongo_instance_001 |
|
| 143 |
+ # Usage: docker logs <name for container> |
|
| 144 |
+ $ docker logs mongo_instance_001 |
|
| 145 | 145 |
|
| 146 | 146 |
# Playing with MongoDB |
| 147 | 147 |
# Usage: mongo --port <port you get from `docker ps`> |
| ... | ... |
@@ -125,11 +125,11 @@ Go to the directory that has your `Dockerfile` and run the following command |
| 125 | 125 |
to build a Docker image. The `-t` flag lets you tag your image so it's easier |
| 126 | 126 |
to find later using the `docker images` command: |
| 127 | 127 |
|
| 128 |
- $ sudo docker build -t <your username>/centos-node-hello . |
|
| 128 |
+ $ docker build -t <your username>/centos-node-hello . |
|
| 129 | 129 |
|
| 130 | 130 |
Your image will now be listed by Docker: |
| 131 | 131 |
|
| 132 |
- $ sudo docker images |
|
| 132 |
+ $ docker images |
|
| 133 | 133 |
|
| 134 | 134 |
# Example |
| 135 | 135 |
REPOSITORY TAG ID CREATED |
| ... | ... |
@@ -142,15 +142,15 @@ Running your image with `-d` runs the container in detached mode, leaving the |
| 142 | 142 |
container running in the background. The `-p` flag redirects a public port to |
| 143 | 143 |
a private port in the container. Run the image you previously built: |
| 144 | 144 |
|
| 145 |
- $ sudo docker run -p 49160:8080 -d <your username>/centos-node-hello |
|
| 145 |
+ $ docker run -p 49160:8080 -d <your username>/centos-node-hello |
|
| 146 | 146 |
|
| 147 | 147 |
Print the output of your app: |
| 148 | 148 |
|
| 149 | 149 |
# Get container ID |
| 150 |
- $ sudo docker ps |
|
| 150 |
+ $ docker ps |
|
| 151 | 151 |
|
| 152 | 152 |
# Print app output |
| 153 |
- $ sudo docker logs <container id> |
|
| 153 |
+ $ docker logs <container id> |
|
| 154 | 154 |
|
| 155 | 155 |
# Example |
| 156 | 156 |
Running on http://localhost:8080 |
| ... | ... |
@@ -159,7 +159,7 @@ Print the output of your app: |
| 159 | 159 |
|
| 160 | 160 |
To test your app, get the port of your app that Docker mapped: |
| 161 | 161 |
|
| 162 |
- $ sudo docker ps |
|
| 162 |
+ $ docker ps |
|
| 163 | 163 |
|
| 164 | 164 |
# Example |
| 165 | 165 |
ID IMAGE COMMAND ... PORTS |
| ... | ... |
@@ -72,11 +72,11 @@ Start by creating a new `Dockerfile`: |
| 72 | 72 |
|
| 73 | 73 |
Build an image from the Dockerfile assign it a name. |
| 74 | 74 |
|
| 75 |
- $ sudo docker build -t eg_postgresql . |
|
| 75 |
+ $ docker build -t eg_postgresql . |
|
| 76 | 76 |
|
| 77 | 77 |
And run the PostgreSQL server container (in the foreground): |
| 78 | 78 |
|
| 79 |
- $ sudo docker run --rm -P --name pg_test eg_postgresql |
|
| 79 |
+ $ docker run --rm -P --name pg_test eg_postgresql |
|
| 80 | 80 |
|
| 81 | 81 |
There are 2 ways to connect to the PostgreSQL server. We can use [*Link |
| 82 | 82 |
Containers*](/userguide/dockerlinks), or we can access it from our host |
| ... | ... |
@@ -93,7 +93,7 @@ Containers can be linked to another container's ports directly using |
| 93 | 93 |
`docker run`. This will set a number of environment |
| 94 | 94 |
variables that can then be used to connect: |
| 95 | 95 |
|
| 96 |
- $ sudo docker run --rm -t -i --link pg_test:pg eg_postgresql bash |
|
| 96 |
+ $ docker run --rm -t -i --link pg_test:pg eg_postgresql bash |
|
| 97 | 97 |
|
| 98 | 98 |
postgres@7ef98b1b7243:/$ psql -h $PG_PORT_5432_TCP_ADDR -p $PG_PORT_5432_TCP_PORT -d docker -U docker --password |
| 99 | 99 |
|
| ... | ... |
@@ -104,7 +104,7 @@ host-mapped port to test as well. You need to use `docker ps` |
| 104 | 104 |
to find out what local host port the container is mapped to |
| 105 | 105 |
first: |
| 106 | 106 |
|
| 107 |
- $ sudo docker ps |
|
| 107 |
+ $ docker ps |
|
| 108 | 108 |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
| 109 | 109 |
5e24362f27f6 eg_postgresql:latest /usr/lib/postgresql/ About an hour ago Up About an hour 0.0.0.0:49153->5432/tcp pg_test |
| 110 | 110 |
$ psql -h localhost -p 49153 -d docker -U docker --password |
| ... | ... |
@@ -135,7 +135,7 @@ prompt, you can create a table and populate it. |
| 135 | 135 |
You can use the defined volumes to inspect the PostgreSQL log files and |
| 136 | 136 |
to backup your configuration and data: |
| 137 | 137 |
|
| 138 |
- $ sudo docker run --rm --volumes-from pg_test -t -i busybox sh |
|
| 138 |
+ $ docker run --rm --volumes-from pg_test -t -i busybox sh |
|
| 139 | 139 |
|
| 140 | 140 |
/ # ls |
| 141 | 141 |
bin etc lib linuxrc mnt proc run sys usr |
| ... | ... |
@@ -20,7 +20,7 @@ image. |
| 20 | 20 |
Next we build an image from our `Dockerfile`. |
| 21 | 21 |
Replace `<your username>` with your own user name. |
| 22 | 22 |
|
| 23 |
- $ sudo docker build -t <your username>/redis . |
|
| 23 |
+ $ docker build -t <your username>/redis . |
|
| 24 | 24 |
|
| 25 | 25 |
## Run the service |
| 26 | 26 |
|
| ... | ... |
@@ -33,7 +33,7 @@ Importantly, we're not exposing any ports on our container. Instead |
| 33 | 33 |
we're going to use a container link to provide access to our Redis |
| 34 | 34 |
database. |
| 35 | 35 |
|
| 36 |
- $ sudo docker run --name redis -d <your username>/redis |
|
| 36 |
+ $ docker run --name redis -d <your username>/redis |
|
| 37 | 37 |
|
| 38 | 38 |
## Create your web application container |
| 39 | 39 |
|
| ... | ... |
@@ -43,7 +43,7 @@ created with an alias of `db`. This will create a secure tunnel to the |
| 43 | 43 |
`redis` container and expose the Redis instance running inside that |
| 44 | 44 |
container to only this container. |
| 45 | 45 |
|
| 46 |
- $ sudo docker run --link redis:db -i -t ubuntu:14.04 /bin/bash |
|
| 46 |
+ $ docker run --link redis:db -i -t ubuntu:14.04 /bin/bash |
|
| 47 | 47 |
|
| 48 | 48 |
Once inside our freshly created container we need to install Redis to |
| 49 | 49 |
get the `redis-cli` binary to test our connection. |
| ... | ... |
@@ -33,15 +33,15 @@ quick access to a test container. |
| 33 | 33 |
|
| 34 | 34 |
Build the image using: |
| 35 | 35 |
|
| 36 |
- $ sudo docker build -t eg_sshd . |
|
| 36 |
+ $ docker build -t eg_sshd . |
|
| 37 | 37 |
|
| 38 | 38 |
## Run a `test_sshd` container |
| 39 | 39 |
|
| 40 | 40 |
Then run it. You can then use `docker port` to find out what host port |
| 41 | 41 |
the container's port 22 is mapped to: |
| 42 | 42 |
|
| 43 |
- $ sudo docker run -d -P --name test_sshd eg_sshd |
|
| 44 |
- $ sudo docker port test_sshd 22 |
|
| 43 |
+ $ docker run -d -P --name test_sshd eg_sshd |
|
| 44 |
+ $ docker port test_sshd 22 |
|
| 45 | 45 |
0.0.0.0:49154 |
| 46 | 46 |
|
| 47 | 47 |
And now you can ssh as `root` on the container's IP address (you can find it |
| ... | ... |
@@ -72,7 +72,7 @@ short script to do the same before you start `sshd -D` and then replace the |
| 72 | 72 |
Finally, clean up after your test by stopping and removing the |
| 73 | 73 |
container, and then removing the image. |
| 74 | 74 |
|
| 75 |
- $ sudo docker stop test_sshd |
|
| 76 |
- $ sudo docker rm test_sshd |
|
| 77 |
- $ sudo docker rmi eg_sshd |
|
| 75 |
+ $ docker stop test_sshd |
|
| 76 |
+ $ docker rm test_sshd |
|
| 77 |
+ $ docker rmi eg_sshd |
|
| 78 | 78 |
|
| ... | ... |
@@ -198,7 +198,7 @@ then run. |
| 198 | 198 |
Either by using the `docker` binary or via the API, the Docker client tells the Docker |
| 199 | 199 |
daemon to run a container. |
| 200 | 200 |
|
| 201 |
- $ sudo docker run -i -t ubuntu /bin/bash |
|
| 201 |
+ $ docker run -i -t ubuntu /bin/bash |
|
| 202 | 202 |
|
| 203 | 203 |
Let's break down this command. The Docker client is launched using the `docker` |
| 204 | 204 |
binary with the `run` option telling it to launch a new container. The bare |
| ... | ... |
@@ -115,7 +115,7 @@ supports: |
| 115 | 115 |
|
| 116 | 116 |
It's possible to run: |
| 117 | 117 |
|
| 118 |
- $ sudo docker pull https://<registry>/repositories/samalba/busybox |
|
| 118 |
+ $ docker pull https://<registry>/repositories/samalba/busybox |
|
| 119 | 119 |
|
| 120 | 120 |
In this case, Docker bypasses the Docker Hub. However the security is not |
| 121 | 121 |
guaranteed (in case Registry A is corrupted) because there won't be any |
| ... | ... |
@@ -26,7 +26,7 @@ This file will describe the steps to assemble the image. |
| 26 | 26 |
Then call `docker build` with the path of your source repository as the argument |
| 27 | 27 |
(for example, `.`): |
| 28 | 28 |
|
| 29 |
- $ sudo docker build . |
|
| 29 |
+ $ docker build . |
|
| 30 | 30 |
|
| 31 | 31 |
The path to the source repository defines where to find the *context* of |
| 32 | 32 |
the build. The build is run by the Docker daemon, not by the CLI, so the |
| ... | ... |
@@ -49,7 +49,7 @@ directory. |
| 49 | 49 |
You can specify a repository and tag at which to save the new image if |
| 50 | 50 |
the build succeeds: |
| 51 | 51 |
|
| 52 |
- $ sudo docker build -t shykes/myapp . |
|
| 52 |
+ $ docker build -t shykes/myapp . |
|
| 53 | 53 |
|
| 54 | 54 |
The Docker daemon will run your steps one-by-one, committing the result |
| 55 | 55 |
to a new image if necessary, before finally outputting the ID of your |
| ... | ... |
@@ -65,7 +65,7 @@ accelerating `docker build` significantly (indicated by `Using cache` - |
| 65 | 65 |
see the [`Dockerfile` Best Practices |
| 66 | 66 |
guide](/articles/dockerfile_best-practices/#build-cache) for more information): |
| 67 | 67 |
|
| 68 |
- $ sudo docker build -t SvenDowideit/ambassador . |
|
| 68 |
+ $ docker build -t SvenDowideit/ambassador . |
|
| 69 | 69 |
Uploading context 10.24 kB |
| 70 | 70 |
Uploading context |
| 71 | 71 |
Step 1 : FROM docker-ut |
| ... | ... |
@@ -175,7 +175,7 @@ The following example shows the use of the `.dockerignore` file to exclude the |
| 175 | 175 |
`.git` directory from the context. Its effect can be seen in the changed size of |
| 176 | 176 |
the uploaded context. |
| 177 | 177 |
|
| 178 |
- $ sudo docker build . |
|
| 178 |
+ $ docker build . |
|
| 179 | 179 |
Uploading context 18.829 MB |
| 180 | 180 |
Uploading context |
| 181 | 181 |
Step 0 : FROM busybox |
| ... | ... |
@@ -185,7 +185,7 @@ the uploaded context. |
| 185 | 185 |
---> 99cc1ad10469 |
| 186 | 186 |
Successfully built 99cc1ad10469 |
| 187 | 187 |
$ echo ".git" > .dockerignore |
| 188 |
- $ sudo docker build . |
|
| 188 |
+ $ docker build . |
|
| 189 | 189 |
Uploading context 6.76 MB |
| 190 | 190 |
Uploading context |
| 191 | 191 |
Step 0 : FROM busybox |
| ... | ... |
@@ -9,13 +9,20 @@ page_keywords: Docker, Docker documentation, CLI, command line |
| 9 | 9 |
To list available commands, either run `docker` with no parameters |
| 10 | 10 |
or execute `docker help`: |
| 11 | 11 |
|
| 12 |
- $ sudo docker |
|
| 12 |
+ $ docker |
|
| 13 | 13 |
Usage: docker [OPTIONS] COMMAND [arg...] |
| 14 | 14 |
-H, --host=[]: The socket(s) to bind to in daemon mode, specified using one or more tcp://host:port, unix:///path/to/socket, fd://* or fd://socketfd. |
| 15 | 15 |
|
| 16 | 16 |
A self-sufficient runtime for Linux containers. |
| 17 | 17 |
|
| 18 | 18 |
... |
| 19 |
+Depending on your Docker system configuration, you may be required |
|
| 20 |
+to preface each `docker` command with `sudo`. To avoid having to use `sudo` with |
|
| 21 |
+the `docker` command, your system administrator can create a Unix group called |
|
| 22 |
+`docker` and add users to it. |
|
| 23 |
+ |
|
| 24 |
+For more information about installing Docker or `sudo` configuration, refer to |
|
| 25 |
+the [installation](/installation) instructions for your operating system. |
|
| 19 | 26 |
|
| 20 | 27 |
## Environment Variables |
| 21 | 28 |
|
| ... | ... |
@@ -44,7 +51,7 @@ variables. |
| 44 | 44 |
## Help |
| 45 | 45 |
To list the help on any command just execute the command, followed by the `--help` option. |
| 46 | 46 |
|
| 47 |
- $ sudo docker run --help |
|
| 47 |
+ $ docker run --help |
|
| 48 | 48 |
|
| 49 | 49 |
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] |
| 50 | 50 |
|
| ... | ... |
@@ -79,11 +86,11 @@ be set to the non-default value by explicitly setting them to `false`: |
| 79 | 79 |
|
| 80 | 80 |
Options like `-a=[]` indicate they can be specified multiple times: |
| 81 | 81 |
|
| 82 |
- $ sudo docker run -a stdin -a stdout -a stderr -i -t ubuntu /bin/bash |
|
| 82 |
+ $ docker run -a stdin -a stdout -a stderr -i -t ubuntu /bin/bash |
|
| 83 | 83 |
|
| 84 | 84 |
Sometimes this can use a more complex value string, as for `-v`: |
| 85 | 85 |
|
| 86 |
- $ sudo docker run -v /host:/container example/mysql |
|
| 86 |
+ $ docker run -v /host:/container example/mysql |
|
| 87 | 87 |
|
| 88 | 88 |
### Strings and Integers |
| 89 | 89 |
|
| ... | ... |
@@ -184,19 +191,19 @@ time using multiple `-H` options: |
| 184 | 184 |
The Docker client will honor the `DOCKER_HOST` environment variable to set |
| 185 | 185 |
the `-H` flag for the client. |
| 186 | 186 |
|
| 187 |
- $ sudo docker -H tcp://0.0.0.0:2375 ps |
|
| 187 |
+ $ docker -H tcp://0.0.0.0:2375 ps |
|
| 188 | 188 |
# or |
| 189 | 189 |
$ export DOCKER_HOST="tcp://0.0.0.0:2375" |
| 190 |
- $ sudo docker ps |
|
| 190 |
+ $ docker ps |
|
| 191 | 191 |
# both are equal |
| 192 | 192 |
|
| 193 | 193 |
Setting the `DOCKER_TLS_VERIFY` environment variable to any value other than the empty |
| 194 | 194 |
string is equivalent to setting the `--tlsverify` flag. The following are equivalent: |
| 195 | 195 |
|
| 196 |
- $ sudo docker --tlsverify ps |
|
| 196 |
+ $ docker --tlsverify ps |
|
| 197 | 197 |
# or |
| 198 | 198 |
$ export DOCKER_TLS_VERIFY=1 |
| 199 |
- $ sudo docker ps |
|
| 199 |
+ $ docker ps |
|
| 200 | 200 |
|
| 201 | 201 |
The Docker client will honor the `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` |
| 202 | 202 |
environment variables (or the lowercase versions thereof). `HTTPS_PROXY` takes |
| ... | ... |
@@ -260,7 +267,7 @@ Currently supported options are: |
| 260 | 260 |
|
| 261 | 261 |
Example use: |
| 262 | 262 |
|
| 263 |
- $ sudo docker -d --storage-opt dm.basesize=20G |
|
| 263 |
+ $ docker -d --storage-opt dm.basesize=20G |
|
| 264 | 264 |
|
| 265 | 265 |
* `dm.loopdatasize` |
| 266 | 266 |
|
| ... | ... |
@@ -270,7 +277,7 @@ Currently supported options are: |
| 270 | 270 |
|
| 271 | 271 |
Example use: |
| 272 | 272 |
|
| 273 |
- $ sudo docker -d --storage-opt dm.loopdatasize=200G |
|
| 273 |
+ $ docker -d --storage-opt dm.loopdatasize=200G |
|
| 274 | 274 |
|
| 275 | 275 |
* `dm.loopmetadatasize` |
| 276 | 276 |
|
| ... | ... |
@@ -281,7 +288,7 @@ Currently supported options are: |
| 281 | 281 |
|
| 282 | 282 |
Example use: |
| 283 | 283 |
|
| 284 |
- $ sudo docker -d --storage-opt dm.loopmetadatasize=4G |
|
| 284 |
+ $ docker -d --storage-opt dm.loopmetadatasize=4G |
|
| 285 | 285 |
|
| 286 | 286 |
* `dm.fs` |
| 287 | 287 |
|
| ... | ... |
@@ -290,7 +297,7 @@ Currently supported options are: |
| 290 | 290 |
|
| 291 | 291 |
Example use: |
| 292 | 292 |
|
| 293 |
- $ sudo docker -d --storage-opt dm.fs=xfs |
|
| 293 |
+ $ docker -d --storage-opt dm.fs=xfs |
|
| 294 | 294 |
|
| 295 | 295 |
* `dm.mkfsarg` |
| 296 | 296 |
|
| ... | ... |
@@ -298,7 +305,7 @@ Currently supported options are: |
| 298 | 298 |
|
| 299 | 299 |
Example use: |
| 300 | 300 |
|
| 301 |
- $ sudo docker -d --storage-opt "dm.mkfsarg=-O ^has_journal" |
|
| 301 |
+ $ docker -d --storage-opt "dm.mkfsarg=-O ^has_journal" |
|
| 302 | 302 |
|
| 303 | 303 |
* `dm.mountopt` |
| 304 | 304 |
|
| ... | ... |
@@ -306,7 +313,7 @@ Currently supported options are: |
| 306 | 306 |
|
| 307 | 307 |
Example use: |
| 308 | 308 |
|
| 309 |
- $ sudo docker -d --storage-opt dm.mountopt=nodiscard |
|
| 309 |
+ $ docker -d --storage-opt dm.mountopt=nodiscard |
|
| 310 | 310 |
|
| 311 | 311 |
* `dm.datadev` |
| 312 | 312 |
|
| ... | ... |
@@ -318,7 +325,7 @@ Currently supported options are: |
| 318 | 318 |
|
| 319 | 319 |
Example use: |
| 320 | 320 |
|
| 321 |
- $ sudo docker -d \ |
|
| 321 |
+ $ docker -d \ |
|
| 322 | 322 |
--storage-opt dm.datadev=/dev/sdb1 \ |
| 323 | 323 |
--storage-opt dm.metadatadev=/dev/sdc1 |
| 324 | 324 |
|
| ... | ... |
@@ -336,7 +343,7 @@ Currently supported options are: |
| 336 | 336 |
|
| 337 | 337 |
Example use: |
| 338 | 338 |
|
| 339 |
- $ sudo docker -d \ |
|
| 339 |
+ $ docker -d \ |
|
| 340 | 340 |
--storage-opt dm.datadev=/dev/sdb1 \ |
| 341 | 341 |
--storage-opt dm.metadatadev=/dev/sdc1 |
| 342 | 342 |
|
| ... | ... |
@@ -347,7 +354,7 @@ Currently supported options are: |
| 347 | 347 |
|
| 348 | 348 |
Example use: |
| 349 | 349 |
|
| 350 |
- $ sudo docker -d --storage-opt dm.blocksize=512K |
|
| 350 |
+ $ docker -d --storage-opt dm.blocksize=512K |
|
| 351 | 351 |
|
| 352 | 352 |
* `dm.blkdiscard` |
| 353 | 353 |
|
| ... | ... |
@@ -361,7 +368,7 @@ Currently supported options are: |
| 361 | 361 |
|
| 362 | 362 |
Example use: |
| 363 | 363 |
|
| 364 |
- $ sudo docker -d --storage-opt dm.blkdiscard=false |
|
| 364 |
+ $ docker -d --storage-opt dm.blkdiscard=false |
|
| 365 | 365 |
|
| 366 | 366 |
### Docker exec-driver option |
| 367 | 367 |
|
| ... | ... |
@@ -478,8 +485,8 @@ attaching to a tty-enabled container (i.e.: launched with `-t`). |
| 478 | 478 |
|
| 479 | 479 |
#### Examples |
| 480 | 480 |
|
| 481 |
- $ sudo docker run -d --name topdemo ubuntu /usr/bin/top -b) |
|
| 482 |
- $ sudo docker attach topdemo |
|
| 481 |
+ $ docker run -d --name topdemo ubuntu /usr/bin/top -b) |
|
| 482 |
+ $ docker attach topdemo |
|
| 483 | 483 |
top - 02:05:52 up 3:05, 0 users, load average: 0.01, 0.02, 0.05 |
| 484 | 484 |
Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie |
| 485 | 485 |
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 |
| ... | ... |
@@ -516,14 +523,14 @@ attaching to a tty-enabled container (i.e.: launched with `-t`). |
| 516 | 516 |
And in this second example, you can see the exit code returned by the `bash` process |
| 517 | 517 |
is returned by the `docker attach` command to its caller too: |
| 518 | 518 |
|
| 519 |
- $ sudo docker run --name test -d -it debian |
|
| 519 |
+ $ docker run --name test -d -it debian |
|
| 520 | 520 |
275c44472aebd77c926d4527885bb09f2f6db21d878c75f0a1c212c03d3bcfab |
| 521 |
- $ sudo docker attach test |
|
| 521 |
+ $ docker attach test |
|
| 522 | 522 |
$$ exit 13 |
| 523 | 523 |
exit |
| 524 | 524 |
$ echo $? |
| 525 | 525 |
13 |
| 526 |
- $ sudo docker ps -a | grep test |
|
| 526 |
+ $ docker ps -a | grep test |
|
| 527 | 527 |
275c44472aeb debian:7 "/bin/bash" 26 seconds ago Exited (13) 17 seconds ago test |
| 528 | 528 |
|
| 529 | 529 |
## build |
| ... | ... |
@@ -636,7 +643,7 @@ See also: |
| 636 | 636 |
|
| 637 | 637 |
#### Examples |
| 638 | 638 |
|
| 639 |
- $ sudo docker build . |
|
| 639 |
+ $ docker build . |
|
| 640 | 640 |
Uploading context 10240 bytes |
| 641 | 641 |
Step 1 : FROM busybox |
| 642 | 642 |
Pulling repository busybox |
| ... | ... |
@@ -681,7 +688,7 @@ If you wish to keep the intermediate containers after the build is |
| 681 | 681 |
complete, you must use `--rm=false`. This does not |
| 682 | 682 |
affect the build cache. |
| 683 | 683 |
|
| 684 |
- $ sudo docker build . |
|
| 684 |
+ $ docker build . |
|
| 685 | 685 |
Uploading context 18.829 MB |
| 686 | 686 |
Uploading context |
| 687 | 687 |
Step 0 : FROM busybox |
| ... | ... |
@@ -691,7 +698,7 @@ affect the build cache. |
| 691 | 691 |
---> 99cc1ad10469 |
| 692 | 692 |
Successfully built 99cc1ad10469 |
| 693 | 693 |
$ echo ".git" > .dockerignore |
| 694 |
- $ sudo docker build . |
|
| 694 |
+ $ docker build . |
|
| 695 | 695 |
Uploading context 6.76 MB |
| 696 | 696 |
Uploading context |
| 697 | 697 |
Step 0 : FROM busybox |
| ... | ... |
@@ -705,25 +712,25 @@ This example shows the use of the `.dockerignore` file to exclude the `.git` |
| 705 | 705 |
directory from the context. Its effect can be seen in the changed size of the |
| 706 | 706 |
uploaded context. |
| 707 | 707 |
|
| 708 |
- $ sudo docker build -t vieux/apache:2.0 . |
|
| 708 |
+ $ docker build -t vieux/apache:2.0 . |
|
| 709 | 709 |
|
| 710 | 710 |
This will build like the previous example, but it will then tag the |
| 711 | 711 |
resulting image. The repository name will be `vieux/apache` |
| 712 | 712 |
and the tag will be `2.0` |
| 713 | 713 |
|
| 714 |
- $ sudo docker build - < Dockerfile |
|
| 714 |
+ $ docker build - < Dockerfile |
|
| 715 | 715 |
|
| 716 | 716 |
This will read a Dockerfile from `STDIN` without context. Due to the |
| 717 | 717 |
lack of a context, no contents of any local directory will be sent to |
| 718 | 718 |
the Docker daemon. Since there is no context, a Dockerfile `ADD` only |
| 719 | 719 |
works if it refers to a remote URL. |
| 720 | 720 |
|
| 721 |
- $ sudo docker build - < context.tar.gz |
|
| 721 |
+ $ docker build - < context.tar.gz |
|
| 722 | 722 |
|
| 723 | 723 |
This will build an image for a compressed context read from `STDIN`. |
| 724 | 724 |
Supported formats are: bzip2, gzip and xz. |
| 725 | 725 |
|
| 726 |
- $ sudo docker build github.com/creack/docker-firefox |
|
| 726 |
+ $ docker build github.com/creack/docker-firefox |
|
| 727 | 727 |
|
| 728 | 728 |
This will clone the GitHub repository and use the cloned repository as |
| 729 | 729 |
context. The Dockerfile at the root of the |
| ... | ... |
@@ -731,21 +738,21 @@ repository is used as Dockerfile. Note that you |
| 731 | 731 |
can specify an arbitrary Git repository by using the `git://` or `git@` |
| 732 | 732 |
schema. |
| 733 | 733 |
|
| 734 |
- $ sudo docker build -f Dockerfile.debug . |
|
| 734 |
+ $ docker build -f Dockerfile.debug . |
|
| 735 | 735 |
|
| 736 | 736 |
This will use a file called `Dockerfile.debug` for the build |
| 737 | 737 |
instructions instead of `Dockerfile`. |
| 738 | 738 |
|
| 739 |
- $ sudo docker build -f dockerfiles/Dockerfile.debug -t myapp_debug . |
|
| 740 |
- $ sudo docker build -f dockerfiles/Dockerfile.prod -t myapp_prod . |
|
| 739 |
+ $ docker build -f dockerfiles/Dockerfile.debug -t myapp_debug . |
|
| 740 |
+ $ docker build -f dockerfiles/Dockerfile.prod -t myapp_prod . |
|
| 741 | 741 |
|
| 742 | 742 |
The above commands will build the current build context (as specified by |
| 743 | 743 |
the `.`) twice, once using a debug version of a `Dockerfile` and once using |
| 744 | 744 |
a production version. |
| 745 | 745 |
|
| 746 | 746 |
$ cd /home/me/myapp/some/dir/really/deep |
| 747 |
- $ sudo docker build -f /home/me/myapp/dockerfiles/debug /home/me/myapp |
|
| 748 |
- $ sudo docker build -f ../../../../dockerfiles/debug /home/me/myapp |
|
| 747 |
+ $ docker build -f /home/me/myapp/dockerfiles/debug /home/me/myapp |
|
| 748 |
+ $ docker build -f ../../../../dockerfiles/debug /home/me/myapp |
|
| 749 | 749 |
|
| 750 | 750 |
These two `docker build` commands do the exact same thing. They both |
| 751 | 751 |
use the contents of the `debug` file instead of looking for a `Dockerfile` |
| ... | ... |
@@ -788,27 +795,27 @@ Supported `Dockerfile` instructions: `ADD`|`CMD`|`ENTRYPOINT`|`ENV`|`EXPOSE`|`FR |
| 788 | 788 |
|
| 789 | 789 |
#### Commit a container |
| 790 | 790 |
|
| 791 |
- $ sudo docker ps |
|
| 791 |
+ $ docker ps |
|
| 792 | 792 |
ID IMAGE COMMAND CREATED STATUS PORTS |
| 793 | 793 |
c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours |
| 794 | 794 |
197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours |
| 795 |
- $ sudo docker commit c3f279d17e0a SvenDowideit/testimage:version3 |
|
| 795 |
+ $ docker commit c3f279d17e0a SvenDowideit/testimage:version3 |
|
| 796 | 796 |
f5283438590d |
| 797 |
- $ sudo docker images | head |
|
| 797 |
+ $ docker images | head |
|
| 798 | 798 |
REPOSITORY TAG ID CREATED VIRTUAL SIZE |
| 799 | 799 |
SvenDowideit/testimage version3 f5283438590d 16 seconds ago 335.7 MB |
| 800 | 800 |
|
| 801 | 801 |
#### Commit a container with new configurations |
| 802 | 802 |
|
| 803 |
- $ sudo docker ps |
|
| 803 |
+ $ docker ps |
|
| 804 | 804 |
ID IMAGE COMMAND CREATED STATUS PORTS |
| 805 | 805 |
c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours |
| 806 | 806 |
197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours |
| 807 |
- $ sudo docker inspect -f "{{ .Config.Env }}" c3f279d17e0a
|
|
| 807 |
+ $ docker inspect -f "{{ .Config.Env }}" c3f279d17e0a
|
|
| 808 | 808 |
[HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin] |
| 809 |
- $ sudo docker commit --change "ENV DEBUG true" c3f279d17e0a SvenDowideit/testimage:version3 |
|
| 809 |
+ $ docker commit --change "ENV DEBUG true" c3f279d17e0a SvenDowideit/testimage:version3 |
|
| 810 | 810 |
f5283438590d |
| 811 |
- $ sudo docker inspect -f "{{ .Config.Env }}" f5283438590d
|
|
| 811 |
+ $ docker inspect -f "{{ .Config.Env }}" f5283438590d
|
|
| 812 | 812 |
[HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin DEBUG=true] |
| 813 | 813 |
|
| 814 | 814 |
## cp |
| ... | ... |
@@ -884,9 +891,9 @@ Please see the [run command](#run) section and the [Docker run reference]( |
| 884 | 884 |
|
| 885 | 885 |
#### Examples |
| 886 | 886 |
|
| 887 |
- $ sudo docker create -t -i fedora bash |
|
| 887 |
+ $ docker create -t -i fedora bash |
|
| 888 | 888 |
6d8af538ec541dd581ebc2a24153a28329acb5268abe5ef868c1f1a261221752 |
| 889 |
- $ sudo docker start -a -i 6d8af538ec5 |
|
| 889 |
+ $ docker start -a -i 6d8af538ec5 |
|
| 890 | 890 |
bash-4.2# |
| 891 | 891 |
|
| 892 | 892 |
As of v1.4.0 container volumes are initialized during the `docker create` |
| ... | ... |
@@ -934,7 +941,7 @@ There are 3 events that are listed in the `diff`: |
| 934 | 934 |
|
| 935 | 935 |
For example: |
| 936 | 936 |
|
| 937 |
- $ sudo docker diff 7bb0e258aefe |
|
| 937 |
+ $ docker diff 7bb0e258aefe |
|
| 938 | 938 |
|
| 939 | 939 |
C /dev |
| 940 | 940 |
A /dev/kmsg |
| ... | ... |
@@ -991,13 +998,13 @@ You'll need two shells for this example. |
| 991 | 991 |
|
| 992 | 992 |
**Shell 1: Listening for events:** |
| 993 | 993 |
|
| 994 |
- $ sudo docker events |
|
| 994 |
+ $ docker events |
|
| 995 | 995 |
|
| 996 | 996 |
**Shell 2: Start and Stop containers:** |
| 997 | 997 |
|
| 998 |
- $ sudo docker start 4386fb97867d |
|
| 999 |
- $ sudo docker stop 4386fb97867d |
|
| 1000 |
- $ sudo docker stop 7805c1d35632 |
|
| 998 |
+ $ docker start 4386fb97867d |
|
| 999 |
+ $ docker stop 4386fb97867d |
|
| 1000 |
+ $ docker stop 7805c1d35632 |
|
| 1001 | 1001 |
|
| 1002 | 1002 |
**Shell 1: (Again .. now showing events):** |
| 1003 | 1003 |
|
| ... | ... |
@@ -1009,20 +1016,20 @@ You'll need two shells for this example. |
| 1009 | 1009 |
|
| 1010 | 1010 |
**Show events in the past from a specified time:** |
| 1011 | 1011 |
|
| 1012 |
- $ sudo docker events --since 1378216169 |
|
| 1012 |
+ $ docker events --since 1378216169 |
|
| 1013 | 1013 |
2014-03-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die |
| 1014 | 1014 |
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop |
| 1015 | 1015 |
2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die |
| 1016 | 1016 |
2014-03-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) stop |
| 1017 | 1017 |
|
| 1018 |
- $ sudo docker events --since '2013-09-03' |
|
| 1018 |
+ $ docker events --since '2013-09-03' |
|
| 1019 | 1019 |
2014-09-03T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) start |
| 1020 | 1020 |
2014-09-03T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die |
| 1021 | 1021 |
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop |
| 1022 | 1022 |
2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die |
| 1023 | 1023 |
2014-09-03T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) stop |
| 1024 | 1024 |
|
| 1025 |
- $ sudo docker events --since '2013-09-03T15:49:29' |
|
| 1025 |
+ $ docker events --since '2013-09-03T15:49:29' |
|
| 1026 | 1026 |
2014-09-03T15:49:29.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die |
| 1027 | 1027 |
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop |
| 1028 | 1028 |
2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die |
| ... | ... |
@@ -1030,29 +1037,29 @@ You'll need two shells for this example. |
| 1030 | 1030 |
|
| 1031 | 1031 |
**Filter events:** |
| 1032 | 1032 |
|
| 1033 |
- $ sudo docker events --filter 'event=stop' |
|
| 1033 |
+ $ docker events --filter 'event=stop' |
|
| 1034 | 1034 |
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop |
| 1035 | 1035 |
2014-09-03T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) stop |
| 1036 | 1036 |
|
| 1037 |
- $ sudo docker events --filter 'image=ubuntu-1:14.04' |
|
| 1037 |
+ $ docker events --filter 'image=ubuntu-1:14.04' |
|
| 1038 | 1038 |
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) start |
| 1039 | 1039 |
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die |
| 1040 | 1040 |
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop |
| 1041 | 1041 |
|
| 1042 |
- $ sudo docker events --filter 'container=7805c1d35632' |
|
| 1042 |
+ $ docker events --filter 'container=7805c1d35632' |
|
| 1043 | 1043 |
2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die |
| 1044 | 1044 |
2014-09-03T15:49:29.999999999Z07:00 7805c1d35632: (from redis:2.8) stop |
| 1045 | 1045 |
|
| 1046 |
- $ sudo docker events --filter 'container=7805c1d35632' --filter 'container=4386fb97867d' |
|
| 1046 |
+ $ docker events --filter 'container=7805c1d35632' --filter 'container=4386fb97867d' |
|
| 1047 | 1047 |
2014-09-03T15:49:29.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die |
| 1048 | 1048 |
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop |
| 1049 | 1049 |
2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die |
| 1050 | 1050 |
2014-09-03T15:49:29.999999999Z07:00 7805c1d35632: (from redis:2.8) stop |
| 1051 | 1051 |
|
| 1052 |
- $ sudo docker events --filter 'container=7805c1d35632' --filter 'event=stop' |
|
| 1052 |
+ $ docker events --filter 'container=7805c1d35632' --filter 'event=stop' |
|
| 1053 | 1053 |
2014-09-03T15:49:29.999999999Z07:00 7805c1d35632: (from redis:2.8) stop |
| 1054 | 1054 |
|
| 1055 |
- $ sudo docker events --filter 'container=container_1' --filter 'container=container_2' |
|
| 1055 |
+ $ docker events --filter 'container=container_1' --filter 'container=container_2' |
|
| 1056 | 1056 |
2014-09-03T15:49:29.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die |
| 1057 | 1057 |
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop |
| 1058 | 1058 |
2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die |
| ... | ... |
@@ -1087,16 +1094,16 @@ If the container is paused, then the `docker exec` command will fail with an err |
| 1087 | 1087 |
|
| 1088 | 1088 |
#### Examples |
| 1089 | 1089 |
|
| 1090 |
- $ sudo docker run --name ubuntu_bash --rm -i -t ubuntu bash |
|
| 1090 |
+ $ docker run --name ubuntu_bash --rm -i -t ubuntu bash |
|
| 1091 | 1091 |
|
| 1092 | 1092 |
This will create a container named `ubuntu_bash` and start a Bash session. |
| 1093 | 1093 |
|
| 1094 |
- $ sudo docker exec -d ubuntu_bash touch /tmp/execWorks |
|
| 1094 |
+ $ docker exec -d ubuntu_bash touch /tmp/execWorks |
|
| 1095 | 1095 |
|
| 1096 | 1096 |
This will create a new file `/tmp/execWorks` inside the running container |
| 1097 | 1097 |
`ubuntu_bash`, in the background. |
| 1098 | 1098 |
|
| 1099 |
- $ sudo docker exec -it ubuntu_bash bash |
|
| 1099 |
+ $ docker exec -it ubuntu_bash bash |
|
| 1100 | 1100 |
|
| 1101 | 1101 |
This will create a new Bash session in the container `ubuntu_bash`. |
| 1102 | 1102 |
|
| ... | ... |
@@ -1112,11 +1119,11 @@ This will create a new Bash session in the container `ubuntu_bash`. |
| 1112 | 1112 |
|
| 1113 | 1113 |
For example: |
| 1114 | 1114 |
|
| 1115 |
- $ sudo docker export red_panda > latest.tar |
|
| 1115 |
+ $ docker export red_panda > latest.tar |
|
| 1116 | 1116 |
|
| 1117 | 1117 |
Or |
| 1118 | 1118 |
|
| 1119 |
- $ sudo docker export --output="latest.tar" red_panda |
|
| 1119 |
+ $ docker export --output="latest.tar" red_panda |
|
| 1120 | 1120 |
|
| 1121 | 1121 |
> **Note:** |
| 1122 | 1122 |
> `docker export` does not export the contents of volumes associated with the |
| ... | ... |
@@ -1138,7 +1145,7 @@ This will create a new Bash session in the container `ubuntu_bash`. |
| 1138 | 1138 |
|
| 1139 | 1139 |
To see how the `docker:latest` image was built: |
| 1140 | 1140 |
|
| 1141 |
- $ sudo docker history docker |
|
| 1141 |
+ $ docker history docker |
|
| 1142 | 1142 |
IMAGE CREATED CREATED BY SIZE |
| 1143 | 1143 |
3e23a5875458790b7a806f95f7ec0d0b2a5c1659bfc899c89f939f6d5b8f7094 8 days ago /bin/sh -c #(nop) ENV LC_ALL=C.UTF-8 0 B |
| 1144 | 1144 |
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 |
| ... | ... |
@@ -1178,7 +1185,7 @@ uses up the `VIRTUAL SIZE` listed only once. |
| 1178 | 1178 |
|
| 1179 | 1179 |
#### Listing the most recently created images |
| 1180 | 1180 |
|
| 1181 |
- $ sudo docker images | head |
|
| 1181 |
+ $ docker images | head |
|
| 1182 | 1182 |
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE |
| 1183 | 1183 |
<none> <none> 77af4d6b9913 19 hours ago 1.089 GB |
| 1184 | 1184 |
committ latest b6fa739cedf5 19 hours ago 1.089 GB |
| ... | ... |
@@ -1193,7 +1200,7 @@ uses up the `VIRTUAL SIZE` listed only once. |
| 1193 | 1193 |
|
| 1194 | 1194 |
#### Listing the full length image IDs |
| 1195 | 1195 |
|
| 1196 |
- $ sudo docker images --no-trunc | head |
|
| 1196 |
+ $ docker images --no-trunc | head |
|
| 1197 | 1197 |
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE |
| 1198 | 1198 |
<none> <none> 77af4d6b9913e693e8d0b4b294fa62ade6054e6b2f1ffb617ac955dd63fb0182 19 hours ago 1.089 GB |
| 1199 | 1199 |
committest latest b6fa739cedf5ea12a620a439402b6004d057da800f91c7524b5086a5e4749c9f 19 hours ago 1.089 GB |
| ... | ... |
@@ -1212,7 +1219,7 @@ called a `digest`. As long as the input used to generate the image is |
| 1212 | 1212 |
unchanged, the digest value is predictable. To list image digest values, use |
| 1213 | 1213 |
the `--digests` flag: |
| 1214 | 1214 |
|
| 1215 |
- $ sudo docker images --digests | head |
|
| 1215 |
+ $ docker images --digests | head |
|
| 1216 | 1216 |
REPOSITORY TAG DIGEST IMAGE ID CREATED VIRTUAL SIZE |
| 1217 | 1217 |
localhost:5000/test/busybox <none> sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf 4986bf8c1536 9 weeks ago 2.43 MB |
| 1218 | 1218 |
|
| ... | ... |
@@ -1232,7 +1239,7 @@ Current filters: |
| 1232 | 1232 |
|
| 1233 | 1233 |
##### Untagged images |
| 1234 | 1234 |
|
| 1235 |
- $ sudo docker images --filter "dangling=true" |
|
| 1235 |
+ $ docker images --filter "dangling=true" |
|
| 1236 | 1236 |
|
| 1237 | 1237 |
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE |
| 1238 | 1238 |
<none> <none> 8abc22fbb042 4 weeks ago 0 B |
| ... | ... |
@@ -1250,7 +1257,7 @@ By having this flag it allows for batch cleanup. |
| 1250 | 1250 |
|
| 1251 | 1251 |
Ready for use by `docker rmi ...`, like: |
| 1252 | 1252 |
|
| 1253 |
- $ sudo docker rmi $(sudo docker images -f "dangling=true" -q) |
|
| 1253 |
+ $ docker rmi $(docker images -f "dangling=true" -q) |
|
| 1254 | 1254 |
|
| 1255 | 1255 |
8abc22fbb042 |
| 1256 | 1256 |
48e5f45168b9 |
| ... | ... |
@@ -1287,21 +1294,21 @@ Supported `Dockerfile` instructions: `CMD`, `ENTRYPOINT`, `ENV`, `EXPOSE`, |
| 1287 | 1287 |
|
| 1288 | 1288 |
This will create a new untagged image. |
| 1289 | 1289 |
|
| 1290 |
- $ sudo docker import http://example.com/exampleimage.tgz |
|
| 1290 |
+ $ docker import http://example.com/exampleimage.tgz |
|
| 1291 | 1291 |
|
| 1292 | 1292 |
**Import from a local file:** |
| 1293 | 1293 |
|
| 1294 | 1294 |
Import to docker via pipe and `STDIN`. |
| 1295 | 1295 |
|
| 1296 |
- $ cat exampleimage.tgz | sudo docker import - exampleimagelocal:new |
|
| 1296 |
+ $ cat exampleimage.tgz | docker import - exampleimagelocal:new |
|
| 1297 | 1297 |
|
| 1298 | 1298 |
**Import from a local directory:** |
| 1299 | 1299 |
|
| 1300 |
- $ sudo tar -c . | sudo docker import - exampleimagedir |
|
| 1300 |
+ $ sudo tar -c . | docker import - exampleimagedir |
|
| 1301 | 1301 |
|
| 1302 | 1302 |
**Import from a local directory with new configurations:** |
| 1303 | 1303 |
|
| 1304 |
- $ sudo tar -c . | sudo docker import --change "ENV DEBUG true" - exampleimagedir |
|
| 1304 |
+ $ sudo tar -c . | docker import --change "ENV DEBUG true" - exampleimagedir |
|
| 1305 | 1305 |
|
| 1306 | 1306 |
Note the `sudo` in this example – you must preserve |
| 1307 | 1307 |
the ownership of the files (especially root ownership) during the |
| ... | ... |
@@ -1317,7 +1324,7 @@ tar, then the ownerships might not get preserved. |
| 1317 | 1317 |
|
| 1318 | 1318 |
For example: |
| 1319 | 1319 |
|
| 1320 |
- $ sudo docker -D info |
|
| 1320 |
+ $ docker -D info |
|
| 1321 | 1321 |
Containers: 14 |
| 1322 | 1322 |
Images: 52 |
| 1323 | 1323 |
Storage Driver: aufs |
| ... | ... |
@@ -1373,25 +1380,25 @@ describes all the details of the format. |
| 1373 | 1373 |
For the most part, you can pick out any field from the JSON in a fairly |
| 1374 | 1374 |
straightforward manner. |
| 1375 | 1375 |
|
| 1376 |
- $ sudo docker inspect --format='{{.NetworkSettings.IPAddress}}' $INSTANCE_ID
|
|
| 1376 |
+ $ docker inspect --format='{{.NetworkSettings.IPAddress}}' $INSTANCE_ID
|
|
| 1377 | 1377 |
|
| 1378 | 1378 |
**Get an instance's MAC Address:** |
| 1379 | 1379 |
|
| 1380 | 1380 |
For the most part, you can pick out any field from the JSON in a fairly |
| 1381 | 1381 |
straightforward manner. |
| 1382 | 1382 |
|
| 1383 |
- $ sudo docker inspect --format='{{.NetworkSettings.MacAddress}}' $INSTANCE_ID
|
|
| 1383 |
+ $ docker inspect --format='{{.NetworkSettings.MacAddress}}' $INSTANCE_ID
|
|
| 1384 | 1384 |
|
| 1385 | 1385 |
**Get an instance's log path:** |
| 1386 | 1386 |
|
| 1387 |
- $ sudo docker inspect --format='{{.LogPath}}' $INSTANCE_ID
|
|
| 1387 |
+ $ docker inspect --format='{{.LogPath}}' $INSTANCE_ID
|
|
| 1388 | 1388 |
|
| 1389 | 1389 |
**List All Port Bindings:** |
| 1390 | 1390 |
|
| 1391 | 1391 |
One can loop over arrays and maps in the results to produce simple text |
| 1392 | 1392 |
output: |
| 1393 | 1393 |
|
| 1394 |
- $ sudo docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID
|
|
| 1394 |
+ $ docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID
|
|
| 1395 | 1395 |
|
| 1396 | 1396 |
**Find a Specific Port Mapping:** |
| 1397 | 1397 |
|
| ... | ... |
@@ -1403,7 +1410,7 @@ numeric public port, you use `index` to find the specific port map, and |
| 1403 | 1403 |
then `index` 0 contains the first object inside of that. Then we ask for |
| 1404 | 1404 |
the `HostPort` field to get the public address. |
| 1405 | 1405 |
|
| 1406 |
- $ sudo docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID
|
|
| 1406 |
+ $ docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID
|
|
| 1407 | 1407 |
|
| 1408 | 1408 |
**Get config:** |
| 1409 | 1409 |
|
| ... | ... |
@@ -1412,7 +1419,7 @@ the template language's custom `json` function does. The `.config` |
| 1412 | 1412 |
section contains complex JSON object, so to grab it as JSON, you use |
| 1413 | 1413 |
`json` to convert the configuration object into JSON. |
| 1414 | 1414 |
|
| 1415 |
- $ sudo docker inspect --format='{{json .config}}' $INSTANCE_ID
|
|
| 1415 |
+ $ docker inspect --format='{{json .config}}' $INSTANCE_ID
|
|
| 1416 | 1416 |
|
| 1417 | 1417 |
## kill |
| 1418 | 1418 |
|
| ... | ... |
@@ -1436,14 +1443,14 @@ signal specified with option `--signal`. |
| 1436 | 1436 |
Loads a tarred repository from a file or the standard input stream. |
| 1437 | 1437 |
Restores both images and tags. |
| 1438 | 1438 |
|
| 1439 |
- $ sudo docker images |
|
| 1439 |
+ $ docker images |
|
| 1440 | 1440 |
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE |
| 1441 |
- $ sudo docker load < busybox.tar |
|
| 1442 |
- $ sudo docker images |
|
| 1441 |
+ $ docker load < busybox.tar |
|
| 1442 |
+ $ docker images |
|
| 1443 | 1443 |
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE |
| 1444 | 1444 |
busybox latest 769b9341d937 7 weeks ago 2.489 MB |
| 1445 |
- $ sudo docker load --input fedora.tar |
|
| 1446 |
- $ sudo docker images |
|
| 1445 |
+ $ docker load --input fedora.tar |
|
| 1446 |
+ $ docker images |
|
| 1447 | 1447 |
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE |
| 1448 | 1448 |
busybox latest 769b9341d937 7 weeks ago 2.489 MB |
| 1449 | 1449 |
fedora rawhide 0d20aec6529d 7 weeks ago 387 MB |
| ... | ... |
@@ -1466,7 +1473,7 @@ If you want to login to a self-hosted registry you can specify this by |
| 1466 | 1466 |
adding the server name. |
| 1467 | 1467 |
|
| 1468 | 1468 |
example: |
| 1469 |
- $ sudo docker login localhost:8080 |
|
| 1469 |
+ $ docker login localhost:8080 |
|
| 1470 | 1470 |
|
| 1471 | 1471 |
## logout |
| 1472 | 1472 |
|
| ... | ... |
@@ -1477,7 +1484,7 @@ adding the server name. |
| 1477 | 1477 |
|
| 1478 | 1478 |
For example: |
| 1479 | 1479 |
|
| 1480 |
- $ sudo docker logout localhost:8080 |
|
| 1480 |
+ $ docker logout localhost:8080 |
|
| 1481 | 1481 |
|
| 1482 | 1482 |
## logs |
| 1483 | 1483 |
|
| ... | ... |
@@ -1531,17 +1538,17 @@ for further details. |
| 1531 | 1531 |
You can find out all the ports mapped by not specifying a `PRIVATE_PORT`, or |
| 1532 | 1532 |
just a specific mapping: |
| 1533 | 1533 |
|
| 1534 |
- $ sudo docker ps test |
|
| 1534 |
+ $ docker ps test |
|
| 1535 | 1535 |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
| 1536 | 1536 |
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 |
| 1537 |
- $ sudo docker port test |
|
| 1537 |
+ $ docker port test |
|
| 1538 | 1538 |
7890/tcp -> 0.0.0.0:4321 |
| 1539 | 1539 |
9876/tcp -> 0.0.0.0:1234 |
| 1540 |
- $ sudo docker port test 7890/tcp |
|
| 1540 |
+ $ docker port test 7890/tcp |
|
| 1541 | 1541 |
0.0.0.0:4321 |
| 1542 |
- $ sudo docker port test 7890/udp |
|
| 1542 |
+ $ docker port test 7890/udp |
|
| 1543 | 1543 |
2014/06/24 11:53:36 Error: No public port '7890/udp' published for test |
| 1544 |
- $ sudo docker port test 7890 |
|
| 1544 |
+ $ docker port test 7890 |
|
| 1545 | 1545 |
0.0.0.0:4321 |
| 1546 | 1546 |
|
| 1547 | 1547 |
## ps |
| ... | ... |
@@ -1562,7 +1569,7 @@ just a specific mapping: |
| 1562 | 1562 |
|
| 1563 | 1563 |
Running `docker ps --no-trunc` showing 2 linked containers. |
| 1564 | 1564 |
|
| 1565 |
- $ sudo docker ps |
|
| 1565 |
+ $ docker ps |
|
| 1566 | 1566 |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
| 1567 | 1567 |
4c01db0b339c ubuntu:12.04 bash 17 seconds ago Up 16 seconds 3300-3310/tcp webapp |
| 1568 | 1568 |
d7886598dbe2 crosbymichael/redis:latest /redis-server --dir 33 minutes ago Up 33 minutes 6379/tcp redis,webapp/db |
| ... | ... |
@@ -1585,7 +1592,7 @@ Current filters: |
| 1585 | 1585 |
|
| 1586 | 1586 |
##### Successfully exited containers |
| 1587 | 1587 |
|
| 1588 |
- $ sudo docker ps -a --filter 'exited=0' |
|
| 1588 |
+ $ docker ps -a --filter 'exited=0' |
|
| 1589 | 1589 |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
| 1590 | 1590 |
ea09c3c82f6e registry:latest /srv/run.sh 2 weeks ago Exited (0) 2 weeks ago 127.0.0.1:5000->5000/tcp desperate_leakey |
| 1591 | 1591 |
106ea823fe4e fedora:latest /bin/sh -c 'bash -l' 2 weeks ago Exited (0) 2 weeks ago determined_albattani |
| ... | ... |
@@ -1615,20 +1622,20 @@ a protocol specifier (`https://`, for example). |
| 1615 | 1615 |
To download a particular image, or set of images (i.e., a repository), |
| 1616 | 1616 |
use `docker pull`: |
| 1617 | 1617 |
|
| 1618 |
- $ sudo docker pull debian |
|
| 1618 |
+ $ docker pull debian |
|
| 1619 | 1619 |
# will pull the debian:latest image and its intermediate layers |
| 1620 |
- $ sudo docker pull debian:testing |
|
| 1620 |
+ $ docker pull debian:testing |
|
| 1621 | 1621 |
# will pull the image named debian:testing and any intermediate |
| 1622 | 1622 |
# layers it is based on. |
| 1623 |
- $ sudo docker pull debian@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf |
|
| 1623 |
+ $ docker pull debian@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf |
|
| 1624 | 1624 |
# will pull the image from the debian repository with the digest |
| 1625 | 1625 |
# sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf |
| 1626 | 1626 |
# and any intermediate layers it is based on. |
| 1627 | 1627 |
# (Typically the empty `scratch` image, a MAINTAINER layer, |
| 1628 | 1628 |
# and the un-tarred base). |
| 1629 |
- $ sudo docker pull --all-tags centos |
|
| 1629 |
+ $ docker pull --all-tags centos |
|
| 1630 | 1630 |
# will pull all the images from the centos repository |
| 1631 |
- $ sudo docker pull registry.hub.docker.com/debian |
|
| 1631 |
+ $ docker pull registry.hub.docker.com/debian |
|
| 1632 | 1632 |
# manually specifies the path to the default Docker registry. This could |
| 1633 | 1633 |
# be replaced with the path to a local registry to pull from another source. |
| 1634 | 1634 |
|
| ... | ... |
@@ -1669,19 +1676,19 @@ The `docker rename` command allows the container to be renamed to a different na |
| 1669 | 1669 |
|
| 1670 | 1670 |
#### Examples |
| 1671 | 1671 |
|
| 1672 |
- $ sudo docker rm /redis |
|
| 1672 |
+ $ docker rm /redis |
|
| 1673 | 1673 |
/redis |
| 1674 | 1674 |
|
| 1675 | 1675 |
This will remove the container referenced under the link |
| 1676 | 1676 |
`/redis`. |
| 1677 | 1677 |
|
| 1678 |
- $ sudo docker rm --link /webapp/redis |
|
| 1678 |
+ $ docker rm --link /webapp/redis |
|
| 1679 | 1679 |
/webapp/redis |
| 1680 | 1680 |
|
| 1681 | 1681 |
This will remove the underlying link between `/webapp` and the `/redis` |
| 1682 | 1682 |
containers removing all network communication. |
| 1683 | 1683 |
|
| 1684 |
- $ sudo docker rm --force redis |
|
| 1684 |
+ $ docker rm --force redis |
|
| 1685 | 1685 |
redis |
| 1686 | 1686 |
|
| 1687 | 1687 |
The main process inside the container referenced under the link `/redis` will receive |
| ... | ... |
@@ -1709,37 +1716,37 @@ You can remove an image using its short or long ID, its tag, or its digest. If |
| 1709 | 1709 |
an image has one or more tag or digest reference, you must remove all of them |
| 1710 | 1710 |
before the image is removed. |
| 1711 | 1711 |
|
| 1712 |
- $ sudo docker images |
|
| 1712 |
+ $ docker images |
|
| 1713 | 1713 |
REPOSITORY TAG IMAGE ID CREATED SIZE |
| 1714 | 1714 |
test1 latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB) |
| 1715 | 1715 |
test latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB) |
| 1716 | 1716 |
test2 latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB) |
| 1717 | 1717 |
|
| 1718 |
- $ sudo docker rmi fd484f19954f |
|
| 1718 |
+ $ docker rmi fd484f19954f |
|
| 1719 | 1719 |
Error: Conflict, cannot delete image fd484f19954f because it is tagged in multiple repositories, use -f to force |
| 1720 | 1720 |
2013/12/11 05:47:16 Error: failed to remove one or more images |
| 1721 | 1721 |
|
| 1722 |
- $ sudo docker rmi test1 |
|
| 1722 |
+ $ docker rmi test1 |
|
| 1723 | 1723 |
Untagged: test1:latest |
| 1724 |
- $ sudo docker rmi test2 |
|
| 1724 |
+ $ docker rmi test2 |
|
| 1725 | 1725 |
Untagged: test2:latest |
| 1726 | 1726 |
|
| 1727 |
- $ sudo docker images |
|
| 1727 |
+ $ docker images |
|
| 1728 | 1728 |
REPOSITORY TAG IMAGE ID CREATED SIZE |
| 1729 | 1729 |
test latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB) |
| 1730 |
- $ sudo docker rmi test |
|
| 1730 |
+ $ docker rmi test |
|
| 1731 | 1731 |
Untagged: test:latest |
| 1732 | 1732 |
Deleted: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8 |
| 1733 | 1733 |
|
| 1734 | 1734 |
An image pulled by digest has no tag associated with it: |
| 1735 | 1735 |
|
| 1736 |
- $ sudo docker images --digests |
|
| 1736 |
+ $ docker images --digests |
|
| 1737 | 1737 |
REPOSITORY TAG DIGEST IMAGE ID CREATED VIRTUAL SIZE |
| 1738 | 1738 |
localhost:5000/test/busybox <none> sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf 4986bf8c1536 9 weeks ago 2.43 MB |
| 1739 | 1739 |
|
| 1740 | 1740 |
To remove an image using its digest: |
| 1741 | 1741 |
|
| 1742 |
- $ sudo docker rmi localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf |
|
| 1742 |
+ $ docker rmi localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf |
|
| 1743 | 1743 |
Untagged: localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf |
| 1744 | 1744 |
Deleted: 4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125 |
| 1745 | 1745 |
Deleted: ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2 |
| ... | ... |
@@ -1814,12 +1821,12 @@ and linking containers. |
| 1814 | 1814 |
|
| 1815 | 1815 |
#### Examples |
| 1816 | 1816 |
|
| 1817 |
- $ sudo docker run --name test -it debian |
|
| 1817 |
+ $ docker run --name test -it debian |
|
| 1818 | 1818 |
$$ exit 13 |
| 1819 | 1819 |
exit |
| 1820 | 1820 |
$ echo $? |
| 1821 | 1821 |
13 |
| 1822 |
- $ sudo docker ps -a | grep test |
|
| 1822 |
+ $ docker ps -a | grep test |
|
| 1823 | 1823 |
275c44472aeb debian:7 "/bin/bash" 26 seconds ago Exited (13) 17 seconds ago test |
| 1824 | 1824 |
|
| 1825 | 1825 |
In this example, we are running `bash` interactively in the `debian:latest` image, and giving |
| ... | ... |
@@ -1827,14 +1834,14 @@ the container the name `test`. We then quit `bash` by running `exit 13`, which m |
| 1827 | 1827 |
will have an exit code of `13`. This is then passed on to the caller of `docker run`, and |
| 1828 | 1828 |
is recorded in the `test` container metadata. |
| 1829 | 1829 |
|
| 1830 |
- $ sudo docker run --cidfile /tmp/docker_test.cid ubuntu echo "test" |
|
| 1830 |
+ $ docker run --cidfile /tmp/docker_test.cid ubuntu echo "test" |
|
| 1831 | 1831 |
|
| 1832 | 1832 |
This will create a container and print `test` to the console. The `cidfile` |
| 1833 | 1833 |
flag makes Docker attempt to create a new file and write the container ID to it. |
| 1834 | 1834 |
If the file exists already, Docker will return an error. Docker will close this |
| 1835 | 1835 |
file when `docker run` exits. |
| 1836 | 1836 |
|
| 1837 |
- $ sudo docker run -t -i --rm ubuntu bash |
|
| 1837 |
+ $ docker run -t -i --rm ubuntu bash |
|
| 1838 | 1838 |
root@bc338942ef20:/# mount -t tmpfs none /mnt |
| 1839 | 1839 |
mount: permission denied |
| 1840 | 1840 |
|
| ... | ... |
@@ -1842,7 +1849,7 @@ This will *not* work, because by default, most potentially dangerous kernel |
| 1842 | 1842 |
capabilities are dropped; including `cap_sys_admin` (which is required to mount |
| 1843 | 1843 |
filesystems). However, the `--privileged` flag will allow it to run: |
| 1844 | 1844 |
|
| 1845 |
- $ sudo docker run --privileged ubuntu bash |
|
| 1845 |
+ $ docker run --privileged ubuntu bash |
|
| 1846 | 1846 |
root@50e3f57e16e6:/# mount -t tmpfs none /mnt |
| 1847 | 1847 |
root@50e3f57e16e6:/# df -h |
| 1848 | 1848 |
Filesystem Size Used Avail Use% Mounted on |
| ... | ... |
@@ -1853,12 +1860,12 @@ lifts all the limitations enforced by the `device` cgroup controller. In other |
| 1853 | 1853 |
words, the container can then do almost everything that the host can do. This |
| 1854 | 1854 |
flag exists to allow special use-cases, like running Docker within Docker. |
| 1855 | 1855 |
|
| 1856 |
- $ sudo docker run -w /path/to/dir/ -i -t ubuntu pwd |
|
| 1856 |
+ $ docker run -w /path/to/dir/ -i -t ubuntu pwd |
|
| 1857 | 1857 |
|
| 1858 | 1858 |
The `-w` lets the command being executed inside directory given, here |
| 1859 | 1859 |
`/path/to/dir/`. If the path does not exists it is created inside the container. |
| 1860 | 1860 |
|
| 1861 |
- $ sudo docker run -v `pwd`:`pwd` -w `pwd` -i -t ubuntu pwd |
|
| 1861 |
+ $ docker run -v `pwd`:`pwd` -w `pwd` -i -t ubuntu pwd |
|
| 1862 | 1862 |
|
| 1863 | 1863 |
The `-v` flag mounts the current working directory into the container. The `-w` |
| 1864 | 1864 |
lets the command being executed inside the current working directory, by |
| ... | ... |
@@ -1866,41 +1873,41 @@ changing into the directory to the value returned by `pwd`. So this |
| 1866 | 1866 |
combination executes the command using the container, but inside the |
| 1867 | 1867 |
current working directory. |
| 1868 | 1868 |
|
| 1869 |
- $ sudo docker run -v /doesnt/exist:/foo -w /foo -i -t ubuntu bash |
|
| 1869 |
+ $ docker run -v /doesnt/exist:/foo -w /foo -i -t ubuntu bash |
|
| 1870 | 1870 |
|
| 1871 | 1871 |
When the host directory of a bind-mounted volume doesn't exist, Docker |
| 1872 | 1872 |
will automatically create this directory on the host for you. In the |
| 1873 | 1873 |
example above, Docker will create the `/doesnt/exist` |
| 1874 | 1874 |
folder before starting your container. |
| 1875 | 1875 |
|
| 1876 |
- $ sudo docker run --read-only -v /icanwrite busybox touch /icanwrite here |
|
| 1876 |
+ $ docker run --read-only -v /icanwrite busybox touch /icanwrite here |
|
| 1877 | 1877 |
|
| 1878 | 1878 |
Volumes can be used in combination with `--read-only` to control where |
| 1879 | 1879 |
a container writes files. The `--read-only` flag mounts the container's root |
| 1880 | 1880 |
filesystem as read only prohibiting writes to locations other than the |
| 1881 | 1881 |
specified volumes for the container. |
| 1882 | 1882 |
|
| 1883 |
- $ sudo docker run -t -i -v /var/run/docker.sock:/var/run/docker.sock -v ./static-docker:/usr/bin/docker busybox sh |
|
| 1883 |
+ $ docker run -t -i -v /var/run/docker.sock:/var/run/docker.sock -v ./static-docker:/usr/bin/docker busybox sh |
|
| 1884 | 1884 |
|
| 1885 | 1885 |
By bind-mounting the docker unix socket and statically linked docker |
| 1886 | 1886 |
binary (such as that provided by [https://get.docker.com]( |
| 1887 | 1887 |
https://get.docker.com)), you give the container the full access to create and |
| 1888 | 1888 |
manipulate the host's Docker daemon. |
| 1889 | 1889 |
|
| 1890 |
- $ sudo docker run -p 127.0.0.1:80:8080 ubuntu bash |
|
| 1890 |
+ $ docker run -p 127.0.0.1:80:8080 ubuntu bash |
|
| 1891 | 1891 |
|
| 1892 | 1892 |
This binds port `8080` of the container to port `80` on `127.0.0.1` of |
| 1893 | 1893 |
the host machine. The [Docker User Guide](/userguide/dockerlinks/) |
| 1894 | 1894 |
explains in detail how to manipulate ports in Docker. |
| 1895 | 1895 |
|
| 1896 |
- $ sudo docker run --expose 80 ubuntu bash |
|
| 1896 |
+ $ docker run --expose 80 ubuntu bash |
|
| 1897 | 1897 |
|
| 1898 | 1898 |
This exposes port `80` of the container for use within a link without |
| 1899 | 1899 |
publishing the port to the host system's interfaces. The [Docker User |
| 1900 | 1900 |
Guide](/userguide/dockerlinks) explains in detail how to manipulate |
| 1901 | 1901 |
ports in Docker. |
| 1902 | 1902 |
|
| 1903 |
- $ sudo docker run -e MYVAR1 --env MYVAR2=foo --env-file ./env.list ubuntu bash |
|
| 1903 |
+ $ docker run -e MYVAR1 --env MYVAR2=foo --env-file ./env.list ubuntu bash |
|
| 1904 | 1904 |
|
| 1905 | 1905 |
This sets environmental variables in the container. For illustration all three |
| 1906 | 1906 |
flags are shown here. Where `-e`, `--env` take an environment variable and |
| ... | ... |
@@ -1917,7 +1924,7 @@ override variables as needed. |
| 1917 | 1917 |
|
| 1918 | 1918 |
$ cat ./env.list |
| 1919 | 1919 |
TEST_FOO=BAR |
| 1920 |
- $ sudo docker run --env TEST_FOO="This is a test" --env-file ./env.list busybox env | grep TEST_FOO |
|
| 1920 |
+ $ docker run --env TEST_FOO="This is a test" --env-file ./env.list busybox env | grep TEST_FOO |
|
| 1921 | 1921 |
TEST_FOO=This is a test |
| 1922 | 1922 |
|
| 1923 | 1923 |
The `--env-file` flag takes a filename as an argument and expects each line |
| ... | ... |
@@ -1944,11 +1951,11 @@ An example of a file passed with `--env-file` |
| 1944 | 1944 |
TEST_APP_DEST_PORT=8888 |
| 1945 | 1945 |
TEST_PASSTHROUGH=howdy |
| 1946 | 1946 |
|
| 1947 |
- $ sudo docker run --name console -t -i ubuntu bash |
|
| 1947 |
+ $ docker run --name console -t -i ubuntu bash |
|
| 1948 | 1948 |
|
| 1949 | 1949 |
A label is a a `key=value` pair that applies metadata to a container. To label a container with two labels: |
| 1950 | 1950 |
|
| 1951 |
- $ sudo docker run -l my-label --label com.example.foo=bar ubuntu bash |
|
| 1951 |
+ $ docker run -l my-label --label com.example.foo=bar ubuntu bash |
|
| 1952 | 1952 |
|
| 1953 | 1953 |
The `my-label` key doesn't specify a value so the label defaults to an empty |
| 1954 | 1954 |
string(`""`). To add multiple labels, repeat the label flag (`-l` or `--label`). |
| ... | ... |
@@ -1961,7 +1968,7 @@ Use the `--label-file` flag to load multiple labels from a file. Delimit each |
| 1961 | 1961 |
label in the file with an EOL mark. The example below loads labels from a |
| 1962 | 1962 |
labels file in the current directory: |
| 1963 | 1963 |
|
| 1964 |
- $ sudo docker run --label-file ./labels ubuntu bash |
|
| 1964 |
+ $ docker run --label-file ./labels ubuntu bash |
|
| 1965 | 1965 |
|
| 1966 | 1966 |
The label-file format is similar to the format for loading environment |
| 1967 | 1967 |
variables. (Unlike environment variables, labels are not visislbe to processes |
| ... | ... |
@@ -1980,7 +1987,7 @@ For additional information on working with labels, see [*Labels - custom |
| 1980 | 1980 |
metadata in Docker*](/userguide/labels-custom-metadata/) in the Docker User |
| 1981 | 1981 |
Guide. |
| 1982 | 1982 |
|
| 1983 |
- $ sudo docker run --link /redis:redis --name console ubuntu bash |
|
| 1983 |
+ $ docker run --link /redis:redis --name console ubuntu bash |
|
| 1984 | 1984 |
|
| 1985 | 1985 |
The `--link` flag will link the container named `/redis` into the newly |
| 1986 | 1986 |
created container with the alias `redis`. The new container can access the |
| ... | ... |
@@ -1988,7 +1995,7 @@ network and environment of the `redis` container via environment variables. |
| 1988 | 1988 |
The `--name` flag will assign the name `console` to the newly created |
| 1989 | 1989 |
container. |
| 1990 | 1990 |
|
| 1991 |
- $ sudo docker run --volumes-from 777f7dc92da7 --volumes-from ba8c0c54f0f2:ro -i -t ubuntu pwd |
|
| 1991 |
+ $ docker run --volumes-from 777f7dc92da7 --volumes-from ba8c0c54f0f2:ro -i -t ubuntu pwd |
|
| 1992 | 1992 |
|
| 1993 | 1993 |
The `--volumes-from` flag mounts all the defined volumes from the referenced |
| 1994 | 1994 |
containers. Containers can be specified by repetitions of the `--volumes-from` |
| ... | ... |
@@ -2000,18 +2007,18 @@ the reference container. |
| 2000 | 2000 |
The `-a` flag tells `docker run` to bind to the container's `STDIN`, `STDOUT` or |
| 2001 | 2001 |
`STDERR`. This makes it possible to manipulate the output and input as needed. |
| 2002 | 2002 |
|
| 2003 |
- $ echo "test" | sudo docker run -i -a stdin ubuntu cat - |
|
| 2003 |
+ $ echo "test" | docker run -i -a stdin ubuntu cat - |
|
| 2004 | 2004 |
|
| 2005 | 2005 |
This pipes data into a container and prints the container's ID by attaching |
| 2006 | 2006 |
only to the container's `STDIN`. |
| 2007 | 2007 |
|
| 2008 |
- $ sudo docker run -a stderr ubuntu echo test |
|
| 2008 |
+ $ docker run -a stderr ubuntu echo test |
|
| 2009 | 2009 |
|
| 2010 | 2010 |
This isn't going to print anything unless there's an error because we've |
| 2011 | 2011 |
only attached to the `STDERR` of the container. The container's logs |
| 2012 | 2012 |
still store what's been written to `STDERR` and `STDOUT`. |
| 2013 | 2013 |
|
| 2014 |
- $ cat somefile | sudo docker run -i -a stdin mybuilder dobuild |
|
| 2014 |
+ $ cat somefile | docker run -i -a stdin mybuilder dobuild |
|
| 2015 | 2015 |
|
| 2016 | 2016 |
This is how piping a file into a container could be done for a build. |
| 2017 | 2017 |
The container's ID will be printed after the build is done and the build |
| ... | ... |
@@ -2019,7 +2026,7 @@ logs could be retrieved using `docker logs`. This is |
| 2019 | 2019 |
useful if you need to pipe a file or something else into a container and |
| 2020 | 2020 |
retrieve the container's ID once the container has finished running. |
| 2021 | 2021 |
|
| 2022 |
- $ sudo docker run --device=/dev/sdc:/dev/xvdc --device=/dev/sdd --device=/dev/zero:/dev/nulo -i -t ubuntu ls -l /dev/{xvdc,sdd,nulo}
|
|
| 2022 |
+ $ docker run --device=/dev/sdc:/dev/xvdc --device=/dev/sdd --device=/dev/zero:/dev/nulo -i -t ubuntu ls -l /dev/{xvdc,sdd,nulo}
|
|
| 2023 | 2023 |
brw-rw---- 1 root disk 8, 2 Feb 9 16:05 /dev/xvdc |
| 2024 | 2024 |
brw-rw---- 1 root disk 8, 3 Feb 9 16:05 /dev/sdd |
| 2025 | 2025 |
crw-rw-rw- 1 root root 1, 5 Feb 9 16:05 /dev/nulo |
| ... | ... |
@@ -2035,19 +2042,19 @@ flag: |
| 2035 | 2035 |
|
| 2036 | 2036 |
|
| 2037 | 2037 |
``` |
| 2038 |
- $ sudo docker run --device=/dev/sda:/dev/xvdc --rm -it ubuntu fdisk /dev/xvdc |
|
| 2038 |
+ $ docker run --device=/dev/sda:/dev/xvdc --rm -it ubuntu fdisk /dev/xvdc |
|
| 2039 | 2039 |
|
| 2040 | 2040 |
Command (m for help): q |
| 2041 |
- $ sudo docker run --device=/dev/sda:/dev/xvdc:r --rm -it ubuntu fdisk /dev/xvdc |
|
| 2041 |
+ $ docker run --device=/dev/sda:/dev/xvdc:r --rm -it ubuntu fdisk /dev/xvdc |
|
| 2042 | 2042 |
You will not be able to write the partition table. |
| 2043 | 2043 |
|
| 2044 | 2044 |
Command (m for help): q |
| 2045 | 2045 |
|
| 2046 |
- $ sudo docker run --device=/dev/sda:/dev/xvdc --rm -it ubuntu fdisk /dev/xvdc |
|
| 2046 |
+ $ docker run --device=/dev/sda:/dev/xvdc --rm -it ubuntu fdisk /dev/xvdc |
|
| 2047 | 2047 |
|
| 2048 | 2048 |
Command (m for help): q |
| 2049 | 2049 |
|
| 2050 |
- $ sudo docker run --device=/dev/sda:/dev/xvdc:m --rm -it ubuntu fdisk /dev/xvdc |
|
| 2050 |
+ $ docker run --device=/dev/sda:/dev/xvdc:m --rm -it ubuntu fdisk /dev/xvdc |
|
| 2051 | 2051 |
fdisk: unable to open /dev/xvdc: Operation not permitted |
| 2052 | 2052 |
``` |
| 2053 | 2053 |
|
| ... | ... |
@@ -2057,11 +2064,11 @@ flag: |
| 2057 | 2057 |
|
| 2058 | 2058 |
**A complete example:** |
| 2059 | 2059 |
|
| 2060 |
- $ sudo docker run -d --name static static-web-files sh |
|
| 2061 |
- $ sudo docker run -d --expose=8098 --name riak riakserver |
|
| 2062 |
- $ sudo docker run -d -m 100m -e DEVELOPMENT=1 -e BRANCH=example-code -v $(pwd):/app/bin:ro --name app appserver |
|
| 2063 |
- $ sudo docker run -d -p 1443:443 --dns=10.0.0.1 --dns-search=dev.org -v /var/log/httpd --volumes-from static --link riak --link app -h www.sven.dev.org --name web webserver |
|
| 2064 |
- $ sudo docker run -t -i --rm --volumes-from web -w /var/log/httpd busybox tail -f access.log |
|
| 2060 |
+ $ docker run -d --name static static-web-files sh |
|
| 2061 |
+ $ docker run -d --expose=8098 --name riak riakserver |
|
| 2062 |
+ $ docker run -d -m 100m -e DEVELOPMENT=1 -e BRANCH=example-code -v $(pwd):/app/bin:ro --name app appserver |
|
| 2063 |
+ $ docker run -d -p 1443:443 --dns=10.0.0.1 --dns-search=dev.org -v /var/log/httpd --volumes-from static --link riak --link app -h www.sven.dev.org --name web webserver |
|
| 2064 |
+ $ docker run -t -i --rm --volumes-from web -w /var/log/httpd busybox tail -f access.log |
|
| 2065 | 2065 |
|
| 2066 | 2066 |
This example shows five containers that might be set up to test a web |
| 2067 | 2067 |
application change: |
| ... | ... |
@@ -2130,7 +2137,7 @@ Docker supports the following restart policies: |
| 2130 | 2130 |
</tbody> |
| 2131 | 2131 |
</table> |
| 2132 | 2132 |
|
| 2133 |
- $ sudo docker run --restart=always redis |
|
| 2133 |
+ $ docker run --restart=always redis |
|
| 2134 | 2134 |
|
| 2135 | 2135 |
This will run the `redis` container with a restart policy of **always** |
| 2136 | 2136 |
so that if the container exits, Docker will restart it. |
| ... | ... |
@@ -2202,18 +2209,18 @@ each argument provided. |
| 2202 | 2202 |
|
| 2203 | 2203 |
It is used to create a backup that can then be used with `docker load` |
| 2204 | 2204 |
|
| 2205 |
- $ sudo docker save busybox > busybox.tar |
|
| 2205 |
+ $ docker save busybox > busybox.tar |
|
| 2206 | 2206 |
$ ls -sh busybox.tar |
| 2207 | 2207 |
2.7M busybox.tar |
| 2208 |
- $ sudo docker save --output busybox.tar busybox |
|
| 2208 |
+ $ docker save --output busybox.tar busybox |
|
| 2209 | 2209 |
$ ls -sh busybox.tar |
| 2210 | 2210 |
2.7M busybox.tar |
| 2211 |
- $ sudo docker save -o fedora-all.tar fedora |
|
| 2212 |
- $ sudo docker save -o fedora-latest.tar fedora:latest |
|
| 2211 |
+ $ docker save -o fedora-all.tar fedora |
|
| 2212 |
+ $ docker save -o fedora-latest.tar fedora:latest |
|
| 2213 | 2213 |
|
| 2214 | 2214 |
It is even useful to cherry-pick particular tags of an image repository |
| 2215 | 2215 |
|
| 2216 |
- $ sudo docker save -o ubuntu.tar ubuntu:lucid ubuntu:saucy |
|
| 2216 |
+ $ docker save -o ubuntu.tar ubuntu:lucid ubuntu:saucy |
|
| 2217 | 2217 |
|
| 2218 | 2218 |
## search |
| 2219 | 2219 |
|
| ... | ... |
@@ -2253,7 +2260,7 @@ more details on finding shared images from the command line. |
| 2253 | 2253 |
|
| 2254 | 2254 |
Running `docker stats` on multiple containers |
| 2255 | 2255 |
|
| 2256 |
- $ sudo docker stats redis1 redis2 |
|
| 2256 |
+ $ docker stats redis1 redis2 |
|
| 2257 | 2257 |
CONTAINER CPU % MEM USAGE/LIMIT MEM % NET I/O |
| 2258 | 2258 |
redis1 0.07% 796 KiB/64 MiB 1.21% 788 B/648 B |
| 2259 | 2259 |
redis2 0.07% 2.746 MiB/64 MiB 4.29% 1.266 KiB/648 B |
| ... | ... |
@@ -2317,7 +2324,7 @@ for further details. |
| 2317 | 2317 |
Show the Docker version, API version, Git commit, Go version and OS/architecture |
| 2318 | 2318 |
of both Docker client and daemon. Example use: |
| 2319 | 2319 |
|
| 2320 |
- $ sudo docker version |
|
| 2320 |
+ $ docker version |
|
| 2321 | 2321 |
Client version: 1.5.0 |
| 2322 | 2322 |
Client API version: 1.17 |
| 2323 | 2323 |
Go version (client): go1.4.1 |
| ... | ... |
@@ -13,11 +13,11 @@ server. |
| 13 | 13 |
Images can be associated with a repository (or multiple) by giving them |
| 14 | 14 |
an image name using one of three different commands: |
| 15 | 15 |
|
| 16 |
-1. At build time (e.g., `sudo docker build -t IMAGENAME`), |
|
| 16 |
+1. At build time (e.g., `docker build -t IMAGENAME`), |
|
| 17 | 17 |
2. When committing a container (e.g., |
| 18 |
- `sudo docker commit CONTAINERID IMAGENAME`) or |
|
| 18 |
+ `docker commit CONTAINERID IMAGENAME`) or |
|
| 19 | 19 |
3. When tagging an image id with an image name (e.g., |
| 20 |
- `sudo docker tag IMAGEID IMAGENAME`). |
|
| 20 |
+ `docker tag IMAGEID IMAGENAME`). |
|
| 21 | 21 |
|
| 22 | 22 |
A Fully Qualified Image Name (FQIN) can be made up of 3 parts: |
| 23 | 23 |
|
| ... | ... |
@@ -42,7 +42,7 @@ going on in the world of Docker. |
| 42 | 42 |
You can also create a Docker Hub account via the command line with the |
| 43 | 43 |
`docker login` command. |
| 44 | 44 |
|
| 45 |
- $ sudo docker login |
|
| 45 |
+ $ docker login |
|
| 46 | 46 |
|
| 47 | 47 |
### Confirm your email |
| 48 | 48 |
|
| ... | ... |
@@ -58,7 +58,7 @@ After you complete the confirmation process, you can login using the web console |
| 58 | 58 |
|
| 59 | 59 |
Or via the command line with the `docker login` command: |
| 60 | 60 |
|
| 61 |
- $ sudo docker login |
|
| 61 |
+ $ docker login |
|
| 62 | 62 |
|
| 63 | 63 |
Your Docker Hub account is now active and ready to use. |
| 64 | 64 |
|
| ... | ... |
@@ -27,7 +27,7 @@ including: |
| 27 | 27 |
Let's start with listing the images we have locally on our host. You can |
| 28 | 28 |
do this using the `docker images` command like so: |
| 29 | 29 |
|
| 30 |
- $ sudo docker images |
|
| 30 |
+ $ docker images |
|
| 31 | 31 |
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE |
| 32 | 32 |
training/webapp latest fc77f57ad303 3 weeks ago 280.5 MB |
| 33 | 33 |
ubuntu 13.10 5e019ab7bf6d 4 weeks ago 180 MB |
| ... | ... |
@@ -63,11 +63,11 @@ refer to a tagged image like so: |
| 63 | 63 |
|
| 64 | 64 |
So when we run a container we refer to a tagged image like so: |
| 65 | 65 |
|
| 66 |
- $ sudo docker run -t -i ubuntu:14.04 /bin/bash |
|
| 66 |
+ $ docker run -t -i ubuntu:14.04 /bin/bash |
|
| 67 | 67 |
|
| 68 | 68 |
If instead we wanted to run an Ubuntu 12.04 image we'd use: |
| 69 | 69 |
|
| 70 |
- $ sudo docker run -t -i ubuntu:12.04 /bin/bash |
|
| 70 |
+ $ docker run -t -i ubuntu:12.04 /bin/bash |
|
| 71 | 71 |
|
| 72 | 72 |
If you don't specify a variant, for example you just use `ubuntu`, then Docker |
| 73 | 73 |
will default to using the `ubuntu:latest` image. |
| ... | ... |
@@ -85,7 +85,7 @@ add some time to the launch of a container. If we want to pre-load an image we |
| 85 | 85 |
can download it using the `docker pull` command. Let's say we'd like to |
| 86 | 86 |
download the `centos` image. |
| 87 | 87 |
|
| 88 |
- $ sudo docker pull centos |
|
| 88 |
+ $ docker pull centos |
|
| 89 | 89 |
Pulling repository centos |
| 90 | 90 |
b7de3133ff98: Pulling dependent layers |
| 91 | 91 |
5cc9e91966f7: Pulling fs layer |
| ... | ... |
@@ -99,7 +99,7 @@ We can see that each layer of the image has been pulled down and now we |
| 99 | 99 |
can run a container from this image and we won't have to wait to |
| 100 | 100 |
download the image. |
| 101 | 101 |
|
| 102 |
- $ sudo docker run -t -i centos /bin/bash |
|
| 102 |
+ $ docker run -t -i centos /bin/bash |
|
| 103 | 103 |
bash-4.1# |
| 104 | 104 |
|
| 105 | 105 |
## Finding images |
| ... | ... |
@@ -117,7 +117,7 @@ which to do our web application development. We can search for a suitable image |
| 117 | 117 |
by using the `docker search` command to find all the images that contain the |
| 118 | 118 |
term `sinatra`. |
| 119 | 119 |
|
| 120 |
- $ sudo docker search sinatra |
|
| 120 |
+ $ docker search sinatra |
|
| 121 | 121 |
NAME DESCRIPTION STARS OFFICIAL AUTOMATED |
| 122 | 122 |
training/sinatra Sinatra training image 0 [OK] |
| 123 | 123 |
marceldegraaf/sinatra Sinatra test app 0 |
| ... | ... |
@@ -152,11 +152,11 @@ prefixed with the user name, here `training`, of the user that created them. |
| 152 | 152 |
|
| 153 | 153 |
We've identified a suitable image, `training/sinatra`, and now we can download it using the `docker pull` command. |
| 154 | 154 |
|
| 155 |
- $ sudo docker pull training/sinatra |
|
| 155 |
+ $ docker pull training/sinatra |
|
| 156 | 156 |
|
| 157 | 157 |
The team can now use this image by running their own containers. |
| 158 | 158 |
|
| 159 |
- $ sudo docker run -t -i training/sinatra /bin/bash |
|
| 159 |
+ $ docker run -t -i training/sinatra /bin/bash |
|
| 160 | 160 |
root@a8cb6ce02d85:/# |
| 161 | 161 |
|
| 162 | 162 |
## Creating our own images |
| ... | ... |
@@ -174,7 +174,7 @@ update and create images. |
| 174 | 174 |
To update an image we first need to create a container from the image |
| 175 | 175 |
we'd like to update. |
| 176 | 176 |
|
| 177 |
- $ sudo docker run -t -i training/sinatra /bin/bash |
|
| 177 |
+ $ docker run -t -i training/sinatra /bin/bash |
|
| 178 | 178 |
root@0b2616b0e5a8:/# |
| 179 | 179 |
|
| 180 | 180 |
> **Note:** |
| ... | ... |
@@ -192,7 +192,7 @@ Now we have a container with the change we want to make. We can then |
| 192 | 192 |
commit a copy of this container to an image using the `docker commit` |
| 193 | 193 |
command. |
| 194 | 194 |
|
| 195 |
- $ sudo docker commit -m "Added json gem" -a "Kate Smith" \ |
|
| 195 |
+ $ docker commit -m "Added json gem" -a "Kate Smith" \ |
|
| 196 | 196 |
0b2616b0e5a8 ouruser/sinatra:v2 |
| 197 | 197 |
4f177bd27a9ff0f6dc2a830403925b5360bfe0b93d476f7fc3231110e7f71b1c |
| 198 | 198 |
|
| ... | ... |
@@ -215,7 +215,7 @@ the image: `v2`. |
| 215 | 215 |
We can then look at our new `ouruser/sinatra` image using the `docker images` |
| 216 | 216 |
command. |
| 217 | 217 |
|
| 218 |
- $ sudo docker images |
|
| 218 |
+ $ docker images |
|
| 219 | 219 |
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE |
| 220 | 220 |
training/sinatra latest 5bc342fa0b91 10 hours ago 446.7 MB |
| 221 | 221 |
ouruser/sinatra v2 3c59e02ddd1a 10 hours ago 446.7 MB |
| ... | ... |
@@ -223,7 +223,7 @@ command. |
| 223 | 223 |
|
| 224 | 224 |
To use our new image to create a container we can then: |
| 225 | 225 |
|
| 226 |
- $ sudo docker run -t -i ouruser/sinatra:v2 /bin/bash |
|
| 226 |
+ $ docker run -t -i ouruser/sinatra:v2 /bin/bash |
|
| 227 | 227 |
root@78e82f680994:/# |
| 228 | 228 |
|
| 229 | 229 |
### Building an image from a `Dockerfile` |
| ... | ... |
@@ -273,7 +273,7 @@ Sinatra gem. |
| 273 | 273 |
|
| 274 | 274 |
Now let's take our `Dockerfile` and use the `docker build` command to build an image. |
| 275 | 275 |
|
| 276 |
- $ sudo docker build -t ouruser/sinatra:v2 . |
|
| 276 |
+ $ docker build -t ouruser/sinatra:v2 . |
|
| 277 | 277 |
Sending build context to Docker daemon 2.048 kB |
| 278 | 278 |
Sending build context to Docker daemon |
| 279 | 279 |
Step 0 : FROM ubuntu:14.04 |
| ... | ... |
@@ -467,7 +467,7 @@ containers will get removed to clean things up. |
| 467 | 467 |
|
| 468 | 468 |
We can then create a container from our new image. |
| 469 | 469 |
|
| 470 |
- $ sudo docker run -t -i ouruser/sinatra:v2 /bin/bash |
|
| 470 |
+ $ docker run -t -i ouruser/sinatra:v2 /bin/bash |
|
| 471 | 471 |
root@8196968dac35:/# |
| 472 | 472 |
|
| 473 | 473 |
> **Note:** |
| ... | ... |
@@ -489,14 +489,14 @@ You can also add a tag to an existing image after you commit or build it. We |
| 489 | 489 |
can do this using the `docker tag` command. Let's add a new tag to our |
| 490 | 490 |
`ouruser/sinatra` image. |
| 491 | 491 |
|
| 492 |
- $ sudo docker tag 5db5f8471261 ouruser/sinatra:devel |
|
| 492 |
+ $ docker tag 5db5f8471261 ouruser/sinatra:devel |
|
| 493 | 493 |
|
| 494 | 494 |
The `docker tag` command takes the ID of the image, here `5db5f8471261`, and our |
| 495 | 495 |
user name, the repository name and the new tag. |
| 496 | 496 |
|
| 497 | 497 |
Let's see our new tag using the `docker images` command. |
| 498 | 498 |
|
| 499 |
- $ sudo docker images ouruser/sinatra |
|
| 499 |
+ $ docker images ouruser/sinatra |
|
| 500 | 500 |
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE |
| 501 | 501 |
ouruser/sinatra latest 5db5f8471261 11 hours ago 446.7 MB |
| 502 | 502 |
ouruser/sinatra devel 5db5f8471261 11 hours ago 446.7 MB |
| ... | ... |
@@ -509,7 +509,7 @@ Hub](https://hub.docker.com) using the `docker push` command. This |
| 509 | 509 |
allows you to share it with others, either publicly, or push it into [a |
| 510 | 510 |
private repository](https://registry.hub.docker.com/plans/). |
| 511 | 511 |
|
| 512 |
- $ sudo docker push ouruser/sinatra |
|
| 512 |
+ $ docker push ouruser/sinatra |
|
| 513 | 513 |
The push refers to a repository [ouruser/sinatra] (len: 1) |
| 514 | 514 |
Sending image list |
| 515 | 515 |
Pushing repository ouruser/sinatra (3 tags) |
| ... | ... |
@@ -523,7 +523,7 @@ containers]( |
| 523 | 523 |
|
| 524 | 524 |
Let's delete the `training/sinatra` image as we don't need it anymore. |
| 525 | 525 |
|
| 526 |
- $ sudo docker rmi training/sinatra |
|
| 526 |
+ $ docker rmi training/sinatra |
|
| 527 | 527 |
Untagged: training/sinatra:latest |
| 528 | 528 |
Deleted: 5bc342fa0b91cabf65246837015197eecfa24b2213ed6a51a8974ae250fedd8d |
| 529 | 529 |
Deleted: ed0fffdcdae5eb2c3a55549857a8be7fc8bc4241fb19ad714364cbfd7a56b22f |
| ... | ... |
@@ -15,7 +15,7 @@ application inside a container takes a single command: `docker run`. |
| 15 | 15 |
|
| 16 | 16 |
Let's try it now. |
| 17 | 17 |
|
| 18 |
- $ sudo docker run ubuntu:14.04 /bin/echo 'Hello world' |
|
| 18 |
+ $ docker run ubuntu:14.04 /bin/echo 'Hello world' |
|
| 19 | 19 |
Hello world |
| 20 | 20 |
|
| 21 | 21 |
And you just launched your first container! |
| ... | ... |
@@ -53,7 +53,7 @@ only run as long as the command you specify is active. Here, as soon as |
| 53 | 53 |
Let's try the `docker run` command again, this time specifying a new |
| 54 | 54 |
command to run in our container. |
| 55 | 55 |
|
| 56 |
- $ sudo docker run -t -i ubuntu:14.04 /bin/bash |
|
| 56 |
+ $ docker run -t -i ubuntu:14.04 /bin/bash |
|
| 57 | 57 |
root@af8bae53bdd3:/# |
| 58 | 58 |
|
| 59 | 59 |
Here we've again specified the `docker run` command and launched an |
| ... | ... |
@@ -98,7 +98,7 @@ like most of the applications we're probably going to run with Docker. |
| 98 | 98 |
|
| 99 | 99 |
Again we can do this with the `docker run` command: |
| 100 | 100 |
|
| 101 |
- $ sudo docker run -d ubuntu:14.04 /bin/sh -c "while true; do echo hello world; sleep 1; done" |
|
| 101 |
+ $ docker run -d ubuntu:14.04 /bin/sh -c "while true; do echo hello world; sleep 1; done" |
|
| 102 | 102 |
1e5535038e285177d5214659a068137486f96ee5c2e85a4ac52dc83f2ebe4147 |
| 103 | 103 |
|
| 104 | 104 |
Wait, what? Where's our "hello world" output? Let's look at what we've run here. |
| ... | ... |
@@ -135,7 +135,7 @@ do that with the `docker ps` command. The `docker ps` command queries |
| 135 | 135 |
the Docker daemon for information about all the containers it knows |
| 136 | 136 |
about. |
| 137 | 137 |
|
| 138 |
- $ sudo docker ps |
|
| 138 |
+ $ docker ps |
|
| 139 | 139 |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
| 140 | 140 |
1e5535038e28 ubuntu:14.04 /bin/sh -c 'while tr 2 minutes ago Up 1 minute insane_babbage |
| 141 | 141 |
|
| ... | ... |
@@ -155,7 +155,7 @@ Okay, so we now know it's running. But is it doing what we asked it to do? To se |
| 155 | 155 |
we're going to look inside the container using the `docker logs` |
| 156 | 156 |
command. Let's use the container name Docker assigned. |
| 157 | 157 |
|
| 158 |
- $ sudo docker logs insane_babbage |
|
| 158 |
+ $ docker logs insane_babbage |
|
| 159 | 159 |
hello world |
| 160 | 160 |
hello world |
| 161 | 161 |
hello world |
| ... | ... |
@@ -171,7 +171,7 @@ Now we've established we can create our own containers let's tidy up |
| 171 | 171 |
after ourselves and stop our daemonized container. To do this we use the |
| 172 | 172 |
`docker stop` command. |
| 173 | 173 |
|
| 174 |
- $ sudo docker stop insane_babbage |
|
| 174 |
+ $ docker stop insane_babbage |
|
| 175 | 175 |
insane_babbage |
| 176 | 176 |
|
| 177 | 177 |
The `docker stop` command tells Docker to politely stop the running |
| ... | ... |
@@ -180,7 +180,7 @@ has just stopped. |
| 180 | 180 |
|
| 181 | 181 |
Let's check it worked with the `docker ps` command. |
| 182 | 182 |
|
| 183 |
- $ sudo docker ps |
|
| 183 |
+ $ docker ps |
|
| 184 | 184 |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
| 185 | 185 |
|
| 186 | 186 |
Excellent. Our container has been stopped. |
| ... | ... |
@@ -16,7 +16,7 @@ container linking. |
| 16 | 16 |
In [the Using Docker section](/userguide/usingdocker), you created a |
| 17 | 17 |
container that ran a Python Flask application: |
| 18 | 18 |
|
| 19 |
- $ sudo docker run -d -P training/webapp python app.py |
|
| 19 |
+ $ docker run -d -P training/webapp python app.py |
|
| 20 | 20 |
|
| 21 | 21 |
> **Note:** |
| 22 | 22 |
> Containers have an internal network and an IP address |
| ... | ... |
@@ -30,14 +30,14 @@ any network port inside it to a random high port within an *ephemeral port |
| 30 | 30 |
range* on your Docker host. Next, when `docker ps` was run, you saw that port |
| 31 | 31 |
5000 in the container was bound to port 49155 on the host. |
| 32 | 32 |
|
| 33 |
- $ sudo docker ps nostalgic_morse |
|
| 33 |
+ $ docker ps nostalgic_morse |
|
| 34 | 34 |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
| 35 | 35 |
bc533791f3f5 training/webapp:latest python app.py 5 seconds ago Up 2 seconds 0.0.0.0:49155->5000/tcp nostalgic_morse |
| 36 | 36 |
|
| 37 | 37 |
You also saw how you can bind a container's ports to a specific port using |
| 38 | 38 |
the `-p` flag: |
| 39 | 39 |
|
| 40 |
- $ sudo docker run -d -p 5000:5000 training/webapp python app.py |
|
| 40 |
+ $ docker run -d -p 5000:5000 training/webapp python app.py |
|
| 41 | 41 |
|
| 42 | 42 |
And you saw why this isn't such a great idea because it constrains you to |
| 43 | 43 |
only one container on that specific port. |
| ... | ... |
@@ -47,7 +47,7 @@ default the `-p` flag will bind the specified port to all interfaces on |
| 47 | 47 |
the host machine. But you can also specify a binding to a specific |
| 48 | 48 |
interface, for example only to the `localhost`. |
| 49 | 49 |
|
| 50 |
- $ sudo docker run -d -p 127.0.0.1:5000:5000 training/webapp python app.py |
|
| 50 |
+ $ docker run -d -p 127.0.0.1:5000:5000 training/webapp python app.py |
|
| 51 | 51 |
|
| 52 | 52 |
This would bind port 5000 inside the container to port 5000 on the |
| 53 | 53 |
`localhost` or `127.0.0.1` interface on the host machine. |
| ... | ... |
@@ -55,18 +55,18 @@ This would bind port 5000 inside the container to port 5000 on the |
| 55 | 55 |
Or, to bind port 5000 of the container to a dynamic port but only on the |
| 56 | 56 |
`localhost`, you could use: |
| 57 | 57 |
|
| 58 |
- $ sudo docker run -d -p 127.0.0.1::5000 training/webapp python app.py |
|
| 58 |
+ $ docker run -d -p 127.0.0.1::5000 training/webapp python app.py |
|
| 59 | 59 |
|
| 60 | 60 |
You can also bind UDP ports by adding a trailing `/udp`. For example: |
| 61 | 61 |
|
| 62 |
- $ sudo docker run -d -p 127.0.0.1:5000:5000/udp training/webapp python app.py |
|
| 62 |
+ $ docker run -d -p 127.0.0.1:5000:5000/udp training/webapp python app.py |
|
| 63 | 63 |
|
| 64 | 64 |
You also learned about the useful `docker port` shortcut which showed us the |
| 65 | 65 |
current port bindings. This is also useful for showing you specific port |
| 66 | 66 |
configurations. For example, if you've bound the container port to the |
| 67 | 67 |
`localhost` on the host machine, then the `docker port` output will reflect that. |
| 68 | 68 |
|
| 69 |
- $ sudo docker port nostalgic_morse 5000 |
|
| 69 |
+ $ docker port nostalgic_morse 5000 |
|
| 70 | 70 |
127.0.0.1:49155 |
| 71 | 71 |
|
| 72 | 72 |
> **Note:** |
| ... | ... |
@@ -98,19 +98,19 @@ yourself. This naming provides two useful functions: |
| 98 | 98 |
|
| 99 | 99 |
You can name your container by using the `--name` flag, for example: |
| 100 | 100 |
|
| 101 |
- $ sudo docker run -d -P --name web training/webapp python app.py |
|
| 101 |
+ $ docker run -d -P --name web training/webapp python app.py |
|
| 102 | 102 |
|
| 103 | 103 |
This launches a new container and uses the `--name` flag to |
| 104 | 104 |
name the container `web`. You can see the container's name using the |
| 105 | 105 |
`docker ps` command. |
| 106 | 106 |
|
| 107 |
- $ sudo docker ps -l |
|
| 107 |
+ $ docker ps -l |
|
| 108 | 108 |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
| 109 | 109 |
aed84ee21bde training/webapp:latest python app.py 12 hours ago Up 2 seconds 0.0.0.0:49154->5000/tcp web |
| 110 | 110 |
|
| 111 | 111 |
You can also use `docker inspect` to return the container's name. |
| 112 | 112 |
|
| 113 |
- $ sudo docker inspect -f "{{ .Name }}" aed84ee21bde
|
|
| 113 |
+ $ docker inspect -f "{{ .Name }}" aed84ee21bde
|
|
| 114 | 114 |
/web |
| 115 | 115 |
|
| 116 | 116 |
> **Note:** |
| ... | ... |
@@ -129,7 +129,7 @@ source container and a recipient container. The recipient can then access select |
| 129 | 129 |
about the source. To create a link, you use the `--link` flag. First, create a new |
| 130 | 130 |
container, this time one containing a database. |
| 131 | 131 |
|
| 132 |
- $ sudo docker run -d --name db training/postgres |
|
| 132 |
+ $ docker run -d --name db training/postgres |
|
| 133 | 133 |
|
| 134 | 134 |
This creates a new container called `db` from the `training/postgres` |
| 135 | 135 |
image, which contains a PostgreSQL database. |
| ... | ... |
@@ -137,11 +137,11 @@ image, which contains a PostgreSQL database. |
| 137 | 137 |
Now, you need to delete the `web` container you created previously so you can replace it |
| 138 | 138 |
with a linked one: |
| 139 | 139 |
|
| 140 |
- $ sudo docker rm -f web |
|
| 140 |
+ $ docker rm -f web |
|
| 141 | 141 |
|
| 142 | 142 |
Now, create a new `web` container and link it with your `db` container. |
| 143 | 143 |
|
| 144 |
- $ sudo docker run -d -P --name web --link db:db training/webapp python app.py |
|
| 144 |
+ $ docker run -d -P --name web --link db:db training/webapp python app.py |
|
| 145 | 145 |
|
| 146 | 146 |
This will link the new `web` container with the `db` container you created |
| 147 | 147 |
earlier. The `--link` flag takes the form: |
| ... | ... |
@@ -153,7 +153,7 @@ alias for the link name. You'll see how that alias gets used shortly. |
| 153 | 153 |
|
| 154 | 154 |
Next, inspect your linked containers with `docker inspect`: |
| 155 | 155 |
|
| 156 |
- $ sudo docker inspect -f "{{ .HostConfig.Links }}" web
|
|
| 156 |
+ $ docker inspect -f "{{ .HostConfig.Links }}" web
|
|
| 157 | 157 |
[/db:/web/db] |
| 158 | 158 |
|
| 159 | 159 |
You can see that the `web` container is now linked to the `db` container |
| ... | ... |
@@ -239,7 +239,7 @@ Returning back to our database example, you can run the `env` |
| 239 | 239 |
command to list the specified container's environment variables. |
| 240 | 240 |
|
| 241 | 241 |
``` |
| 242 |
- $ sudo docker run --rm --name web2 --link db:db training/webapp env |
|
| 242 |
+ $ docker run --rm --name web2 --link db:db training/webapp env |
|
| 243 | 243 |
. . . |
| 244 | 244 |
DB_NAME=/web2/db |
| 245 | 245 |
DB_PORT=tcp://172.17.0.5:5432 |
| ... | ... |
@@ -276,7 +276,7 @@ In addition to the environment variables, Docker adds a host entry for the |
| 276 | 276 |
source container to the `/etc/hosts` file. Here's an entry for the `web` |
| 277 | 277 |
container: |
| 278 | 278 |
|
| 279 |
- $ sudo docker run -t -i --rm --link db:webdb training/webapp /bin/bash |
|
| 279 |
+ $ docker run -t -i --rm --link db:webdb training/webapp /bin/bash |
|
| 280 | 280 |
root@aed84ee21bde:/opt/webapp# cat /etc/hosts |
| 281 | 281 |
172.17.0.7 aed84ee21bde |
| 282 | 282 |
. . . |
| ... | ... |
@@ -314,9 +314,9 @@ If you restart the source container, the linked containers `/etc/hosts` files |
| 314 | 314 |
will be automatically updated with the source container's new IP address, |
| 315 | 315 |
allowing linked communication to continue. |
| 316 | 316 |
|
| 317 |
- $ sudo docker restart db |
|
| 317 |
+ $ docker restart db |
|
| 318 | 318 |
db |
| 319 |
- $ sudo docker run -t -i --rm --link db:db training/webapp /bin/bash |
|
| 319 |
+ $ docker run -t -i --rm --link db:db training/webapp /bin/bash |
|
| 320 | 320 |
root@aed84ee21bde:/opt/webapp# cat /etc/hosts |
| 321 | 321 |
172.17.0.7 aed84ee21bde |
| 322 | 322 |
. . . |
| ... | ... |
@@ -27,7 +27,7 @@ Typically, you'll want to start by creating an account on Docker Hub (if you hav |
| 27 | 27 |
already) and logging in. You can create your account directly on |
| 28 | 28 |
[Docker Hub](https://hub.docker.com/account/signup/), or by running: |
| 29 | 29 |
|
| 30 |
- $ sudo docker login |
|
| 30 |
+ $ docker login |
|
| 31 | 31 |
|
| 32 | 32 |
This will prompt you for a user name, which will become the public namespace for your |
| 33 | 33 |
public repositories. |
| ... | ... |
@@ -45,7 +45,7 @@ You can search the [Docker Hub](https://hub.docker.com) registry via its search |
| 45 | 45 |
interface or by using the command line interface. Searching can find images by image |
| 46 | 46 |
name, user name, or description: |
| 47 | 47 |
|
| 48 |
- $ sudo docker search centos |
|
| 48 |
+ $ docker search centos |
|
| 49 | 49 |
NAME DESCRIPTION STARS OFFICIAL TRUSTED |
| 50 | 50 |
centos Official CentOS 6 Image as of 12 April 2014 88 |
| 51 | 51 |
tianon/centos CentOS 5 and 6, created using rinse instea... 21 |
| ... | ... |
@@ -60,7 +60,7 @@ repository from the image name. |
| 60 | 60 |
|
| 61 | 61 |
Once you've found the image you want, you can download it with `docker pull <imagename>`: |
| 62 | 62 |
|
| 63 |
- $ sudo docker pull centos |
|
| 63 |
+ $ docker pull centos |
|
| 64 | 64 |
Pulling repository centos |
| 65 | 65 |
0b443ba03958: Download complete |
| 66 | 66 |
539c0211cd76: Download complete |
| ... | ... |
@@ -86,7 +86,7 @@ or committed your container to a named image as we saw |
| 86 | 86 |
|
| 87 | 87 |
Now you can push this repository to the registry designated by its name or tag. |
| 88 | 88 |
|
| 89 |
- $ sudo docker push yourname/newimage |
|
| 89 |
+ $ docker push yourname/newimage |
|
| 90 | 90 |
|
| 91 | 91 |
The image will then be uploaded and available for use by your team-mates and/or the |
| 92 | 92 |
community. |
| ... | ... |
@@ -44,7 +44,7 @@ You can add a data volume to a container using the `-v` flag with the |
| 44 | 44 |
to mount multiple data volumes. Let's mount a single volume now in our web |
| 45 | 45 |
application container. |
| 46 | 46 |
|
| 47 |
- $ sudo docker run -d -P --name web -v /webapp training/webapp python app.py |
|
| 47 |
+ $ docker run -d -P --name web -v /webapp training/webapp python app.py |
|
| 48 | 48 |
|
| 49 | 49 |
This will create a new volume inside a container at `/webapp`. |
| 50 | 50 |
|
| ... | ... |
@@ -86,7 +86,7 @@ directory from your Docker daemon's host into a container. |
| 86 | 86 |
> `docker run -v /c/Users/<path>:/<container path ...` (Windows). All other paths |
| 87 | 87 |
> come from the Boot2Docker virtual machine's filesystem. |
| 88 | 88 |
|
| 89 |
- $ sudo docker run -d -P --name web -v /src/webapp:/opt/webapp training/webapp python app.py |
|
| 89 |
+ $ docker run -d -P --name web -v /src/webapp:/opt/webapp training/webapp python app.py |
|
| 90 | 90 |
|
| 91 | 91 |
This will mount the host directory, `/src/webapp`, into the container at |
| 92 | 92 |
`/opt/webapp`. |
| ... | ... |
@@ -111,7 +111,7 @@ create it for you. |
| 111 | 111 |
Docker defaults to a read-write volume but we can also mount a directory |
| 112 | 112 |
read-only. |
| 113 | 113 |
|
| 114 |
- $ sudo docker run -d -P --name web -v /src/webapp:/opt/webapp:ro training/webapp python app.py |
|
| 114 |
+ $ docker run -d -P --name web -v /src/webapp:/opt/webapp:ro training/webapp python app.py |
|
| 115 | 115 |
|
| 116 | 116 |
Here we've mounted the same `/src/webapp` directory but we've added the `ro` |
| 117 | 117 |
option to specify that the mount should be read-only. |
| ... | ... |
@@ -121,7 +121,7 @@ option to specify that the mount should be read-only. |
| 121 | 121 |
The `-v` flag can also be used to mount a single file - instead of *just* |
| 122 | 122 |
directories - from the host machine. |
| 123 | 123 |
|
| 124 |
- $ sudo docker run --rm -it -v ~/.bash_history:/.bash_history ubuntu /bin/bash |
|
| 124 |
+ $ docker run --rm -it -v ~/.bash_history:/.bash_history ubuntu /bin/bash |
|
| 125 | 125 |
|
| 126 | 126 |
This will drop you into a bash shell in a new container, you will have your bash |
| 127 | 127 |
history from the host and when you exit the container, the host will have the |
| ... | ... |
@@ -145,15 +145,15 @@ Let's create a new named container with a volume to share. |
| 145 | 145 |
While this container doesn't run an application, it reuses the `training/postgres` |
| 146 | 146 |
image so that all containers are using layers in common, saving disk space. |
| 147 | 147 |
|
| 148 |
- $ sudo docker create -v /dbdata --name dbdata training/postgres /bin/true |
|
| 148 |
+ $ docker create -v /dbdata --name dbdata training/postgres /bin/true |
|
| 149 | 149 |
|
| 150 | 150 |
You can then use the `--volumes-from` flag to mount the `/dbdata` volume in another container. |
| 151 | 151 |
|
| 152 |
- $ sudo docker run -d --volumes-from dbdata --name db1 training/postgres |
|
| 152 |
+ $ docker run -d --volumes-from dbdata --name db1 training/postgres |
|
| 153 | 153 |
|
| 154 | 154 |
And another: |
| 155 | 155 |
|
| 156 |
- $ sudo docker run -d --volumes-from dbdata --name db2 training/postgres |
|
| 156 |
+ $ docker run -d --volumes-from dbdata --name db2 training/postgres |
|
| 157 | 157 |
|
| 158 | 158 |
In this case, if the `postgres` image contained a directory called `/dbdata` |
| 159 | 159 |
then mounting the volumes from the `dbdata` container hides the |
| ... | ... |
@@ -166,7 +166,7 @@ volumes from multiple containers. |
| 166 | 166 |
You can also extend the chain by mounting the volume that came from the |
| 167 | 167 |
`dbdata` container in yet another container via the `db1` or `db2` containers. |
| 168 | 168 |
|
| 169 |
- $ sudo docker run -d --name db3 --volumes-from db1 training/postgres |
|
| 169 |
+ $ docker run -d --name db3 --volumes-from db1 training/postgres |
|
| 170 | 170 |
|
| 171 | 171 |
If you remove containers that mount volumes, including the initial `dbdata` |
| 172 | 172 |
container, or the subsequent containers `db1` and `db2`, the volumes will not |
| ... | ... |
@@ -189,7 +189,7 @@ backups, restores or migrations. We do this by using the |
| 189 | 189 |
`--volumes-from` flag to create a new container that mounts that volume, |
| 190 | 190 |
like so: |
| 191 | 191 |
|
| 192 |
- $ sudo docker run --volumes-from dbdata -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /dbdata |
|
| 192 |
+ $ docker run --volumes-from dbdata -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /dbdata |
|
| 193 | 193 |
|
| 194 | 194 |
Here we've launched a new container and mounted the volume from the |
| 195 | 195 |
`dbdata` container. We've then mounted a local host directory as |
| ... | ... |
@@ -201,11 +201,11 @@ we'll be left with a backup of our `dbdata` volume. |
| 201 | 201 |
You could then restore it to the same container, or another that you've made |
| 202 | 202 |
elsewhere. Create a new container. |
| 203 | 203 |
|
| 204 |
- $ sudo docker run -v /dbdata --name dbdata2 ubuntu /bin/bash |
|
| 204 |
+ $ docker run -v /dbdata --name dbdata2 ubuntu /bin/bash |
|
| 205 | 205 |
|
| 206 | 206 |
Then un-tar the backup file in the new container's data volume. |
| 207 | 207 |
|
| 208 |
- $ sudo docker run --volumes-from dbdata2 -v $(pwd):/backup busybox tar xvf /backup/backup.tar |
|
| 208 |
+ $ docker run --volumes-from dbdata2 -v $(pwd):/backup busybox tar xvf /backup/backup.tar |
|
| 209 | 209 |
|
| 210 | 210 |
You can use the techniques above to automate backup, migration and |
| 211 | 211 |
restore testing using your preferred tools. |
| ... | ... |
@@ -27,12 +27,12 @@ flags and arguments. |
| 27 | 27 |
|
| 28 | 28 |
# Usage: [sudo] docker [command] [flags] [arguments] .. |
| 29 | 29 |
# Example: |
| 30 |
- $ sudo docker run -i -t ubuntu /bin/bash |
|
| 30 |
+ $ docker run -i -t ubuntu /bin/bash |
|
| 31 | 31 |
|
| 32 | 32 |
Let's see this in action by using the `docker version` command to return |
| 33 | 33 |
version information on the currently installed Docker client and daemon. |
| 34 | 34 |
|
| 35 |
- $ sudo docker version |
|
| 35 |
+ $ docker version |
|
| 36 | 36 |
|
| 37 | 37 |
This command will not only provide you the version of Docker client and |
| 38 | 38 |
daemon you are using, but also the version of Go (the programming |
| ... | ... |
@@ -54,7 +54,7 @@ language powering Docker). |
| 54 | 54 |
We can see all of the commands available to us with the Docker client by |
| 55 | 55 |
running the `docker` binary without any options. |
| 56 | 56 |
|
| 57 |
- $ sudo docker |
|
| 57 |
+ $ docker |
|
| 58 | 58 |
|
| 59 | 59 |
You will see a list of all currently available commands. |
| 60 | 60 |
|
| ... | ... |
@@ -71,12 +71,12 @@ You can also zoom in and review the usage for specific Docker commands. |
| 71 | 71 |
Try typing Docker followed with a `[command]` to see the usage for that |
| 72 | 72 |
command: |
| 73 | 73 |
|
| 74 |
- $ sudo docker attach |
|
| 74 |
+ $ docker attach |
|
| 75 | 75 |
Help output . . . |
| 76 | 76 |
|
| 77 | 77 |
Or you can also pass the `--help` flag to the `docker` binary. |
| 78 | 78 |
|
| 79 |
- $ sudo docker attach --help |
|
| 79 |
+ $ docker attach --help |
|
| 80 | 80 |
|
| 81 | 81 |
This will display the help text and all available flags: |
| 82 | 82 |
|
| ... | ... |
@@ -102,7 +102,7 @@ Docker. |
| 102 | 102 |
For our web application we're going to run a Python Flask application. |
| 103 | 103 |
Let's start with a `docker run` command. |
| 104 | 104 |
|
| 105 |
- $ sudo docker run -d -P training/webapp python app.py |
|
| 105 |
+ $ docker run -d -P training/webapp python app.py |
|
| 106 | 106 |
|
| 107 | 107 |
Let's review what our command did. We've specified two flags: `-d` and |
| 108 | 108 |
`-P`. We've already seen the `-d` flag which tells Docker to run the |
| ... | ... |
@@ -125,7 +125,7 @@ Lastly, we've specified a command for our container to run: `python app.py`. Thi |
| 125 | 125 |
|
| 126 | 126 |
Now let's see our running container using the `docker ps` command. |
| 127 | 127 |
|
| 128 |
- $ sudo docker ps -l |
|
| 128 |
+ $ docker ps -l |
|
| 129 | 129 |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
| 130 | 130 |
bc533791f3f5 training/webapp:latest python app.py 5 seconds ago Up 2 seconds 0.0.0.0:49155->5000/tcp nostalgic_morse |
| 131 | 131 |
|
| ... | ... |
@@ -160,7 +160,7 @@ to a high port (from *ephemeral port range* which typically ranges from 32768 |
| 160 | 160 |
to 61000) on the local Docker host. We can also bind Docker containers to |
| 161 | 161 |
specific ports using the `-p` flag, for example: |
| 162 | 162 |
|
| 163 |
- $ sudo docker run -d -p 5000:5000 training/webapp python app.py |
|
| 163 |
+ $ docker run -d -p 5000:5000 training/webapp python app.py |
|
| 164 | 164 |
|
| 165 | 165 |
This would map port 5000 inside our container to port 5000 on our local |
| 166 | 166 |
host. You might be asking about now: why wouldn't we just want to always |
| ... | ... |
@@ -196,7 +196,7 @@ Docker has a useful shortcut we can use: `docker port`. To use `docker port` we |
| 196 | 196 |
specify the ID or name of our container and then the port for which we need the |
| 197 | 197 |
corresponding public-facing port. |
| 198 | 198 |
|
| 199 |
- $ sudo docker port nostalgic_morse 5000 |
|
| 199 |
+ $ docker port nostalgic_morse 5000 |
|
| 200 | 200 |
0.0.0.0:49155 |
| 201 | 201 |
|
| 202 | 202 |
In this case we've looked up what port is mapped externally to port 5000 inside |
| ... | ... |
@@ -207,7 +207,7 @@ the container. |
| 207 | 207 |
Let's also find out a bit more about what's happening with our application and |
| 208 | 208 |
use another of the commands we've learnt, `docker logs`. |
| 209 | 209 |
|
| 210 |
- $ sudo docker logs -f nostalgic_morse |
|
| 210 |
+ $ docker logs -f nostalgic_morse |
|
| 211 | 211 |
* Running on http://0.0.0.0:5000/ |
| 212 | 212 |
10.0.2.2 - - [23/May/2014 20:16:31] "GET / HTTP/1.1" 200 - |
| 213 | 213 |
10.0.2.2 - - [23/May/2014 20:16:31] "GET /favicon.ico HTTP/1.1" 404 - |
| ... | ... |
@@ -222,7 +222,7 @@ the application running on port 5000 and the access log entries for it. |
| 222 | 222 |
In addition to the container's logs we can also examine the processes |
| 223 | 223 |
running inside it using the `docker top` command. |
| 224 | 224 |
|
| 225 |
- $ sudo docker top nostalgic_morse |
|
| 225 |
+ $ docker top nostalgic_morse |
|
| 226 | 226 |
PID USER COMMAND |
| 227 | 227 |
854 root python app.py |
| 228 | 228 |
|
| ... | ... |
@@ -235,7 +235,7 @@ Lastly, we can take a low-level dive into our Docker container using the |
| 235 | 235 |
`docker inspect` command. It returns a JSON hash of useful configuration |
| 236 | 236 |
and status information about Docker containers. |
| 237 | 237 |
|
| 238 |
- $ sudo docker inspect nostalgic_morse |
|
| 238 |
+ $ docker inspect nostalgic_morse |
|
| 239 | 239 |
|
| 240 | 240 |
Let's see a sample of that JSON output. |
| 241 | 241 |
|
| ... | ... |
@@ -255,7 +255,7 @@ Let's see a sample of that JSON output. |
| 255 | 255 |
We can also narrow down the information we want to return by requesting a |
| 256 | 256 |
specific element, for example to return the container's IP address we would: |
| 257 | 257 |
|
| 258 |
- $ sudo docker inspect -f '{{ .NetworkSettings.IPAddress }}' nostalgic_morse
|
|
| 258 |
+ $ docker inspect -f '{{ .NetworkSettings.IPAddress }}' nostalgic_morse
|
|
| 259 | 259 |
172.17.0.5 |
| 260 | 260 |
|
| 261 | 261 |
## Stopping our Web Application Container |
| ... | ... |
@@ -263,13 +263,13 @@ specific element, for example to return the container's IP address we would: |
| 263 | 263 |
Okay we've seen web application working. Now let's stop it using the |
| 264 | 264 |
`docker stop` command and the name of our container: `nostalgic_morse`. |
| 265 | 265 |
|
| 266 |
- $ sudo docker stop nostalgic_morse |
|
| 266 |
+ $ docker stop nostalgic_morse |
|
| 267 | 267 |
nostalgic_morse |
| 268 | 268 |
|
| 269 | 269 |
We can now use the `docker ps` command to check if the container has |
| 270 | 270 |
been stopped. |
| 271 | 271 |
|
| 272 |
- $ sudo docker ps -l |
|
| 272 |
+ $ docker ps -l |
|
| 273 | 273 |
|
| 274 | 274 |
## Restarting our Web Application Container |
| 275 | 275 |
|
| ... | ... |
@@ -278,7 +278,7 @@ developer needs the container back. From here you have two choices: you |
| 278 | 278 |
can create a new container or restart the old one. Let's look at |
| 279 | 279 |
starting our previous container back up. |
| 280 | 280 |
|
| 281 |
- $ sudo docker start nostalgic_morse |
|
| 281 |
+ $ docker start nostalgic_morse |
|
| 282 | 282 |
nostalgic_morse |
| 283 | 283 |
|
| 284 | 284 |
Now quickly run `docker ps -l` again to see the running container is |
| ... | ... |
@@ -294,7 +294,7 @@ responds. |
| 294 | 294 |
Your colleague has let you know that they've now finished with the container |
| 295 | 295 |
and won't need it again. So let's remove it using the `docker rm` command. |
| 296 | 296 |
|
| 297 |
- $ sudo docker rm nostalgic_morse |
|
| 297 |
+ $ docker rm nostalgic_morse |
|
| 298 | 298 |
Error: Impossible to remove a running container, please stop it first or use -f |
| 299 | 299 |
2014/05/24 08:12:56 Error: failed to remove one or more containers |
| 300 | 300 |
|
| ... | ... |
@@ -302,9 +302,9 @@ What happened? We can't actually remove a running container. This protects |
| 302 | 302 |
you from accidentally removing a running container you might need. Let's try |
| 303 | 303 |
this again by stopping the container first. |
| 304 | 304 |
|
| 305 |
- $ sudo docker stop nostalgic_morse |
|
| 305 |
+ $ docker stop nostalgic_morse |
|
| 306 | 306 |
nostalgic_morse |
| 307 |
- $ sudo docker rm nostalgic_morse |
|
| 307 |
+ $ docker rm nostalgic_morse |
|
| 308 | 308 |
nostalgic_morse |
| 309 | 309 |
|
| 310 | 310 |
And now our container is stopped and deleted. |