docs/quickstart.md
f93fee5f
 <!--[metadata]>
 +++
e310d070
 aliases = ["/engine/userguide/basics/"]
0b882cc0
 title = "Quickstart"
f93fee5f
 description = "Common usage and commands"
 keywords = ["Examples, Usage, basic commands, docker, documentation,  examples"]
 [menu.main]
e310d070
 parent = "engine_use"
 weight=-90
f93fee5f
 +++
 <![end-metadata]-->
ac999a9c
 
0b882cc0
 # Docker Engine Quickstart
ac999a9c
 
0b882cc0
 This quickstart assumes you have a working installation of Docker Engine. To verify Engine is installed and configured, use the following command:
ac999a9c
 
     # Check that you have a working install
29d01b7d
     $ docker info
ac999a9c
 
0b882cc0
 If you have a successful install, the system information appears. If you get `docker: command not found` or something like
2269472f
 `/var/lib/docker/repositories: permission denied` you may have an
 incomplete Docker installation or insufficient privileges to access
e310d070
 Engine on your machine. With the default installation of Engine `docker`
ff61be9b
 commands need to be run by a user that is in the `docker` group or by the
 `root` user.
29d01b7d
 
e310d070
 Depending on your Engine system configuration, you may be required
0b882cc0
 to preface each `docker` command with `sudo`. If you want to run without using
 `sudo` with the `docker` commands, then create a Unix group called `docker` and
 add the user to the 'docker' group.
29d01b7d
 
e310d070
 For more information about installing Docker Engine or `sudo` configuration, refer to
 the [installation](installation/index.md) instructions for your operating system.
ac999a9c
 
 
 ## Download a pre-built image
 
0b882cc0
 To pull an `ubuntu` image, run:
 
ac999a9c
     # Download an ubuntu image
29d01b7d
     $ docker pull ubuntu
ac999a9c
 
