2013-03-26 17:25:42 -04:00
|
|
|
:title: Base commands
|
2013-03-25 22:52:52 -04:00
|
|
|
:description: Common usage and commands
|
|
|
|
:keywords: Examples, Usage
|
|
|
|
|
|
|
|
|
|
|
|
Base commands
|
|
|
|
=============
|
|
|
|
|
|
|
|
|
|
|
|
Running an interactive shell
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
# Download a base image
|
2013-03-27 09:43:05 -04:00
|
|
|
docker pull base
|
2013-03-25 22:52:52 -04:00
|
|
|
|
|
|
|
# Run an interactive shell in the base image,
|
|
|
|
# allocate a tty, attach stdin and stdout
|
2013-03-26 22:31:35 -04:00
|
|
|
docker run -i -t base /bin/bash
|
2013-03-25 22:52:52 -04:00
|
|
|
|
|
|
|
|
|
|
|
Starting a long-running worker process
|
|
|
|
--------------------------------------
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
# Run docker in daemon mode
|
2013-03-26 23:28:46 -04:00
|
|
|
(sudo docker -d || echo "Docker daemon already running") &
|
2013-03-25 22:52:52 -04:00
|
|
|
|
|
|
|
# Start a very useful long-running process
|
2013-03-26 23:28:46 -04:00
|
|
|
JOB=$(docker run -d base /bin/sh -c "while true; do echo Hello world; sleep 1; done")
|
2013-03-25 22:52:52 -04:00
|
|
|
|
|
|
|
# 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
|
2013-03-26 23:28:46 -04:00
|
|
|
JOB=$(docker run -d -p 4444 base /bin/nc -l -p 4444)
|
2013-03-25 22:52:52 -04:00
|
|
|
|
|
|
|
# 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)"
|
2013-03-26 15:14:58 -04:00
|
|
|
|
|
|
|
Continue to the complete `Command Line Interface`_
|
|
|
|
|
|
|
|
.. _Command Line Interface: ../commandline/cli.html
|