github.com/boynux/docker@v1.11.0-rc4/docs/quickstart.md (about)

     1  <!--[metadata]>
     2  +++
     3  aliases = ["/engine/userguide/basics/"]
     4  title = "Quickstart"
     5  description = "Common usage and commands"
     6  keywords = ["Examples, Usage, basic commands, docker, documentation,  examples"]
     7  [menu.main]
     8  parent = "engine_use"
     9  weight=-90
    10  +++
    11  <![end-metadata]-->
    12  
    13  # Docker Engine Quickstart
    14  
    15  This quickstart assumes you have a working installation of Docker Engine. To verify Engine is installed and configured, use the following command:
    16  
    17      # Check that you have a working install
    18      $ docker info
    19  
    20  If you have a successful install, the system information appears. If you get `docker: command not found` or something like
    21  `/var/lib/docker/repositories: permission denied` you may have an
    22  incomplete Docker installation or insufficient privileges to access
    23  Engine on your machine. With the default installation of Engine `docker`
    24  commands need to be run by a user that is in the `docker` group or by the
    25  `root` user.
    26  
    27  Depending on your Engine system configuration, you may be required
    28  to preface each `docker` command with `sudo`. If you want to run without using
    29  `sudo` with the `docker` commands, then create a Unix group called `docker` and
    30  add the user to the 'docker' group.
    31  
    32  For more information about installing Docker Engine or `sudo` configuration, refer to
    33  the [installation](installation/index.md) instructions for your operating system.
    34  
    35  
    36  ## Download a pre-built image
    37  
    38  To pull an `ubuntu` image, run:
    39  
    40      # Download an ubuntu image
    41      $ docker pull ubuntu
    42  
    43  This downloads the `ubuntu` image by name from [Docker Hub](https://hub.docker.com) to a local
    44  image cache. To search for an image, run `docker search`. For more information, go to:
    45  [Searching images](userguide/containers/dockerrepos.md#searching-for-images)
    46  
    47  
    48  > **Note**:
    49  > When the image is successfully downloaded, you see a 12 character
    50  > hash `539c0211cd76: Download complete` which is the
    51  > short form of the Image ID. These short Image IDs are the first 12
    52  > characters of the full Image ID. To view this information, run
    53  > `docker inspect` or `docker images --no-trunc=true`.
    54  
    55  To display a list of downloaded images, run `docker images`.
    56  
    57  ## Running an interactive shell
    58  
    59  To run an interactive shell in the Ubuntu image:
    60  
    61      $ docker run -i -t ubuntu /bin/bash       
    62  
    63  The `-i` flag starts an interactive container.
    64  The `-t` flag creates a pseudo-TTY that attaches `stdin` and `stdout`.  
    65  The image is `ubuntu`.
    66  The command `/bin/bash` starts a shell you can log in.
    67  
    68  To detach the `tty` without exiting the shell, use the escape sequence
    69  `Ctrl-p` + `Ctrl-q`. The container continues to exist in a stopped state
    70  once exited. To list all running containers, run `docker ps`. To view stopped and running containers,
    71  run `docker ps -a`.
    72  
    73  ## Bind Docker to another host/port or a Unix socket
    74  
    75  > **Warning**:
    76  > Changing the default `docker` daemon binding to a
    77  > TCP port or Unix *docker* user group will increase your security risks
    78  > by allowing non-root users to gain *root* access on the host. Make sure
    79  > you control access to `docker`. If you are binding
    80  > to a TCP port, anyone with access to that port has full Docker access;
    81  > so it is not advisable on an open network.
    82  
    83  With `-H` it is possible to make the Docker daemon to listen on a
    84  specific IP and port. By default, it will listen on
    85  `unix:///var/run/docker.sock` to allow only local connections by the
    86  *root* user. You *could* set it to `0.0.0.0:2375` or a specific host IP
    87  to give access to everybody, but that is **not recommended** because
    88  then it is trivial for someone to gain root access to the host where the
    89  daemon is running.
    90  
    91  Similarly, the Docker client can use `-H` to connect to a custom port.
    92  The Docker client will default to connecting to `unix:///var/run/docker.sock`
    93  on Linux, and `tcp://127.0.0.1:2376` on Windows.
    94  
    95  `-H` accepts host and port assignment in the following format:
    96  
    97      tcp://[host]:[port][path] or unix://path
    98  
    99  For example:
   100  
   101  -   `tcp://` -> TCP connection to `127.0.0.1` on either port `2376` when TLS encryption
   102      is on, or port `2375` when communication is in plain text.
   103  -   `tcp://host:2375` -> TCP connection on
   104      host:2375
   105  -   `tcp://host:2375/path` -> TCP connection on
   106      host:2375 and prepend path to all requests
   107  -   `unix://path/to/socket` -> Unix socket located
   108      at `path/to/socket`
   109  
   110  `-H`, when empty, will default to the same value as
   111  when no `-H` was passed in.
   112  
   113  `-H` also accepts short form for TCP bindings:
   114  
   115      `host:` or `host:port` or `:port`
   116  
   117  Run Docker in daemon mode:
   118  
   119      $ sudo <path to>/docker daemon -H 0.0.0.0:5555 &
   120  
   121  Download an `ubuntu` image:
   122  
   123      $ docker -H :5555 pull ubuntu
   124  
   125  You can use multiple `-H`, for example, if you want to listen on both
   126  TCP and a Unix socket
   127  
   128      # Run docker in daemon mode
   129      $ sudo <path to>/docker daemon -H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock &
   130      # Download an ubuntu image, use default Unix socket
   131      $ docker pull ubuntu
   132      # OR use the TCP port
   133      $ docker -H tcp://127.0.0.1:2375 pull ubuntu
   134  
   135  ## Starting a long-running worker process
   136  
   137      # Start a very useful long-running process
   138      $ JOB=$(docker run -d ubuntu /bin/sh -c "while true; do echo Hello world; sleep 1; done")
   139  
   140      # Collect the output of the job so far
   141      $ docker logs $JOB
   142  
   143      # Kill the job
   144      $ docker kill $JOB
   145  
   146  ## Listing containers
   147  
   148      $ docker ps # Lists only running containers
   149      $ docker ps -a # Lists all containers
   150  
   151  ## Controlling containers
   152  
   153      # Start a new container
   154      $ JOB=$(docker run -d ubuntu /bin/sh -c "while true; do echo Hello world; sleep 1; done")
   155  
   156      # Stop the container
   157      $ docker stop $JOB
   158  
   159      # Start the container
   160      $ docker start $JOB
   161  
   162      # Restart the container
   163      $ docker restart $JOB
   164  
   165      # SIGKILL a container
   166      $ docker kill $JOB
   167  
   168      # Remove a container
   169      $ docker stop $JOB # Container must be stopped to remove it
   170      $ docker rm $JOB
   171  
   172  ## Bind a service on a TCP port
   173  
   174      # Bind port 4444 of this container, and tell netcat to listen on it
   175      $ JOB=$(docker run -d -p 4444 ubuntu:12.10 /bin/nc -l 4444)
   176  
   177      # Which public port is NATed to my container?
   178      $ PORT=$(docker port $JOB 4444 | awk -F: '{ print $2 }')
   179  
   180      # Connect to the public port
   181      $ echo hello world | nc 127.0.0.1 $PORT
   182  
   183      # Verify that the network connection worked
   184      $ echo "Daemon received: $(docker logs $JOB)"
   185  
   186  ## Committing (saving) a container state
   187  
   188  To save the current state of a container as an image:
   189  
   190      $ docker commit <container> <some_name>
   191  
   192  When you commit your container, Docker Engine only stores the diff (difference) between
   193  the source image and the current state of the container's image. To list images
   194  you already have, run:
   195  
   196      # List your images
   197      $ docker images
   198  
   199  You now have an image state from which you can create new instances.
   200  
   201  ## Where to go next
   202  
   203  * Work your way through the [Docker Engine User Guide](userguide/index.md)
   204  * Read more about [Store Images on Docker Hub](userguide/containers/dockerrepos.md)
   205  * Review [Command Line](reference/commandline/cli.md)