0b882cc0
 This downloads the `ubuntu` image by name from [Docker Hub](https://hub.docker.com) to a local
 image cache. To search for an image, run `docker search`. For more information, go to:
 [Searching images](userguide/containers/dockerrepos.md#searching-for-images)
 
ac999a9c
 
79358500
 > **Note**:
0d72772c
 > When the image is successfully downloaded, you see a 12 character
79358500
 > hash `539c0211cd76: Download complete` which is the
0b882cc0
 > short form of the Image ID. These short Image IDs are the first 12
 > characters of the full Image ID. To view this information, run
0d72772c
 > `docker inspect` or `docker images --no-trunc=true`.
ac999a9c
 
0b882cc0
 To display a list of downloaded images, run `docker images`.
 
ac999a9c
 ## Running an interactive shell
 
0d72772c
 To run an interactive shell in the Ubuntu image:
 
     $ docker run -i -t ubuntu /bin/bash       
9ef855f9
 
0b882cc0
 The `-i` flag starts an interactive container.
 The `-t` flag creates a pseudo-TTY that attaches `stdin` and `stdout`.  
 The image is `ubuntu`.
 The command `/bin/bash` starts a shell you can log in.
0d72772c
 
ff61be9b
 To detach the `tty` without exiting the shell, use the escape sequence
0b882cc0
 `Ctrl-p` + `Ctrl-q`. The container continues to exist in a stopped state
 once exited. To list all running containers, run `docker ps`. To view stopped and running containers,
 run `docker ps -a`.
ac999a9c
 
 ## Bind Docker to another host/port or a Unix socket
 
2269472f
 > **Warning**:
79358500
 > Changing the default `docker` daemon binding to a
 > TCP port or Unix *docker* user group will increase your security risks
 > by allowing non-root users to gain *root* access on the host. Make sure
 > you control access to `docker`. If you are binding
 > to a TCP port, anyone with access to that port has full Docker access;
 > so it is not advisable on an open network.
ac999a9c
 
2269472f
 With `-H` it is possible to make the Docker daemon to listen on a
 specific IP and port. By default, it will listen on
 `unix:///var/run/docker.sock` to allow only local connections by the
5febba93
 *root* user. You *could* set it to `0.0.0.0:2375` or a specific host IP
2269472f
 to give access to everybody, but that is **not recommended** because
 then it is trivial for someone to gain root access to the host where the
 daemon is running.
ac999a9c
 
2269472f
 Similarly, the Docker client can use `-H` to connect to a custom port.
50f09060
 The Docker client will default to connecting to `unix:///var/run/docker.sock`
 on Linux, and `tcp://127.0.0.1:2376` on Windows.
ac999a9c
 
2269472f
 `-H` accepts host and port assignment in the following format:
 
50f09060
     tcp://[host]:[port][path] or unix://path
ac999a9c
 
 For example:
 
50f09060
 -   `tcp://` -> TCP connection to `127.0.0.1` on either port `2376` when TLS encryption
     is on, or port `2375` when communication is in plain text.
5febba93
 -   `tcp://host:2375` -> TCP connection on
     host:2375
d2cde4fa
 -   `tcp://host:2375/path` -> TCP connection on
     host:2375 and prepend path to all requests
2269472f
 -   `unix://path/to/socket` -> Unix socket located
ac999a9c
     at `path/to/socket`
 
 `-H`, when empty, will default to the same value as
 when no `-H` was passed in.
 
 `-H` also accepts short form for TCP bindings:
 
50f09060
     `host:` or `host:port` or `:port`
2269472f
 
 Run Docker in daemon mode:
 
e246f1e4
     $ sudo <path to>/docker daemon -H 0.0.0.0:5555 &
2269472f
 
 Download an `ubuntu` image:
 
29d01b7d
     $ docker -H :5555 pull ubuntu
ac999a9c
 
2269472f
 You can use multiple `-H`, for example, if you want to listen on both
 TCP and a Unix socket
ac999a9c
 
     # Run docker in daemon mode
e246f1e4
     $ sudo <path to>/docker daemon -H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock &
ac999a9c
     # Download an ubuntu image, use default Unix socket
29d01b7d
     $ docker pull ubuntu
ac999a9c
     # OR use the TCP port
29d01b7d
     $ docker -H tcp://127.0.0.1:2375 pull ubuntu
ac999a9c
 
 ## Starting a long-running worker process
 
     # Start a very useful long-running process
29d01b7d
     $ JOB=$(docker run -d ubuntu /bin/sh -c "while true; do echo Hello world; sleep 1; done")
ac999a9c
 
     # Collect the output of the job so far
29d01b7d
     $ docker logs $JOB
ac999a9c
 
     # Kill the job
29d01b7d
     $ docker kill $JOB
ac999a9c
 
 ## Listing containers
 
29d01b7d
     $ docker ps # Lists only running containers
     $ docker ps -a # Lists all containers
ac999a9c
 
 ## Controlling containers
 
     # Start a new container
29d01b7d
     $ JOB=$(docker run -d ubuntu /bin/sh -c "while true; do echo Hello world; sleep 1; done")
ac999a9c
 
     # Stop the container
29d01b7d
     $ docker stop $JOB
ac999a9c
 
     # Start the container
29d01b7d
     $ docker start $JOB
ac999a9c
 
     # Restart the container
29d01b7d
     $ docker restart $JOB
ac999a9c
 
     # SIGKILL a container
29d01b7d
     $ docker kill $JOB
ac999a9c
 
     # Remove a container
29d01b7d
     $ docker stop $JOB # Container must be stopped to remove it
     $ docker rm $JOB
ac999a9c
 
 ## Bind a service on a TCP port
 
     # Bind port 4444 of this container, and tell netcat to listen on it
29d01b7d
     $ JOB=$(docker run -d -p 4444 ubuntu:12.10 /bin/nc -l 4444)
ac999a9c
 
     # Which public port is NATed to my container?
29d01b7d
     $ PORT=$(docker port $JOB 4444 | awk -F: '{ print $2 }')
ac999a9c
 
     # Connect to the public port
f87a97f7
     $ echo hello world | nc 127.0.0.1 $PORT
ac999a9c
 
     # Verify that the network connection worked
29d01b7d
     $ echo "Daemon received: $(docker logs $JOB)"
ac999a9c
 
 ## Committing (saving) a container state
 
0b882cc0
 To save the current state of a container as an image:
ac999a9c
 
0d72772c
     $ docker commit <container> <some_name>
ac999a9c
 
0b882cc0
 When you commit your container, Docker Engine only stores the diff (difference) between
 the source image and the current state of the container's image. To list images
 you already have, run:
 
2188c8d2
     # List your images
29d01b7d
     $ docker images
ac999a9c
 
a0505edc
 You now have an image state from which you can create new instances.
ac999a9c
 
9ef855f9
 ## Where to go next
 
0b882cc0
 * Work your way through the [Docker Engine User Guide](userguide/index.md)
 * Read more about [Store Images on Docker Hub](userguide/containers/dockerrepos.md)
 * Review [Command Line](reference/commandline/cli.md)