1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/docs/sources/commandline/basics.rst
2013-03-29 17:38:31 -07:00

88 lines
2 KiB
ReStructuredText

:title: Base commands
:description: Common usage and commands
:keywords: Examples, Usage
The basics
=============
Running an interactive shell
----------------------------
.. code-block:: bash
# Download a base image
docker pull base
# Run an interactive shell in the base image,
# allocate a tty, attach stdin and stdout
docker run -i -t base /bin/bash
Starting a long-running worker process
--------------------------------------
.. code-block:: bash
# Run docker in daemon mode
(sudo docker -d || echo "Docker daemon already running") &
# Start a very useful long-running process
JOB=$(docker run -d base /bin/sh -c "while true; do echo Hello world; sleep 1; done")
# Collect the output of the job so far
docker logs $JOB
# Kill the job
docker kill $JOB
Listing all running containers
------------------------------
.. code-block:: bash
docker ps
Expose a service on a TCP port
------------------------------
.. code-block:: bash
# Expose port 4444 of this container, and tell netcat to listen on it
JOB=$(docker run -d -p 4444 base /bin/nc -l -p 4444)
# Which public port is NATed to my container?
PORT=$(docker port $JOB 4444)
# Connect to the public port via the host's public address
echo hello world | nc $(hostname) $PORT
# Verify that the network connection worked
echo "Daemon received: $(docker logs $JOB)"
Continue to the complete `Command Line Interface`_
.. _Command Line Interface: ../commandline/cli.html
Committing an image
---------------------
Committing your container to an (named) image is useful because this way it can be re-used. Compare it to creating
a virtual machine image. Except your containers will generally be shorted lived so saving (committing) the state of
it is more important.
The state of a container can be saved at any time by running
::
docker commit <container_id>
However, it is probably more useful to commit it to a specific name
::
docker commit <container_id> <your username>/some_name