|
@@ -9,11 +9,13 @@ The Basics
|
|
Starting Docker
|
|
Starting Docker
|
|
---------------
|
|
---------------
|
|
|
|
|
|
-If you have used one of the quick install paths', Docker may have been installed with upstart, Ubuntu's
|
|
|
|
-system for starting processes at boot time. You should be able to run ``docker help`` and get output.
|
|
|
|
|
|
+If you have used one of the quick install paths', Docker may have been
|
|
|
|
+installed with upstart, Ubuntu's system for starting processes at boot
|
|
|
|
+time. You should be able to run ``sudo docker help`` and get output.
|
|
|
|
|
|
-If you get ``docker: command not found`` or something like ``/var/lib/docker/repositories: permission denied``
|
|
|
|
-you will need to specify the path to it and manually start it.
|
|
|
|
|
|
+If you get ``docker: command not found`` or something like
|
|
|
|
+``/var/lib/docker/repositories: permission denied`` you will need to
|
|
|
|
+specify the path to it and manually start it.
|
|
|
|
|
|
.. code-block:: bash
|
|
.. code-block:: bash
|
|
|
|
|
|
@@ -27,45 +29,73 @@ Running an interactive shell
|
|
.. code-block:: bash
|
|
.. code-block:: bash
|
|
|
|
|
|
# Download an ubuntu image
|
|
# Download an ubuntu image
|
|
- docker pull ubuntu
|
|
|
|
|
|
+ sudo docker pull ubuntu
|
|
|
|
|
|
# Run an interactive shell in the ubuntu image,
|
|
# Run an interactive shell in the ubuntu image,
|
|
# allocate a tty, attach stdin and stdout
|
|
# allocate a tty, attach stdin and stdout
|
|
- docker run -i -t ubuntu /bin/bash
|
|
|
|
|
|
+ sudo docker run -i -t ubuntu /bin/bash
|
|
|
|
|
|
-Bind Docker to another host/port or a unix socket
|
|
|
|
|
|
+Why ``sudo``?
|
|
|
|
+-------------
|
|
|
|
+
|
|
|
|
+The ``docker`` daemon always runs as root, and since ``docker``
|
|
|
|
+version 0.5.2, ``docker`` binds to a Unix socket instead of a TCP
|
|
|
|
+port. By default that Unix socket is owned by the user *root*, and so,
|
|
|
|
+by default, you can access it with ``sudo``.
|
|
|
|
+
|
|
|
|
+Starting in version 0.5.3, if you create a Unix group called *docker*
|
|
|
|
+and add users to it, then the ``docker`` daemon will make the
|
|
|
|
+ownership of the Unix socket read/writable by the *docker* group when
|
|
|
|
+the daemon starts. The ``docker`` daemon must always run as root, but
|
|
|
|
+if you run the ``docker`` client as a user in the *docker* group then
|
|
|
|
+you don't need to add ``sudo`` to all the client commands.
|
|
|
|
+
|
|
|
|
+Bind Docker to another host/port or a Unix socket
|
|
-------------------------------------------------
|
|
-------------------------------------------------
|
|
|
|
|
|
-With -H it is possible to make the Docker daemon to listen on a specific ip and port. By default, it will listen on 127.0.0.1:4243 to allow only local connections but you can set it to 0.0.0.0:4243 or a specific host ip to give access to everybody.
|
|
|
|
|
|
+.. DANGER:: 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 potentially gain *root* access on the
|
|
|
|
+ host (`e.g. #1369
|
|
|
|
+ <https://github.com/dotcloud/docker/issues/1369>`_). Make sure you
|
|
|
|
+ control access to ``docker``.
|
|
|
|
|
|
-Similarly, the Docker client can use -H to connect to a custom port.
|
|
|
|
|
|
+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
|
|
|
|
+*root* user. You *could* set it to 0.0.0.0:4243 or a specific host ip 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.
|
|
|
|
+
|
|
|
|
+Similarly, the Docker client can use ``-H`` to connect to a custom port.
|
|
|
|
+
|
|
|
|
+``-H`` accepts host and port assignment in the following format:
|
|
|
|
+``tcp://[host][:port]`` or ``unix://path``
|
|
|
|
|
|
--H accepts host and port assignment in the following format: tcp://[host][:port] or unix://path
|
|
|
|
For example:
|
|
For example:
|
|
|
|
|
|
-* tcp://host -> tcp connection on host:4243
|
|
|
|
-* tcp://host:port -> tcp connection on host:port
|
|
|
|
-* tcp://:port -> tcp connection on 127.0.0.1:port
|
|
|
|
-* unix://path/to/socket -> unix socket located at path/to/socket
|
|
|
|
|
|
+* ``tcp://host:4243`` -> tcp connection on host:4243
|
|
|
|
+* ``unix://path/to/socket`` -> unix socket located at ``path/to/socket``
|
|
|
|
|
|
.. code-block:: bash
|
|
.. code-block:: bash
|
|
|
|
|
|
# Run docker in daemon mode
|
|
# Run docker in daemon mode
|
|
sudo <path to>/docker -H 0.0.0.0:5555 -d &
|
|
sudo <path to>/docker -H 0.0.0.0:5555 -d &
|
|
# Download an ubuntu image
|
|
# Download an ubuntu image
|
|
- docker -H :5555 pull ubuntu
|
|
|
|
|
|
+ sudo docker -H :5555 pull ubuntu
|
|
|
|
|
|
-You can use multiple -H, for example, if you want to listen
|
|
|
|
-on both tcp and a unix socket
|
|
|
|
|
|
+You can use multiple ``-H``, for example, if you want to listen on
|
|
|
|
+both TCP and a Unix socket
|
|
|
|
|
|
.. code-block:: bash
|
|
.. code-block:: bash
|
|
|
|
|
|
# Run docker in daemon mode
|
|
# Run docker in daemon mode
|
|
sudo <path to>/docker -H tcp://127.0.0.1:4243 -H unix:///var/run/docker.sock -d &
|
|
sudo <path to>/docker -H tcp://127.0.0.1:4243 -H unix:///var/run/docker.sock -d &
|
|
- # Download an ubuntu image
|
|
|
|
- docker pull ubuntu
|
|
|
|
- # OR
|
|
|
|
- docker -H unix:///var/run/docker.sock pull ubuntu
|
|
|
|
|
|
+ # Download an ubuntu image, use default Unix socket
|
|
|
|
+ sudo docker pull ubuntu
|
|
|
|
+ # OR use the TCP port
|
|
|
|
+ sudo docker -H tcp://127.0.0.1:4243 pull ubuntu
|
|
|
|
|
|
Starting a long-running worker process
|
|
Starting a long-running worker process
|
|
--------------------------------------
|
|
--------------------------------------
|
|
@@ -73,13 +103,13 @@ Starting a long-running worker process
|
|
.. code-block:: bash
|
|
.. code-block:: bash
|
|
|
|
|
|
# Start a very useful long-running process
|
|
# Start a very useful long-running process
|
|
- JOB=$(docker run -d ubuntu /bin/sh -c "while true; do echo Hello world; sleep 1; done")
|
|
|
|
|
|
+ JOB=$(sudo docker run -d ubuntu /bin/sh -c "while true; do echo Hello world; sleep 1; done")
|
|
|
|
|
|
# Collect the output of the job so far
|
|
# Collect the output of the job so far
|
|
- docker logs $JOB
|
|
|
|
|
|
+ sudo docker logs $JOB
|
|
|
|
|
|
# Kill the job
|
|
# Kill the job
|
|
- docker kill $JOB
|
|
|
|
|
|
+ sudo docker kill $JOB
|
|
|
|
|
|
|
|
|
|
Listing all running containers
|
|
Listing all running containers
|
|
@@ -87,7 +117,7 @@ Listing all running containers
|
|
|
|
|
|
.. code-block:: bash
|
|
.. code-block:: bash
|
|
|
|
|
|
- docker ps
|
|
|
|
|
|
+ sudo docker ps
|
|
|
|
|
|
Expose a service on a TCP port
|
|
Expose a service on a TCP port
|
|
------------------------------
|
|
------------------------------
|
|
@@ -95,10 +125,10 @@ Expose a service on a TCP port
|
|
.. code-block:: bash
|
|
.. code-block:: bash
|
|
|
|
|
|
# Expose port 4444 of this container, and tell netcat to listen on it
|
|
# Expose port 4444 of this container, and tell netcat to listen on it
|
|
- JOB=$(docker run -d -p 4444 ubuntu /bin/nc -l -p 4444)
|
|
|
|
|
|
+ JOB=$(sudo docker run -d -p 4444 ubuntu /bin/nc -l -p 4444)
|
|
|
|
|
|
# Which public port is NATed to my container?
|
|
# Which public port is NATed to my container?
|
|
- PORT=$(docker port $JOB 4444)
|
|
|
|
|
|
+ PORT=$(sudo docker port $JOB 4444)
|
|
|
|
|
|
# Connect to the public port via the host's public address
|
|
# Connect to the public port via the host's public address
|
|
# Please note that because of how routing works connecting to localhost or 127.0.0.1 $PORT will not work.
|
|
# Please note that because of how routing works connecting to localhost or 127.0.0.1 $PORT will not work.
|
|
@@ -107,7 +137,7 @@ Expose a service on a TCP port
|
|
echo hello world | nc $IP $PORT
|
|
echo hello world | nc $IP $PORT
|
|
|
|
|
|
# Verify that the network connection worked
|
|
# Verify that the network connection worked
|
|
- echo "Daemon received: $(docker logs $JOB)"
|
|
|
|
|
|
+ echo "Daemon received: $(sudo docker logs $JOB)"
|
|
|
|
|
|
|
|
|
|
Committing (saving) a container state
|
|
Committing (saving) a container state
|
|
@@ -115,21 +145,23 @@ Committing (saving) a container state
|
|
|
|
|
|
Save your containers state to a container image, so the state can be re-used.
|
|
Save your containers state to a container image, so the state can be re-used.
|
|
|
|
|
|
-When you commit your container only the differences between the image the container was created from
|
|
|
|
-and the current state of the container will be stored (as a diff). See which images you already have
|
|
|
|
-using ``docker images``
|
|
|
|
|
|
+When you commit your container only the differences between the image
|
|
|
|
+the container was created from and the current state of the container
|
|
|
|
+will be stored (as a diff). See which images you already have using
|
|
|
|
+``sudo docker images``
|
|
|
|
|
|
.. code-block:: bash
|
|
.. code-block:: bash
|
|
|
|
|
|
# Commit your container to a new named image
|
|
# Commit your container to a new named image
|
|
- docker commit <container_id> <some_name>
|
|
|
|
|
|
+ sudo docker commit <container_id> <some_name>
|
|
|
|
|
|
# List your containers
|
|
# List your containers
|
|
- docker images
|
|
|
|
|
|
+ sudo docker images
|
|
|
|
|
|
You now have a image state from which you can create new instances.
|
|
You now have a image state from which you can create new instances.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-Read more about :ref:`working_with_the_repository` or continue to the complete :ref:`cli`
|
|
|
|
|
|
+Read more about :ref:`working_with_the_repository` or continue to the
|
|
|
|
+complete :ref:`cli`
|
|
|
|
|