mirror of https://github.com/docker/docs.git
2581 lines
128 KiB
HTML
2581 lines
128 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
||
|
||
<meta name="docker_version" content="1.4.1">
|
||
<meta name="docker_git_branch" content="master">
|
||
<meta name="docker_git_commit" content="3c097c2">
|
||
<meta name="docker_build_date" content="Wed Jan 28 04:30:29 UTC 2015">
|
||
|
||
<meta name="description" content="Docker's CLI command description and usage">
|
||
<meta name="keywords" content="Docker, Docker documentation, CLI, command line">
|
||
|
||
<link rel="canonical" href="/reference/commandline/cli/">
|
||
<link href="/css/bootstrap-custom.css" rel="stylesheet">
|
||
<link href="/css/main.css" rel="stylesheet">
|
||
<link href="/css/prettify-1.0.css" rel="stylesheet">
|
||
<link rel="stylesheet" type="text/css" href="/css/dockerfile_tutorial.css">
|
||
<link href="/tipuesearch/tipuesearch.css" rel="stylesheet">
|
||
<link href="/css/docs.css" rel="stylesheet">
|
||
<link rel="shortcut icon" href="/img/favicon.png">
|
||
<title>Command line - Docker Documentation</title>
|
||
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
|
||
<!--[if lt IE 9]>
|
||
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
|
||
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
|
||
<![endif]-->
|
||
|
||
<script type="text/javascript">
|
||
!function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="4.0.0";
|
||
analytics.load("IWj9D0UpZHZdZUZX9jl98PcpBFWBnBMy");
|
||
analytics.page();
|
||
}}();
|
||
</script>
|
||
|
||
</head>
|
||
<body>
|
||
|
||
<div id="topmostnav" class="topmostnav_loggedout navbar navbar-static-top public">
|
||
<div class="container">
|
||
<a href="http://www.docker.com/" title="Homepage">
|
||
<div class="brand logo"><img src="/img/nav/docker-logo-loggedout.png"> </div>
|
||
</a>
|
||
<ul class="nav">
|
||
<li class=""><a href="http://www.docker.com/whatisdocker/" title="What is Docker">What is Docker?</a></li>
|
||
<li class=""><a href="http://www.docker.com/resources/usecases/" title="Use Cases">Use Cases</a></li>
|
||
<li class=""><a href="http://www.docker.com/tryit/" title="Try It!">Try It!</a></li>
|
||
<li class="active"><a href="https://docs.docker.com" title="Install & Docs">Install & Docs</a></li>
|
||
<li><a href="https://registry.hub.docker.com" title="Browse">Browse</a></li>
|
||
</ul>
|
||
<div id="usernav" class="pull-right">
|
||
<a href="https://hub.docker.com/account/login" class="btn nav-button2" title="Lg In">Log In</a>
|
||
<a href="https://hub.docker.com/account/signup" class="btn nav-button1" title="Sign Up">Sign Up</a>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div id="topmostnav" class="topmostnav_loggedin navbar navbar-static-top">
|
||
<div class="container">
|
||
<a href="http://www.docker.com/" title="Docker Docs Home"><div class="brand logo"><img src="/img/nav/docker-logo-loggedin.png"> </div></a>
|
||
<form id="search_box_header" class="navbar-index-search pull-right" action="https://registry.hub.docker.com/search">
|
||
<span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span><input type="text" class="search-query ui-autocomplete-input" placeholder="Search..." name="q" value="" autocomplete="off">
|
||
</form>
|
||
<ul class="nav">
|
||
<li><a href="https://registry.hub.docker.com" title="Browse Repos">Browse Repos</a></li>
|
||
<li class="active"><a href="http://docs.docker.com" title="Documentation">Documentation</a></li>
|
||
<li><a href="http://www.docker.com/community/participate/" title="Community">Community</a></li>
|
||
<li><a href="http://www.docker.com/resources/help/" title="Help">Help</a></li>
|
||
</ul>
|
||
<div id="usernav" class="pull-right">
|
||
<ul class="nav user">
|
||
<li class="dropdown">
|
||
<a id="logged-in-header-username" class="dropdown-toggle" data-toggle="dropdown" href="#">
|
||
<img class="profile" src="" alt="profile picture">
|
||
</a>
|
||
<ul class="dropdown-menu pull-right">
|
||
<li><a href="https://hub.docker.com/">View Profile</a></li>
|
||
<li><a href="https://hub.docker.com/account/settings/">Settings</a></li>
|
||
<li><a href="https://hub.docker.com/repos/">My Repositories</a></li>
|
||
<li><a href="https://hub.docker.com/plans/billing-info">Billing</a></li>
|
||
<li><a href="https://hub.docker.com/account/logout/?next=/">Log out</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="wrap">
|
||
<nav id="nav_menu" class="clearfix navbar navbar-default navbar-static-top affix" role="navigation">
|
||
<div id="docsnav">
|
||
<ul id="main-nav" class="pull-left">
|
||
|
||
|
||
<li class="dd_menu pull-left">
|
||
|
||
<a href="/">About</a>
|
||
|
||
<ul class="dd_submenu" style="max-height: 75px;">
|
||
|
||
<li >
|
||
<a href="/">Docker</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/release-notes/">Release Notes</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/introduction/understanding-docker/">Understanding Docker</a>
|
||
</li>
|
||
|
||
</ul>
|
||
</li>
|
||
|
||
|
||
|
||
<li class="dd_menu pull-left">
|
||
|
||
<a href="/installation/mac/">Installation</a>
|
||
|
||
<ul class="dd_submenu" style="max-height: 75px;">
|
||
|
||
<li >
|
||
<a href="/installation/mac/">Mac OS X</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/installation/ubuntulinux/">Ubuntu</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/installation/rhel/">Red Hat Enterprise Linux</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/installation/oracle/">Oracle Linux</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/installation/centos/">CentOS</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/installation/debian/">Debian</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/installation/gentoolinux/">Gentoo</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/installation/google/">Google Cloud Platform</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/installation/rackspace/">Rackspace Cloud</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/installation/amazon/">Amazon EC2</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/installation/softlayer/">IBM Softlayer</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/installation/archlinux/">Arch Linux</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/installation/frugalware/">FrugalWare</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/installation/fedora/">Fedora</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/installation/SUSE/">SUSE</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/installation/cruxlinux/">CRUX Linux</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/installation/windows/">Microsoft Windows</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/installation/binaries/">Binaries</a>
|
||
</li>
|
||
|
||
</ul>
|
||
</li>
|
||
|
||
|
||
|
||
<li class="dd_menu pull-left">
|
||
|
||
<a href="/userguide/">User Guide</a>
|
||
|
||
<ul class="dd_submenu" style="max-height: 75px;">
|
||
|
||
<li >
|
||
<a href="/userguide/">The Docker User Guide</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/userguide/dockerhub/">Getting Started with Docker Hub</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/userguide/dockerizing/">Dockerizing Applications</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/userguide/usingdocker/">Working with Containers</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/userguide/dockerimages/">Working with Docker Images</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/userguide/dockerlinks/">Linking containers together</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/userguide/dockervolumes/">Managing data in containers</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/userguide/dockerrepos/">Working with Docker Hub</a>
|
||
</li>
|
||
|
||
</ul>
|
||
</li>
|
||
|
||
|
||
|
||
<li class="dd_menu pull-left">
|
||
|
||
<a href="/docker-hub/">Docker Hub</a>
|
||
|
||
<ul class="dd_submenu" style="max-height: 75px;">
|
||
|
||
<li >
|
||
<a href="/docker-hub/">Docker Hub</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/docker-hub/accounts/">Accounts</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/docker-hub/repos/">Repositories</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/docker-hub/builds/">Automated Builds</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/docker-hub/official_repos/">Official Repo Guidelines</a>
|
||
</li>
|
||
|
||
</ul>
|
||
</li>
|
||
|
||
|
||
|
||
<li class="dd_menu pull-left">
|
||
|
||
<a href="/examples/nodejs_web_app/">Examples</a>
|
||
|
||
<ul class="dd_submenu" style="max-height: 75px;">
|
||
|
||
<li >
|
||
<a href="/examples/nodejs_web_app/">Dockerizing a Node.js web application</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/examples/mongodb/">Dockerizing MongoDB</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/examples/running_redis_service/">Dockerizing a Redis service</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/examples/postgresql_service/">Dockerizing a PostgreSQL service</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/examples/running_riak_service/">Dockerizing a Riak service</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/examples/running_ssh_service/">Dockerizing an SSH service</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/examples/couchdb_data_volumes/">Dockerizing a CouchDB service</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/examples/apt-cacher-ng/">Dockerizing an Apt-Cacher-ng service</a>
|
||
</li>
|
||
|
||
</ul>
|
||
</li>
|
||
|
||
|
||
|
||
<li class="dd_menu pull-left">
|
||
|
||
<a href="/articles/basics/">Articles</a>
|
||
|
||
<ul class="dd_submenu" style="max-height: 75px;">
|
||
|
||
<li >
|
||
<a href="/articles/basics/">Docker basics</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/articles/networking/">Advanced networking</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/articles/security/">Security</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/articles/https/">Running Docker with HTTPS</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/articles/registry_mirror/">Run a local registry mirror</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/articles/host_integration/">Automatically starting containers</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/articles/baseimages/">Creating a base image</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/articles/dockerfile_best-practices/">Best practices for writing Dockerfiles</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/articles/certificates/">Using certificates for repository client verification</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/articles/using_supervisord/">Using Supervisor</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/articles/cfengine_process_management/">Process management with CFEngine</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/articles/puppet/">Using Puppet</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/articles/chef/">Using Chef</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/articles/dsc/">Using PowerShell DSC</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/articles/ambassador_pattern_linking/">Cross-Host linking using ambassador containers</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/articles/runmetrics/">Runtime metrics</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/articles/b2d_volume_resize/">Increasing a Boot2Docker volume</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/articles/systemd/">Controlling and configuring Docker using Systemd</a>
|
||
</li>
|
||
|
||
</ul>
|
||
</li>
|
||
|
||
|
||
|
||
<li class="dd_menu pull-left active">
|
||
|
||
<a href="/reference/commandline/cli/">Reference</a>
|
||
|
||
<ul class="dd_submenu" style="max-height: 75px;">
|
||
|
||
<li class="active">
|
||
<a href="/reference/commandline/cli/">Command line</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/reference/builder/">Dockerfile</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/faq/">FAQ</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/reference/run/">Run Reference</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/reference/api/docker-io_api/">Docker Hub API</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/reference/api/registry_api/">Docker Registry API</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/reference/api/registry_api_client_libraries/">Docker Registry API Client Libraries</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/reference/api/hub_registry_spec/">Docker Hub and Registry Spec</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/reference/api/docker_remote_api/">Docker Remote API</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/reference/api/docker_remote_api_v1.16/">Docker Remote API v1.16</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/reference/api/docker_remote_api_v1.15/">Docker Remote API v1.15</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/reference/api/docker_remote_api_v1.14/">Docker Remote API v1.14</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/reference/api/docker_remote_api_v1.13/">Docker Remote API v1.13</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/reference/api/docker_remote_api_v1.12/">Docker Remote API v1.12</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/reference/api/docker_remote_api_v1.11/">Docker Remote API v1.11</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/reference/api/remote_api_client_libraries/">Docker Remote API Client Libraries</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/reference/api/docker_io_accounts_api/">Docker Hub Accounts API</a>
|
||
</li>
|
||
|
||
</ul>
|
||
</li>
|
||
|
||
|
||
|
||
<li class="dd_menu pull-left">
|
||
|
||
<a href="/contributing/contributing/">Contribute</a>
|
||
|
||
<ul class="dd_submenu" style="max-height: 75px;">
|
||
|
||
<li >
|
||
<a href="/contributing/contributing/">Contributing</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/contributing/devenvironment/">Development environment</a>
|
||
</li>
|
||
|
||
<li >
|
||
<a href="/contributing/docs_style-guide/">Documentation style guide</a>
|
||
</li>
|
||
|
||
</ul>
|
||
</li>
|
||
|
||
|
||
</ul>
|
||
<form id="nav_search" class="pull-right" action="/jsearch/">
|
||
<span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span>
|
||
<input name="q" id="tipue_search_input" type="text" class="search_input search-query ui-autocomplete-input" placeholder="Search the Docs" autocomplete="off">
|
||
</form>
|
||
</div>
|
||
</nav>
|
||
<div id="content" class="container">
|
||
<div class="row">
|
||
|
||
<div class="span3" id="leftnav">
|
||
<div id="toc_table">
|
||
<ul class="nav nav-tabs nav-stacked">
|
||
|
||
|
||
<li class=""><a href="#option-types">Option types</a></li>
|
||
|
||
<h3><a href="#boolean">Boolean</a></h3>
|
||
|
||
<h3><a href="#multi">Multi</a></h3>
|
||
|
||
<h3><a href="#strings-and-integers">Strings and Integers</a></h3>
|
||
|
||
|
||
<li class=""><a href="#daemon">daemon</a></li>
|
||
|
||
<h3><a href="#daemon-socket-option">Daemon socket option</a></h3>
|
||
|
||
<h3><a href="#daemon-storage-driver-option">Daemon storage-driver option</a></h3>
|
||
|
||
<h3><a href="#docker-exec-driver-option">Docker exec-driver option</a></h3>
|
||
|
||
<h3><a href="#daemon-dns-options">Daemon DNS options</a></h3>
|
||
|
||
<h3><a href="#insecure-registries">Insecure registries</a></h3>
|
||
|
||
<h3><a href="#running-a-docker-daemon-behind-a-https_proxy">Running a Docker daemon behind a HTTPS_PROXY</a></h3>
|
||
|
||
<h3><a href="#miscellaneous-options">Miscellaneous options</a></h3>
|
||
|
||
|
||
<li class=""><a href="#attach">attach</a></li>
|
||
|
||
<h3><a href="#examples">Examples</a></h3>
|
||
|
||
|
||
<li class=""><a href="#build">build</a></li>
|
||
|
||
<h3><a href="#example-dockerignore-file">Example .dockerignore file</a></h3>
|
||
|
||
<h3><a href="#examples_1">Examples</a></h3>
|
||
|
||
|
||
<li class=""><a href="#commit">commit</a></li>
|
||
|
||
<h3><a href="#commit-an-existing-container">Commit an existing container</a></h3>
|
||
|
||
|
||
<li class=""><a href="#cp">cp</a></li>
|
||
|
||
|
||
<li class=""><a href="#create">create</a></li>
|
||
|
||
<h3><a href="#examples_2">Examples</a></h3>
|
||
|
||
|
||
<li class=""><a href="#diff">diff</a></li>
|
||
|
||
|
||
<li class=""><a href="#events">events</a></li>
|
||
|
||
<h3><a href="#filtering">Filtering</a></h3>
|
||
|
||
<h3><a href="#examples_3">Examples</a></h3>
|
||
|
||
|
||
<li class=""><a href="#exec">exec</a></li>
|
||
|
||
<h3><a href="#examples_4">Examples</a></h3>
|
||
|
||
|
||
<li class=""><a href="#export">export</a></li>
|
||
|
||
|
||
<li class=""><a href="#history">history</a></li>
|
||
|
||
|
||
<li class=""><a href="#images">images</a></li>
|
||
|
||
<h3><a href="#listing-the-most-recently-created-images">Listing the most recently created images</a></h3>
|
||
|
||
<h3><a href="#listing-the-full-length-image-ids">Listing the full length image IDs</a></h3>
|
||
|
||
<h3><a href="#filtering_1">Filtering</a></h3>
|
||
|
||
|
||
<li class=""><a href="#import">import</a></li>
|
||
|
||
<h3><a href="#examples_5">Examples</a></h3>
|
||
|
||
|
||
<li class=""><a href="#info">info</a></li>
|
||
|
||
|
||
<li class=""><a href="#inspect">inspect</a></li>
|
||
|
||
<h3><a href="#examples_6">Examples</a></h3>
|
||
|
||
|
||
<li class=""><a href="#kill">kill</a></li>
|
||
|
||
|
||
<li class=""><a href="#load">load</a></li>
|
||
|
||
|
||
<li class=""><a href="#login">login</a></li>
|
||
|
||
|
||
<li class=""><a href="#logout">logout</a></li>
|
||
|
||
|
||
<li class=""><a href="#logs">logs</a></li>
|
||
|
||
|
||
<li class=""><a href="#pause">pause</a></li>
|
||
|
||
|
||
<li class=""><a href="#port">port</a></li>
|
||
|
||
|
||
<li class=""><a href="#ps">ps</a></li>
|
||
|
||
<h3><a href="#filtering_2">Filtering</a></h3>
|
||
|
||
|
||
<li class=""><a href="#pull">pull</a></li>
|
||
|
||
|
||
<li class=""><a href="#push">push</a></li>
|
||
|
||
|
||
<li class=""><a href="#restart">restart</a></li>
|
||
|
||
|
||
<li class=""><a href="#rm">rm</a></li>
|
||
|
||
<h3><a href="#examples_7">Examples</a></h3>
|
||
|
||
|
||
<li class=""><a href="#rmi">rmi</a></li>
|
||
|
||
<h3><a href="#removing-tagged-images">Removing tagged images</a></h3>
|
||
|
||
|
||
<li class=""><a href="#run">run</a></li>
|
||
|
||
<h3><a href="#examples_8">Examples</a></h3>
|
||
|
||
<h3><a href="#restart-policies">Restart Policies</a></h3>
|
||
|
||
<h3><a href="#adding-entries-to-a-container-hosts-file">Adding entries to a container hosts file</a></h3>
|
||
|
||
|
||
<li class=""><a href="#save">save</a></li>
|
||
|
||
|
||
<li class=""><a href="#search">search</a></li>
|
||
|
||
|
||
<li class=""><a href="#start">start</a></li>
|
||
|
||
|
||
<li class=""><a href="#stop">stop</a></li>
|
||
|
||
|
||
<li class=""><a href="#tag">tag</a></li>
|
||
|
||
|
||
<li class=""><a href="#top">top</a></li>
|
||
|
||
|
||
<li class=""><a href="#unpause">unpause</a></li>
|
||
|
||
|
||
<li class=""><a href="#version">version</a></li>
|
||
|
||
|
||
<li class=""><a href="#wait">wait</a></li>
|
||
|
||
|
||
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
<div class="span9 content-body">
|
||
|
||
|
||
|
||
<div id="versionnav" class="span3 pull-right invisible">
|
||
<ul class="nav version pull-right">
|
||
<li class="dropdown">
|
||
<a id="document-version-number" class="dropdown-toggle" data-toggle="dropdown" href="#">
|
||
Version v1.4
|
||
</a>
|
||
<ul id="documentation-version-list" class="dropdown-menu pull-right">
|
||
|
||
<li role="presentation" class="divider"></li>
|
||
<li> <a class="home-link3 tertiary-nav" href="https://github.com/docker/docker/blob/master/docs/sources/reference/commandline/cli.md" >Edit on GitHub</a></li>
|
||
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
|
||
<h1 id="command-line">Command Line</h1>
|
||
<blockquote>
|
||
<p><strong>Note:</strong> if you are using a remote Docker daemon, such as Boot2Docker,
|
||
then <em>do not</em> type the <code>sudo</code> before the <code>docker</code> commands shown in the
|
||
documentation's examples.</p>
|
||
</blockquote>
|
||
<p>To list available commands, either run <code>docker</code> with no parameters
|
||
or execute <code>docker help</code>:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker
|
||
Usage: docker [OPTIONS] COMMAND [arg...]
|
||
-H, --host=[]: The socket(s) to bind to in daemon mode, specified using one or more tcp://host:port, unix:///path/to/socket, fd://* or fd://socketfd.
|
||
|
||
A self-sufficient runtime for Linux containers.
|
||
|
||
...
|
||
</code></pre>
|
||
<h2 id="option-types">Option types</h2>
|
||
<p>Single character commandline options can be combined, so rather than
|
||
typing <code>docker run -t -i --name test busybox sh</code>,
|
||
you can write <code>docker run -ti --name test busybox sh</code>.</p>
|
||
<h3 id="boolean">Boolean</h3>
|
||
<p>Boolean options look like <code>-d=false</code>. The value you
|
||
see is the default value which gets set if you do <strong>not</strong> use the
|
||
boolean flag. If you do call <code>run -d</code>, that sets the
|
||
opposite boolean value, so in this case, <code>true</code>, and
|
||
so <code>docker run -d</code> <strong>will</strong> run in "detached" mode,
|
||
in the background. Other boolean options are similar – specifying them
|
||
will set the value to the opposite of the default value.</p>
|
||
<h3 id="multi">Multi</h3>
|
||
<p>Options like <code>-a=[]</code> indicate they can be specified multiple times:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker run -a stdin -a stdout -a stderr -i -t ubuntu /bin/bash
|
||
</code></pre>
|
||
<p>Sometimes this can use a more complex value string, as for <code>-v</code>:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker run -v /host:/container example/mysql
|
||
</code></pre>
|
||
<h3 id="strings-and-integers">Strings and Integers</h3>
|
||
<p>Options like <code>--name=""</code> expect a string, and they
|
||
can only be specified once. Options like <code>-c=0</code>
|
||
expect an integer, and they can only be specified once.</p>
|
||
<h2 id="daemon">daemon</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker [OPTIONS] COMMAND [arg...]
|
||
|
||
A self-sufficient runtime for linux containers.
|
||
|
||
Options:
|
||
--api-enable-cors=false Enable CORS headers in the remote API
|
||
-b, --bridge="" Attach containers to a pre-existing network bridge
|
||
use 'none' to disable container networking
|
||
--bip="" Use this CIDR notation address for the network bridge's IP, not compatible with -b
|
||
-D, --debug=false Enable debug mode
|
||
-d, --daemon=false Enable daemon mode
|
||
--dns=[] Force Docker to use specific DNS servers
|
||
--dns-search=[] Force Docker to use specific DNS search domains
|
||
-e, --exec-driver="native" Force the Docker runtime to use a specific exec driver
|
||
--fixed-cidr="" IPv4 subnet for fixed IPs (ex: 10.20.0.0/16)
|
||
this subnet must be nested in the bridge subnet (which is defined by -b or --bip)
|
||
-G, --group="docker" Group to assign the unix socket specified by -H when running in daemon mode
|
||
use '' (the empty string) to disable setting of a group
|
||
-g, --graph="/var/lib/docker" Path to use as the root of the Docker runtime
|
||
-H, --host=[] The socket(s) to bind to in daemon mode or connect to in client mode, specified using one or more tcp://host:port, unix:///path/to/socket, fd://* or fd://socketfd.
|
||
--icc=true Allow unrestricted inter-container and Docker daemon host communication
|
||
--insecure-registry=[] Enable insecure communication with specified registries (disables certificate verification for HTTPS and enables HTTP fallback) (e.g., localhost:5000 or 10.20.0.0/16)
|
||
--ip=0.0.0.0 Default IP address to use when binding container ports
|
||
--ip-forward=true Enable net.ipv4.ip_forward
|
||
--ip-masq=true Enable IP masquerading for bridge's IP range
|
||
--iptables=true Enable Docker's addition of iptables rules
|
||
-l, --log-level="info" Set the logging level
|
||
--label=[] Set key=value labels to the daemon (displayed in `docker info`)
|
||
--mtu=0 Set the containers network MTU
|
||
if no value is provided: default to the default route MTU or 1500 if no default route is available
|
||
-p, --pidfile="/var/run/docker.pid" Path to use for daemon PID file
|
||
--registry-mirror=[] Specify a preferred Docker registry mirror
|
||
-s, --storage-driver="" Force the Docker runtime to use a specific storage driver
|
||
--selinux-enabled=false Enable selinux support. SELinux does not presently support the BTRFS storage driver
|
||
--storage-opt=[] Set storage driver options
|
||
--tls=false Use TLS; implied by --tlsverify flag
|
||
--tlscacert="/home/sven/.docker/ca.pem" Trust only remotes providing a certificate signed by the CA given here
|
||
--tlscert="/home/sven/.docker/cert.pem" Path to TLS certificate file
|
||
--tlskey="/home/sven/.docker/key.pem" Path to TLS key file
|
||
--tlsverify=false Use TLS and verify the remote (daemon: verify client, client: verify daemon)
|
||
-v, --version=false Print version information and quit
|
||
</code></pre>
|
||
<p>Options with [] may be specified multiple times.</p>
|
||
<p>The Docker daemon is the persistent process that manages containers.
|
||
Docker uses the same binary for both the daemon and client. To run the
|
||
daemon you provide the <code>-d</code> flag.</p>
|
||
<p>To run the daemon with debug output, use <code>docker -d -D</code>.</p>
|
||
<h3 id="daemon-socket-option">Daemon socket option</h3>
|
||
<p>The Docker daemon can listen for <a href="/reference/api/docker_remote_api/">Docker Remote API</a>
|
||
requests via three different types of Socket: <code>unix</code>, <code>tcp</code>, and <code>fd</code>.</p>
|
||
<p>By default, a <code>unix</code> domain socket (or IPC socket) is created at <code>/var/run/docker.sock</code>,
|
||
requiring either <code>root</code> permission, or <code>docker</code> group membership.</p>
|
||
<p>If you need to access the Docker daemon remotely, you need to enable the <code>tcp</code>
|
||
Socket. Beware that the default setup provides un-encrypted and un-authenticated
|
||
direct access to the Docker daemon - and should be secured either using the
|
||
<a href="/articles/https/">built in HTTPS encrypted socket</a>, or by putting a secure web
|
||
proxy in front of it. You can listen on port <code>2375</code> on all network interfaces
|
||
with <code>-H tcp://0.0.0.0:2375</code>, or on a particular network interface using its IP
|
||
address: <code>-H tcp://192.168.59.103:2375</code>. It is conventional to use port <code>2375</code>
|
||
for un-encrypted, and port <code>2376</code> for encrypted communication with the daemon.</p>
|
||
<blockquote>
|
||
<p><strong>Note</strong> If you're using an HTTPS encrypted socket, keep in mind that only TLS1.0
|
||
and greater are supported. Protocols SSLv3 and under are not supported anymore
|
||
for security reasons.</p>
|
||
</blockquote>
|
||
<p>On Systemd based systems, you can communicate with the daemon via
|
||
<a href="http://0pointer.de/blog/projects/socket-activation.html">systemd socket activation</a>, use
|
||
<code>docker -d -H fd://</code>. Using <code>fd://</code> will work perfectly for most setups but
|
||
you can also specify individual sockets: <code>docker -d -H fd://3</code>. If the
|
||
specified socket activated files aren't found, then Docker will exit. You
|
||
can find examples of using Systemd socket activation with Docker and
|
||
Systemd in the <a href="https://github.com/docker/docker/tree/master/contrib/init/systemd/">Docker source tree</a>.</p>
|
||
<p>You can configure the Docker daemon to listen to multiple sockets at the same
|
||
time using multiple <code>-H</code> options:</p>
|
||
<pre class="prettyprint well"><code># listen using the default unix socket, and on 2 specific IP addresses on this host.
|
||
docker -d -H unix:///var/run/docker.sock -H tcp://192.168.59.106 -H tcp://10.10.10.2
|
||
</code></pre>
|
||
<p>The Docker client will honor the <code>DOCKER_HOST</code> environment variable to set
|
||
the <code>-H</code> flag for the client.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker -H tcp://0.0.0.0:2375 ps
|
||
# or
|
||
$ export DOCKER_HOST="tcp://0.0.0.0:2375"
|
||
$ sudo docker ps
|
||
# both are equal
|
||
</code></pre>
|
||
<p>Setting the <code>DOCKER_TLS_VERIFY</code> environment variable to any value other than the empty
|
||
string is equivalent to setting the <code>--tlsverify</code> flag. The following are equivalent:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker --tlsverify ps
|
||
# or
|
||
$ export DOCKER_TLS_VERIFY=1
|
||
$ sudo docker ps
|
||
</code></pre>
|
||
<h3 id="daemon-storage-driver-option">Daemon storage-driver option</h3>
|
||
<p>The Docker daemon has support for several different image layer storage drivers: <code>aufs</code>,
|
||
<code>devicemapper</code>, <code>btrfs</code> and <code>overlay</code>.</p>
|
||
<p>The <code>aufs</code> driver is the oldest, but is based on a Linux kernel patch-set that
|
||
is unlikely to be merged into the main kernel. These are also known to cause some
|
||
serious kernel crashes. However, <code>aufs</code> is also the only storage driver that allows
|
||
containers to share executable and shared library memory, so is a useful choice
|
||
when running thousands of containers with the same program or libraries.</p>
|
||
<p>The <code>devicemapper</code> driver uses thin provisioning and Copy on Write (CoW)
|
||
snapshots. For each devicemapper graph location – typically
|
||
<code>/var/lib/docker/devicemapper</code> – a thin pool is created based on two block
|
||
devices, one for data and one for metadata. By default, these block devices
|
||
are created automatically by using loopback mounts of automatically created
|
||
sparse files. Refer to <a href="#storage-driver-options">Storage driver options</a> below
|
||
for a way how to customize this setup.
|
||
<a href="http://jpetazzo.github.io/2014/01/29/docker-device-mapper-resize/">~jpetazzo/Resizing Docker containers with the Device Mapper plugin</a> article
|
||
explains how to tune your existing setup without the use of options.</p>
|
||
<p>The <code>btrfs</code> driver is very fast for <code>docker build</code> - but like <code>devicemapper</code> does not
|
||
share executable memory between devices. Use <code>docker -d -s btrfs -g /mnt/btrfs_partition</code>.</p>
|
||
<p>The <code>overlay</code> is a very fast union filesystem. It is now merged in the main
|
||
Linux kernel as of <a href="https://lkml.org/lkml/2014/10/26/137">3.18.0</a>.
|
||
Call <code>docker -d -s overlay</code> to use it. </p>
|
||
<blockquote>
|
||
<p><strong>Note:</strong>
|
||
It is currently unsupported on <code>btrfs</code> or any Copy on Write filesystem
|
||
and should only be used over <code>ext4</code> partitions.</p>
|
||
</blockquote>
|
||
<h4 id="storage-driver-options">Storage driver options</h4>
|
||
<p>Particular storage-driver can be configured with options specified with
|
||
<code>--storage-opt</code> flags. The only driver accepting options is <code>devicemapper</code> as
|
||
of now. All its options are prefixed with <code>dm</code>.</p>
|
||
<p>Currently supported options are:</p>
|
||
<ul>
|
||
<li>
|
||
<p><code>dm.basesize</code></p>
|
||
<p>Specifies the size to use when creating the base device, which limits the
|
||
size of images and containers. The default value is 10G. Note, thin devices
|
||
are inherently "sparse", so a 10G device which is mostly empty doesn't use
|
||
10 GB of space on the pool. However, the filesystem will use more space for
|
||
the empty case the larger the device is.</p>
|
||
<p><strong>Warning</strong>: This value affects the system-wide "base" empty filesystem
|
||
that may already be initialized and inherited by pulled images. Typically,
|
||
a change to this value will require additional steps to take effect:</p>
|
||
<pre class="prettyprint well"><code>$ sudo service docker stop
|
||
$ sudo rm -rf /var/lib/docker
|
||
$ sudo service docker start
|
||
</code></pre>
|
||
<p>Example use:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker -d --storage-opt dm.basesize=20G
|
||
</code></pre>
|
||
</li>
|
||
<li>
|
||
<p><code>dm.loopdatasize</code></p>
|
||
<p>Specifies the size to use when creating the loopback file for the "data"
|
||
device which is used for the thin pool. The default size is 100G. Note that
|
||
the file is sparse, so it will not initially take up this much space.</p>
|
||
<p>Example use:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker -d --storage-opt dm.loopdatasize=200G
|
||
</code></pre>
|
||
</li>
|
||
<li>
|
||
<p><code>dm.loopmetadatasize</code></p>
|
||
<p>Specifies the size to use when creating the loopback file for the
|
||
"metadata" device which is used for the thin pool. The default size is 2G.
|
||
Note that the file is sparse, so it will not initially take up this much
|
||
space.</p>
|
||
<p>Example use:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker -d --storage-opt dm.loopmetadatasize=4G
|
||
</code></pre>
|
||
</li>
|
||
<li>
|
||
<p><code>dm.fs</code></p>
|
||
<p>Specifies the filesystem type to use for the base device. The supported
|
||
options are "ext4" and "xfs". The default is "ext4"</p>
|
||
<p>Example use:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker -d --storage-opt dm.fs=xfs
|
||
</code></pre>
|
||
</li>
|
||
<li>
|
||
<p><code>dm.mkfsarg</code></p>
|
||
<p>Specifies extra mkfs arguments to be used when creating the base device.</p>
|
||
<p>Example use:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker -d --storage-opt "dm.mkfsarg=-O ^has_journal"
|
||
</code></pre>
|
||
</li>
|
||
<li>
|
||
<p><code>dm.mountopt</code></p>
|
||
<p>Specifies extra mount options used when mounting the thin devices.</p>
|
||
<p>Example use:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker -d --storage-opt dm.mountopt=nodiscard
|
||
</code></pre>
|
||
</li>
|
||
<li>
|
||
<p><code>dm.datadev</code></p>
|
||
<p>Specifies a custom blockdevice to use for data for the thin pool.</p>
|
||
<p>If using a block device for device mapper storage, ideally both datadev and
|
||
metadatadev should be specified to completely avoid using the loopback
|
||
device.</p>
|
||
<p>Example use:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker -d \
|
||
--storage-opt dm.datadev=/dev/sdb1 \
|
||
--storage-opt dm.metadatadev=/dev/sdc1
|
||
</code></pre>
|
||
</li>
|
||
<li>
|
||
<p><code>dm.metadatadev</code></p>
|
||
<p>Specifies a custom blockdevice to use for metadata for the thin pool.</p>
|
||
<p>For best performance the metadata should be on a different spindle than the
|
||
data, or even better on an SSD.</p>
|
||
<p>If setting up a new metadata pool it is required to be valid. This can be
|
||
achieved by zeroing the first 4k to indicate empty metadata, like this:</p>
|
||
<pre class="prettyprint well"><code>$ dd if=/dev/zero of=$metadata_dev bs=4096 count=1
|
||
</code></pre>
|
||
<p>Example use:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker -d \
|
||
--storage-opt dm.datadev=/dev/sdb1 \
|
||
--storage-opt dm.metadatadev=/dev/sdc1
|
||
</code></pre>
|
||
</li>
|
||
<li>
|
||
<p><code>dm.blocksize</code></p>
|
||
<p>Specifies a custom blocksize to use for the thin pool. The default
|
||
blocksize is 64K.</p>
|
||
<p>Example use:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker -d --storage-opt dm.blocksize=512K
|
||
</code></pre>
|
||
</li>
|
||
<li>
|
||
<p><code>dm.blkdiscard</code></p>
|
||
<p>Enables or disables the use of blkdiscard when removing devicemapper
|
||
devices. This is enabled by default (only) if using loopback devices and is
|
||
required to res-parsify the loopback file on image/container removal.</p>
|
||
<p>Disabling this on loopback can lead to <em>much</em> faster container removal
|
||
times, but will make the space used in <code>/var/lib/docker</code> directory not be
|
||
returned to the system for other use when containers are removed.</p>
|
||
<p>Example use:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker -d --storage-opt dm.blkdiscard=false
|
||
</code></pre>
|
||
</li>
|
||
</ul>
|
||
<h3 id="docker-exec-driver-option">Docker exec-driver option</h3>
|
||
<p>The Docker daemon uses a specifically built <code>libcontainer</code> execution driver as its
|
||
interface to the Linux kernel <code>namespaces</code>, <code>cgroups</code>, and <code>SELinux</code>.</p>
|
||
<p>There is still legacy support for the original <a href="https://linuxcontainers.org/">LXC userspace tools</a> via the <code>lxc</code> execution driver, however, this is
|
||
not where the primary development of new functionality is taking place.
|
||
Add <code>-e lxc</code> to the daemon flags to use the <code>lxc</code> execution driver.</p>
|
||
<h3 id="daemon-dns-options">Daemon DNS options</h3>
|
||
<p>To set the DNS server for all Docker containers, use
|
||
<code>docker -d --dns 8.8.8.8</code>.</p>
|
||
<p>To set the DNS search domain for all Docker containers, use
|
||
<code>docker -d --dns-search example.com</code>.</p>
|
||
<h3 id="insecure-registries">Insecure registries</h3>
|
||
<p>Docker considers a private registry either secure or insecure.
|
||
In the rest of this section, <em>registry</em> is used for <em>private registry</em>, and <code>myregistry:5000</code>
|
||
is a placeholder example for a private registry.</p>
|
||
<p>A secure registry uses TLS and a copy of its CA certificate is placed on the Docker host at
|
||
<code>/etc/docker/certs.d/myregistry:5000/ca.crt</code>.
|
||
An insecure registry is either not using TLS (i.e., listening on plain text HTTP), or is using
|
||
TLS with a CA certificate not known by the Docker daemon. The latter can happen when the
|
||
certificate was not found under <code>/etc/docker/certs.d/myregistry:5000/</code>, or if the certificate
|
||
verification failed (i.e., wrong CA).</p>
|
||
<p>By default, Docker assumes all, but local (see local registries below), registries are secure.
|
||
Communicating with an insecure registry is not possible if Docker assumes that registry is secure.
|
||
In order to communicate with an insecure registry, the Docker daemon requires <code>--insecure-registry</code>
|
||
in one of the following two forms: </p>
|
||
<ul>
|
||
<li><code>--insecure-registry myregistry:5000</code> tells the Docker daemon that myregistry:5000 should be considered insecure.</li>
|
||
<li><code>--insecure-registry 10.1.0.0/16</code> tells the Docker daemon that all registries whose domain resolve to an IP address is part
|
||
of the subnet described by the CIDR syntax, should be considered insecure.</li>
|
||
</ul>
|
||
<p>The flag can be used multiple times to allow multiple registries to be marked as insecure.</p>
|
||
<p>If an insecure registry is not marked as insecure, <code>docker pull</code>, <code>docker push</code>, and <code>docker search</code>
|
||
will result in an error message prompting the user to either secure or pass the <code>--insecure-registry</code>
|
||
flag to the Docker daemon as described above.</p>
|
||
<p>Local registries, whose IP address falls in the 127.0.0.0/8 range, are automatically marked as insecure
|
||
as of Docker 1.3.2. It is not recommended to rely on this, as it may change in the future.</p>
|
||
<h3 id="running-a-docker-daemon-behind-a-https_proxy">Running a Docker daemon behind a HTTPS_PROXY</h3>
|
||
<p>When running inside a LAN that uses a <code>HTTPS</code> proxy, the Docker Hub certificates
|
||
will be replaced by the proxy's certificates. These certificates need to be added
|
||
to your Docker host's configuration:</p>
|
||
<ol>
|
||
<li>Install the <code>ca-certificates</code> package for your distribution</li>
|
||
<li>Ask your network admin for the proxy's CA certificate and append them to
|
||
<code>/etc/pki/tls/certs/ca-bundle.crt</code></li>
|
||
<li>Then start your Docker daemon with <code>HTTPS_PROXY=http://username:password@proxy:port/ docker -d</code>.
|
||
The <code>username:</code> and <code>password@</code> are optional - and are only needed if your proxy
|
||
is set up to require authentication.</li>
|
||
</ol>
|
||
<p>This will only add the proxy and authentication to the Docker daemon's requests -
|
||
your <code>docker build</code>s and running containers will need extra configuration to use
|
||
the proxy</p>
|
||
<h3 id="miscellaneous-options">Miscellaneous options</h3>
|
||
<p>IP masquerading uses address translation to allow containers without a public IP to talk
|
||
to other machines on the Internet. This may interfere with some network topologies and
|
||
can be disabled with --ip-masq=false.</p>
|
||
<p>Docker supports softlinks for the Docker data directory
|
||
(<code>/var/lib/docker</code>) and for <code>/var/lib/docker/tmp</code>. The <code>DOCKER_TMPDIR</code> and the data directory can be set like this:</p>
|
||
<pre class="prettyprint well"><code>DOCKER_TMPDIR=/mnt/disk2/tmp /usr/local/bin/docker -d -D -g /var/lib/docker -H unix:// > /var/lib/boot2docker/docker.log 2>&1
|
||
# or
|
||
export DOCKER_TMPDIR=/mnt/disk2/tmp
|
||
/usr/local/bin/docker -d -D -g /var/lib/docker -H unix:// > /var/lib/boot2docker/docker.log 2>&1
|
||
</code></pre>
|
||
<h2 id="attach">attach</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker attach [OPTIONS] CONTAINER
|
||
|
||
Attach to a running container
|
||
|
||
--no-stdin=false Do not attach STDIN
|
||
--sig-proxy=true Proxy all received signals to the process (non-TTY mode only). SIGCHLD, SIGKILL, and SIGSTOP are not proxied.
|
||
</code></pre>
|
||
<p>The <code>attach</code> command lets you view or interact with any running container's
|
||
primary process (<code>pid 1</code>).</p>
|
||
<p>You can attach to the same contained process multiple times simultaneously, screen
|
||
sharing style, or quickly view the progress of your daemonized process.</p>
|
||
<blockquote>
|
||
<p><strong>Note:</strong> This command is not for running a new process in a container.
|
||
See: <a href="#exec"><code>docker exec</code></a>.</p>
|
||
</blockquote>
|
||
<p>You can detach from the container again (and leave it running) with
|
||
<code>CTRL-p CTRL-q</code> (for a quiet exit), or <code>CTRL-c</code> which will send a
|
||
SIGKILL to the container, or <code>CTRL-\</code> to get a stacktrace of the
|
||
Docker client when it quits. When you detach from the container's
|
||
process the exit code will be returned to the client.</p>
|
||
<p>To stop a container, use <code>docker stop</code>.</p>
|
||
<p>To kill the container, use <code>docker kill</code>.</p>
|
||
<h4 id="examples">Examples</h4>
|
||
<pre class="prettyprint well"><code>$ ID=$(sudo docker run -d ubuntu /usr/bin/top -b)
|
||
$ sudo docker attach $ID
|
||
top - 02:05:52 up 3:05, 0 users, load average: 0.01, 0.02, 0.05
|
||
Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie
|
||
Cpu(s): 0.1%us, 0.2%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
|
||
Mem: 373572k total, 355560k used, 18012k free, 27872k buffers
|
||
Swap: 786428k total, 0k used, 786428k free, 221740k cached
|
||
|
||
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
|
||
1 root 20 0 17200 1116 912 R 0 0.3 0:00.03 top
|
||
|
||
top - 02:05:55 up 3:05, 0 users, load average: 0.01, 0.02, 0.05
|
||
Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie
|
||
Cpu(s): 0.0%us, 0.2%sy, 0.0%ni, 99.8%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
|
||
Mem: 373572k total, 355244k used, 18328k free, 27872k buffers
|
||
Swap: 786428k total, 0k used, 786428k free, 221776k cached
|
||
|
||
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
|
||
1 root 20 0 17208 1144 932 R 0 0.3 0:00.03 top
|
||
|
||
|
||
top - 02:05:58 up 3:06, 0 users, load average: 0.01, 0.02, 0.05
|
||
Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie
|
||
Cpu(s): 0.2%us, 0.3%sy, 0.0%ni, 99.5%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
|
||
Mem: 373572k total, 355780k used, 17792k free, 27880k buffers
|
||
Swap: 786428k total, 0k used, 786428k free, 221776k cached
|
||
|
||
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
|
||
1 root 20 0 17208 1144 932 R 0 0.3 0:00.03 top
|
||
^C$
|
||
$ sudo docker stop $ID
|
||
</code></pre>
|
||
<h2 id="build">build</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker build [OPTIONS] PATH | URL | -
|
||
|
||
Build a new image from the source code at PATH
|
||
|
||
--force-rm=false Always remove intermediate containers, even after unsuccessful builds
|
||
--no-cache=false Do not use cache when building the image
|
||
--pull=false Always attempt to pull a newer version of the image
|
||
-q, --quiet=false Suppress the verbose output generated by the containers
|
||
--rm=true Remove intermediate containers after a successful build
|
||
-t, --tag="" Repository name (and optionally a tag) to be applied to the resulting image in case of success
|
||
</code></pre>
|
||
<p>Use this command to build Docker images from a Dockerfile and a
|
||
"context".</p>
|
||
<p>The files at <code>PATH</code> or <code>URL</code> are called the "context" of the build. The
|
||
build process may refer to any of the files in the context, for example
|
||
when using an <a href="/reference/builder/#add"><em>ADD</em></a> instruction.
|
||
When a single Dockerfile is given as <code>URL</code> or is piped through <code>STDIN</code>
|
||
(<code>docker build - < Dockerfile</code>), then no context is set.</p>
|
||
<p>When a Git repository is set as <code>URL</code>, then the repository is used as
|
||
the context. The Git repository is cloned with its submodules
|
||
(<code>git clone -recursive</code>). A fresh <code>git clone</code> occurs in a temporary directory
|
||
on your local host, and then this is sent to the Docker daemon as the
|
||
context. This way, your local user credentials and VPN's etc can be
|
||
used to access private repositories.</p>
|
||
<p>If a file named <code>.dockerignore</code> exists in the root of <code>PATH</code> then it
|
||
is interpreted as a newline-separated list of exclusion patterns.
|
||
Exclusion patterns match files or directories relative to <code>PATH</code> that
|
||
will be excluded from the context. Globbing is done using Go's
|
||
<a href="http://golang.org/pkg/path/filepath#Match">filepath.Match</a> rules.</p>
|
||
<p>Please note that <code>.dockerignore</code> files in other subdirectories are
|
||
considered as normal files. Filepaths in .dockerignore are absolute with
|
||
the current directory as the root. Wildcards are allowed but the search
|
||
is not recursive.</p>
|
||
<h4 id="example-dockerignore-file">Example .dockerignore file</h4>
|
||
<pre class="prettyprint well"><code>*/temp*
|
||
*/*/temp*
|
||
temp?
|
||
</code></pre>
|
||
<p>The first line above <code>*/temp*</code>, would ignore all files with names starting with
|
||
<code>temp</code> from any subdirectory below the root directory. For example, a file named
|
||
<code>/somedir/temporary.txt</code> would be ignored. The second line <code>*/*/temp*</code>, will
|
||
ignore files starting with name <code>temp</code> from any subdirectory that is two levels
|
||
below the root directory. For example, the file <code>/somedir/subdir/temporary.txt</code>
|
||
would get ignored in this case. The last line in the above example <code>temp?</code>
|
||
will ignore the files that match the pattern from the root directory.
|
||
For example, the files <code>tempa</code>, <code>tempb</code> are ignored from the root directory.
|
||
Currently there is no support for regular expressions. Formats
|
||
like <code>[^temp*]</code> are ignored.</p>
|
||
<p>See also:</p>
|
||
<p><a href="/reference/builder"><em>Dockerfile Reference</em></a>.</p>
|
||
<h4 id="examples_1">Examples</h4>
|
||
<pre class="prettyprint well"><code>$ sudo docker build .
|
||
Uploading context 10240 bytes
|
||
Step 1 : FROM busybox
|
||
Pulling repository busybox
|
||
---> e9aa60c60128MB/2.284 MB (100%) endpoint: https://cdn-registry-1.docker.io/v1/
|
||
Step 2 : RUN ls -lh /
|
||
---> Running in 9c9e81692ae9
|
||
total 24
|
||
drwxr-xr-x 2 root root 4.0K Mar 12 2013 bin
|
||
drwxr-xr-x 5 root root 4.0K Oct 19 00:19 dev
|
||
drwxr-xr-x 2 root root 4.0K Oct 19 00:19 etc
|
||
drwxr-xr-x 2 root root 4.0K Nov 15 23:34 lib
|
||
lrwxrwxrwx 1 root root 3 Mar 12 2013 lib64 -> lib
|
||
dr-xr-xr-x 116 root root 0 Nov 15 23:34 proc
|
||
lrwxrwxrwx 1 root root 3 Mar 12 2013 sbin -> bin
|
||
dr-xr-xr-x 13 root root 0 Nov 15 23:34 sys
|
||
drwxr-xr-x 2 root root 4.0K Mar 12 2013 tmp
|
||
drwxr-xr-x 2 root root 4.0K Nov 15 23:34 usr
|
||
---> b35f4035db3f
|
||
Step 3 : CMD echo Hello world
|
||
---> Running in 02071fceb21b
|
||
---> f52f38b7823e
|
||
Successfully built f52f38b7823e
|
||
Removing intermediate container 9c9e81692ae9
|
||
Removing intermediate container 02071fceb21b
|
||
</code></pre>
|
||
<p>This example specifies that the <code>PATH</code> is
|
||
<code>.</code>, and so all the files in the local directory get
|
||
<code>tar</code>d and sent to the Docker daemon. The <code>PATH</code>
|
||
specifies where to find the files for the "context" of the build on the
|
||
Docker daemon. Remember that the daemon could be running on a remote
|
||
machine and that no parsing of the Dockerfile
|
||
happens at the client side (where you're running
|
||
<code>docker build</code>). That means that <em>all</em> the files at
|
||
<code>PATH</code> get sent, not just the ones listed to
|
||
<a href="/reference/builder/#add"><em>ADD</em></a> in the Dockerfile.</p>
|
||
<p>The transfer of context from the local machine to the Docker daemon is
|
||
what the <code>docker</code> client means when you see the
|
||
"Sending build context" message.</p>
|
||
<p>If you wish to keep the intermediate containers after the build is
|
||
complete, you must use <code>--rm=false</code>. This does not
|
||
affect the build cache.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker build .
|
||
Uploading context 18.829 MB
|
||
Uploading context
|
||
Step 0 : FROM busybox
|
||
---> 769b9341d937
|
||
Step 1 : CMD echo Hello world
|
||
---> Using cache
|
||
---> 99cc1ad10469
|
||
Successfully built 99cc1ad10469
|
||
$ echo ".git" > .dockerignore
|
||
$ sudo docker build .
|
||
Uploading context 6.76 MB
|
||
Uploading context
|
||
Step 0 : FROM busybox
|
||
---> 769b9341d937
|
||
Step 1 : CMD echo Hello world
|
||
---> Using cache
|
||
---> 99cc1ad10469
|
||
Successfully built 99cc1ad10469
|
||
</code></pre>
|
||
<p>This example shows the use of the <code>.dockerignore</code> file to exclude the <code>.git</code>
|
||
directory from the context. Its effect can be seen in the changed size of the
|
||
uploaded context.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker build -t vieux/apache:2.0 .
|
||
</code></pre>
|
||
<p>This will build like the previous example, but it will then tag the
|
||
resulting image. The repository name will be <code>vieux/apache</code>
|
||
and the tag will be <code>2.0</code></p>
|
||
<pre class="prettyprint well"><code>$ sudo docker build - < Dockerfile
|
||
</code></pre>
|
||
<p>This will read a Dockerfile from <code>STDIN</code> without context. Due to the
|
||
lack of a context, no contents of any local directory will be sent to
|
||
the Docker daemon. Since there is no context, a Dockerfile <code>ADD</code> only
|
||
works if it refers to a remote URL.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker build - < context.tar.gz
|
||
</code></pre>
|
||
<p>This will build an image for a compressed context read from <code>STDIN</code>.
|
||
Supported formats are: bzip2, gzip and xz.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker build github.com/creack/docker-firefox
|
||
</code></pre>
|
||
<p>This will clone the GitHub repository and use the cloned repository as
|
||
context. The Dockerfile at the root of the
|
||
repository is used as Dockerfile. Note that you
|
||
can specify an arbitrary Git repository by using the <code>git://</code> or <code>git@</code>
|
||
schema.</p>
|
||
<blockquote>
|
||
<p><strong>Note:</strong> <code>docker build</code> will return a <code>no such file or directory</code> error
|
||
if the file or directory does not exist in the uploaded context. This may
|
||
happen if there is no context, or if you specify a file that is elsewhere
|
||
on the Host system. The context is limited to the current directory (and its
|
||
children) for security reasons, and to ensure repeatable builds on remote
|
||
Docker hosts. This is also the reason why <code>ADD ../file</code> will not work.</p>
|
||
</blockquote>
|
||
<h2 id="commit">commit</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
|
||
|
||
Create a new image from a container's changes
|
||
|
||
-a, --author="" Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
|
||
-m, --message="" Commit message
|
||
-p, --pause=true Pause container during commit
|
||
</code></pre>
|
||
<p>It can be useful to commit a container's file changes or settings into a
|
||
new image. This allows you debug a container by running an interactive
|
||
shell, or to export a working dataset to another server. Generally, it
|
||
is better to use Dockerfiles to manage your images in a documented and
|
||
maintainable way.</p>
|
||
<p>By default, the container being committed and its processes will be paused
|
||
while the image is committed. This reduces the likelihood of
|
||
encountering data corruption during the process of creating the commit.
|
||
If this behavior is undesired, set the 'p' option to false.</p>
|
||
<h4 id="commit-an-existing-container">Commit an existing container</h4>
|
||
<pre class="prettyprint well"><code>$ sudo docker ps
|
||
ID IMAGE COMMAND CREATED STATUS PORTS
|
||
c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours
|
||
197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours
|
||
$ sudo docker commit c3f279d17e0a SvenDowideit/testimage:version3
|
||
f5283438590d
|
||
$ sudo docker images | head
|
||
REPOSITORY TAG ID CREATED VIRTUAL SIZE
|
||
SvenDowideit/testimage version3 f5283438590d 16 seconds ago 335.7 MB
|
||
</code></pre>
|
||
<h2 id="cp">cp</h2>
|
||
<p>Copy files/folders from a container's filesystem to the host
|
||
path. Paths are relative to the root of the filesystem.</p>
|
||
<pre class="prettyprint well"><code>Usage: docker cp CONTAINER:PATH HOSTPATH
|
||
|
||
Copy files/folders from the PATH to the HOSTPATH
|
||
</code></pre>
|
||
<h2 id="create">create</h2>
|
||
<p>Creates a new container.</p>
|
||
<pre class="prettyprint well"><code>Usage: docker create [OPTIONS] IMAGE [COMMAND] [ARG...]
|
||
|
||
Create a new container
|
||
|
||
-a, --attach=[] Attach to STDIN, STDOUT or STDERR.
|
||
--add-host=[] Add a custom host-to-IP mapping (host:ip)
|
||
-c, --cpu-shares=0 CPU shares (relative weight)
|
||
--cap-add=[] Add Linux capabilities
|
||
--cap-drop=[] Drop Linux capabilities
|
||
--cidfile="" Write the container ID to the file
|
||
--cpuset="" CPUs in which to allow execution (0-3, 0,1)
|
||
--device=[] Add a host device to the container (e.g. --device=/dev/sdc:/dev/xvdc:rwm)
|
||
--dns=[] Set custom DNS servers
|
||
--dns-search=[] Set custom DNS search domains (Use --dns-search=. if you don't wish to set the search domain)
|
||
-e, --env=[] Set environment variables
|
||
--entrypoint="" Overwrite the default ENTRYPOINT of the image
|
||
--env-file=[] Read in a line delimited file of environment variables
|
||
--expose=[] Expose a port or a range of ports (e.g. --expose=3300-3310) from the container without publishing it to your host
|
||
-h, --hostname="" Container host name
|
||
-i, --interactive=false Keep STDIN open even if not attached
|
||
--ipc="" Default is to create a private IPC namespace (POSIX SysV IPC) for the container
|
||
'container:<name|id>': reuses another container shared memory, semaphores and message queues
|
||
'host': use the host shared memory,semaphores and message queues inside the container. Note: the host mode gives the container full access to local shared memory and is therefore considered insecure.
|
||
--link=[] Add link to another container in the form of name:alias
|
||
--lxc-conf=[] (lxc exec-driver only) Add custom lxc options --lxc-conf="lxc.cgroup.cpuset.cpus = 0,1"
|
||
-m, --memory="" Memory limit (format: <number><optional unit>, where unit = b, k, m or g)
|
||
--mac-address="" Container MAC address (e.g. 92:d0:c6:0a:29:33)
|
||
--name="" Assign a name to the container
|
||
--net="bridge" Set the Network mode for the container
|
||
'bridge': creates a new network stack for the container on the docker bridge
|
||
'none': no networking for this container
|
||
'container:<name|id>': reuses another container network stack
|
||
'host': use the host network stack inside the container. Note: the host mode gives the container full access to local system services such as D-bus and is therefore considered insecure.
|
||
-P, --publish-all=false Publish all exposed ports to the host interfaces
|
||
-p, --publish=[] Publish a container's port to the host
|
||
format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort
|
||
(use 'docker port' to see the actual mapping)
|
||
--privileged=false Give extended privileges to this container
|
||
--restart="" Restart policy to apply when a container exits (no, on-failure[:max-retry], always)
|
||
--security-opt=[] Security Options
|
||
-t, --tty=false Allocate a pseudo-TTY
|
||
-u, --user="" Username or UID
|
||
-v, --volume=[] Bind mount a volume (e.g., from the host: -v /host:/container, from Docker: -v /container)
|
||
--volumes-from=[] Mount volumes from the specified container(s)
|
||
-w, --workdir="" Working directory inside the container
|
||
</code></pre>
|
||
<p>The <code>docker create</code> command creates a writeable container layer over
|
||
the specified image and prepares it for running the specified command.
|
||
The container ID is then printed to <code>STDOUT</code>.
|
||
This is similar to <code>docker run -d</code> except the container is never started.
|
||
You can then use the <code>docker start <container_id></code> command to start the
|
||
container at any point.</p>
|
||
<p>This is useful when you want to set up a container configuration ahead
|
||
of time so that it is ready to start when you need it.</p>
|
||
<p>Note that volumes set by <code>create</code> may be over-ridden by options set with
|
||
<code>start</code>.</p>
|
||
<p>Please see the <a href="#run">run command</a> section for more details.</p>
|
||
<h4 id="examples_2">Examples</h4>
|
||
<pre class="prettyprint well"><code>$ sudo docker create -t -i fedora bash
|
||
6d8af538ec541dd581ebc2a24153a28329acb5268abe5ef868c1f1a261221752
|
||
$ sudo docker start -a -i 6d8af538ec5
|
||
bash-4.2#
|
||
</code></pre>
|
||
<p>As of v1.4.0 container volumes are initialized during the <code>docker create</code>
|
||
phase (i.e., <code>docker run</code> too). For example, this allows you to <code>create</code> the
|
||
<code>data</code> volume container, and then use it from another container:</p>
|
||
<pre class="prettyprint well"><code>$ docker create -v /data --name data ubuntu
|
||
240633dfbb98128fa77473d3d9018f6123b99c454b3251427ae190a7d951ad57
|
||
$ docker run --rm --volumes-from data ubuntu ls -la /data
|
||
total 8
|
||
drwxr-xr-x 2 root root 4096 Dec 5 04:10 .
|
||
drwxr-xr-x 48 root root 4096 Dec 5 04:11 ..
|
||
</code></pre>
|
||
<p>Similarly, <code>create</code> a host directory bind mounted volume container, which
|
||
can then be used from the subsequent container:</p>
|
||
<pre class="prettyprint well"><code>$ docker create -v /home/docker:/docker --name docker ubuntu
|
||
9aa88c08f319cd1e4515c3c46b0de7cc9aa75e878357b1e96f91e2c773029f03
|
||
$ docker run --rm --volumes-from docker ubuntu ls -la /docker
|
||
total 20
|
||
drwxr-sr-x 5 1000 staff 180 Dec 5 04:00 .
|
||
drwxr-xr-x 48 root root 4096 Dec 5 04:13 ..
|
||
-rw-rw-r-- 1 1000 staff 3833 Dec 5 04:01 .ash_history
|
||
-rw-r--r-- 1 1000 staff 446 Nov 28 11:51 .ashrc
|
||
-rw-r--r-- 1 1000 staff 25 Dec 5 04:00 .gitconfig
|
||
drwxr-sr-x 3 1000 staff 60 Dec 1 03:28 .local
|
||
-rw-r--r-- 1 1000 staff 920 Nov 28 11:51 .profile
|
||
drwx--S--- 2 1000 staff 460 Dec 5 00:51 .ssh
|
||
drwxr-xr-x 32 1000 staff 1140 Dec 5 04:01 docker
|
||
</code></pre>
|
||
<h2 id="diff">diff</h2>
|
||
<p>List the changed files and directories in a container᾿s filesystem</p>
|
||
<pre class="prettyprint well"><code>Usage: docker diff CONTAINER
|
||
|
||
Inspect changes on a container's filesystem
|
||
</code></pre>
|
||
<p>There are 3 events that are listed in the <code>diff</code>:</p>
|
||
<ol>
|
||
<li><code>A</code> - Add</li>
|
||
<li><code>D</code> - Delete</li>
|
||
<li><code>C</code> - Change</li>
|
||
</ol>
|
||
<p>For example:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker diff 7bb0e258aefe
|
||
|
||
C /dev
|
||
A /dev/kmsg
|
||
C /etc
|
||
A /etc/mtab
|
||
A /go
|
||
A /go/src
|
||
A /go/src/github.com
|
||
A /go/src/github.com/docker
|
||
A /go/src/github.com/docker/docker
|
||
A /go/src/github.com/docker/docker/.git
|
||
....
|
||
</code></pre>
|
||
<h2 id="events">events</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker events [OPTIONS]
|
||
|
||
Get real time events from the server
|
||
|
||
-f, --filter=[] Provide filter values (i.e., 'event=stop')
|
||
--since="" Show all events created since timestamp
|
||
--until="" Stream events until this timestamp
|
||
</code></pre>
|
||
<p>Docker containers will report the following events:</p>
|
||
<pre class="prettyprint well"><code>create, destroy, die, export, kill, pause, restart, start, stop, unpause
|
||
</code></pre>
|
||
<p>and Docker images will report:</p>
|
||
<pre class="prettyprint well"><code>untag, delete
|
||
</code></pre>
|
||
<h4 id="filtering">Filtering</h4>
|
||
<p>The filtering flag (<code>-f</code> or <code>--filter</code>) format is of "key=value". If you would like to use
|
||
multiple filters, pass multiple flags (e.g., <code>--filter "foo=bar" --filter "bif=baz"</code>)</p>
|
||
<p>Using the same filter multiple times will be handled as a <em>OR</em>; for example
|
||
<code>--filter container=588a23dac085 --filter container=a8f7720b8c22</code> will display events for
|
||
container 588a23dac085 <em>OR</em> container a8f7720b8c22</p>
|
||
<p>Using multiple filters will be handled as a <em>AND</em>; for example
|
||
<code>--filter container=588a23dac085 --filter event=start</code> will display events for container
|
||
container 588a23dac085 <em>AND</em> the event type is <em>start</em></p>
|
||
<p>Current filters:
|
||
* event
|
||
* image
|
||
* container</p>
|
||
<h4 id="examples_3">Examples</h4>
|
||
<p>You'll need two shells for this example.</p>
|
||
<p><strong>Shell 1: Listening for events:</strong></p>
|
||
<pre class="prettyprint well"><code>$ sudo docker events
|
||
</code></pre>
|
||
<p><strong>Shell 2: Start and Stop containers:</strong></p>
|
||
<pre class="prettyprint well"><code>$ sudo docker start 4386fb97867d
|
||
$ sudo docker stop 4386fb97867d
|
||
$ sudo docker stop 7805c1d35632
|
||
</code></pre>
|
||
<p><strong>Shell 1: (Again .. now showing events):</strong></p>
|
||
<pre class="prettyprint well"><code>2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) start
|
||
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die
|
||
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop
|
||
2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die
|
||
2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) stop
|
||
</code></pre>
|
||
<p><strong>Show events in the past from a specified time:</strong></p>
|
||
<pre class="prettyprint well"><code>$ sudo docker events --since 1378216169
|
||
2014-03-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die
|
||
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop
|
||
2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die
|
||
2014-03-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) stop
|
||
|
||
$ sudo docker events --since '2013-09-03'
|
||
2014-09-03T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) start
|
||
2014-09-03T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die
|
||
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop
|
||
2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die
|
||
2014-09-03T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) stop
|
||
|
||
$ sudo docker events --since '2013-09-03 15:49:29 +0200 CEST'
|
||
2014-09-03T15:49:29.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die
|
||
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop
|
||
2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die
|
||
2014-09-03T15:49:29.999999999Z07:00 7805c1d35632: (from redis:2.8) stop
|
||
</code></pre>
|
||
<p><strong>Filter events:</strong></p>
|
||
<pre class="prettyprint well"><code>$ sudo docker events --filter 'event=stop'
|
||
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop
|
||
2014-09-03T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) stop
|
||
|
||
$ sudo docker events --filter 'image=ubuntu-1:14.04'
|
||
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) start
|
||
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die
|
||
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop
|
||
|
||
$ sudo docker events --filter 'container=7805c1d35632'
|
||
2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die
|
||
2014-09-03T15:49:29.999999999Z07:00 7805c1d35632: (from redis:2.8) stop
|
||
|
||
$ sudo docker events --filter 'container=7805c1d35632' --filter 'container=4386fb97867d'
|
||
2014-09-03T15:49:29.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die
|
||
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop
|
||
2014-05-10T17:42:14.999999999Z07:00 7805c1d35632: (from redis:2.8) die
|
||
2014-09-03T15:49:29.999999999Z07:00 7805c1d35632: (from redis:2.8) stop
|
||
|
||
$ sudo docker events --filter 'container=7805c1d35632' --filter 'event=stop'
|
||
2014-09-03T15:49:29.999999999Z07:00 7805c1d35632: (from redis:2.8) stop
|
||
</code></pre>
|
||
<h2 id="exec">exec</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
|
||
|
||
Run a command in a running container
|
||
|
||
-d, --detach=false Detached mode: run command in the background
|
||
-i, --interactive=false Keep STDIN open even if not attached
|
||
-t, --tty=false Allocate a pseudo-TTY
|
||
</code></pre>
|
||
<p>The <code>docker exec</code> command runs a new command in a running container.</p>
|
||
<p>The command started using <code>docker exec</code> will only run while the container's primary
|
||
process (<code>PID 1</code>) is running, and will not be restarted if the container is restarted.</p>
|
||
<p>If the container is paused, then the <code>docker exec</code> command will fail with an error:</p>
|
||
<pre class="prettyprint well"><code>$ docker pause test
|
||
test
|
||
$ docker ps
|
||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||
1ae3b36715d2 ubuntu:latest "bash" 17 seconds ago Up 16 seconds (Paused) test
|
||
$ docker exec test ls
|
||
FATA[0000] Error response from daemon: Container test is paused, unpause the container before exec
|
||
$ echo $?
|
||
1
|
||
</code></pre>
|
||
<h4 id="examples_4">Examples</h4>
|
||
<pre class="prettyprint well"><code>$ sudo docker run --name ubuntu_bash --rm -i -t ubuntu bash
|
||
</code></pre>
|
||
<p>This will create a container named <code>ubuntu_bash</code> and start a Bash session.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker exec -d ubuntu_bash touch /tmp/execWorks
|
||
</code></pre>
|
||
<p>This will create a new file <code>/tmp/execWorks</code> inside the running container
|
||
<code>ubuntu_bash</code>, in the background.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker exec -it ubuntu_bash bash
|
||
</code></pre>
|
||
<p>This will create a new Bash session in the container <code>ubuntu_bash</code>.</p>
|
||
<h2 id="export">export</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker export CONTAINER
|
||
|
||
Export the contents of a filesystem as a tar archive to STDOUT
|
||
</code></pre>
|
||
<p>For example:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker export red_panda > latest.tar
|
||
</code></pre>
|
||
<blockquote>
|
||
<p><strong>Note:</strong>
|
||
<code>docker export</code> does not export the contents of volumes associated with the
|
||
container. If a volume is mounted on top of an existing directory in the
|
||
container, <code>docker export</code> will export the contents of the <em>underlying</em>
|
||
directory, not the contents of the volume.</p>
|
||
<p>Refer to <a href="/userguide/dockervolumes/#backup-restore-or-migrate-data-volumes">Backup, restore, or migrate data volumes</a>
|
||
in the user guide for examples on exporting data in a volume.</p>
|
||
</blockquote>
|
||
<h2 id="history">history</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker history [OPTIONS] IMAGE
|
||
|
||
Show the history of an image
|
||
|
||
--no-trunc=false Don't truncate output
|
||
-q, --quiet=false Only show numeric IDs
|
||
</code></pre>
|
||
<p>To see how the <code>docker:latest</code> image was built:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker history docker
|
||
IMAGE CREATED CREATED BY SIZE
|
||
3e23a5875458790b7a806f95f7ec0d0b2a5c1659bfc899c89f939f6d5b8f7094 8 days ago /bin/sh -c #(nop) ENV LC_ALL=C.UTF-8 0 B
|
||
8578938dd17054dce7993d21de79e96a037400e8d28e15e7290fea4f65128a36 8 days ago /bin/sh -c dpkg-reconfigure locales && locale-gen C.UTF-8 && /usr/sbin/update-locale LANG=C.UTF-8 1.245 MB
|
||
be51b77efb42f67a5e96437b3e102f81e0a1399038f77bf28cea0ed23a65cf60 8 days ago /bin/sh -c apt-get update && apt-get install -y git libxml2-dev python build-essential make gcc python-dev locales python-pip 338.3 MB
|
||
4b137612be55ca69776c7f30c2d2dd0aa2e7d72059820abf3e25b629f887a084 6 weeks ago /bin/sh -c #(nop) ADD jessie.tar.xz in / 121 MB
|
||
750d58736b4b6cc0f9a9abe8f258cef269e3e9dceced1146503522be9f985ada 6 weeks ago /bin/sh -c #(nop) MAINTAINER Tianon Gravi <admwiggin@gmail.com> - mkimage-debootstrap.sh -t jessie.tar.xz jessie http://http.debian.net/debian 0 B
|
||
511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158 9 months ago 0 B
|
||
</code></pre>
|
||
<h2 id="images">images</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker images [OPTIONS] [REPOSITORY]
|
||
|
||
List images
|
||
|
||
-a, --all=false Show all images (by default filter out the intermediate image layers)
|
||
-f, --filter=[] Provide filter values (i.e., 'dangling=true')
|
||
--no-trunc=false Don't truncate output
|
||
-q, --quiet=false Only show numeric IDs
|
||
</code></pre>
|
||
<p>The default <code>docker images</code> will show all top level
|
||
images, their repository and tags, and their virtual size.</p>
|
||
<p>Docker images have intermediate layers that increase reusability,
|
||
decrease disk usage, and speed up <code>docker build</code> by
|
||
allowing each step to be cached. These intermediate layers are not shown
|
||
by default.</p>
|
||
<p>The <code>VIRTUAL SIZE</code> is the cumulative space taken up by the image and all
|
||
its parent images. This is also the disk space used by the contents of the
|
||
Tar file created when you <code>docker save</code> an image.</p>
|
||
<p>An image will be listed more than once if it has multiple repository names
|
||
or tags. This single image (identifiable by its matching <code>IMAGE ID</code>)
|
||
uses up the <code>VIRTUAL SIZE</code> listed only once.</p>
|
||
<h4 id="listing-the-most-recently-created-images">Listing the most recently created images</h4>
|
||
<pre class="prettyprint well"><code>$ sudo docker images | head
|
||
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
|
||
<none> <none> 77af4d6b9913 19 hours ago 1.089 GB
|
||
committ latest b6fa739cedf5 19 hours ago 1.089 GB
|
||
<none> <none> 78a85c484f71 19 hours ago 1.089 GB
|
||
docker latest 30557a29d5ab 20 hours ago 1.089 GB
|
||
<none> <none> 5ed6274db6ce 24 hours ago 1.089 GB
|
||
postgres 9 746b819f315e 4 days ago 213.4 MB
|
||
postgres 9.3 746b819f315e 4 days ago 213.4 MB
|
||
postgres 9.3.5 746b819f315e 4 days ago 213.4 MB
|
||
postgres latest 746b819f315e 4 days ago 213.4 MB
|
||
</code></pre>
|
||
<h4 id="listing-the-full-length-image-ids">Listing the full length image IDs</h4>
|
||
<pre class="prettyprint well"><code>$ sudo docker images --no-trunc | head
|
||
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
|
||
<none> <none> 77af4d6b9913e693e8d0b4b294fa62ade6054e6b2f1ffb617ac955dd63fb0182 19 hours ago 1.089 GB
|
||
committest latest b6fa739cedf5ea12a620a439402b6004d057da800f91c7524b5086a5e4749c9f 19 hours ago 1.089 GB
|
||
<none> <none> 78a85c484f71509adeaace20e72e941f6bdd2b25b4c75da8693efd9f61a37921 19 hours ago 1.089 GB
|
||
docker latest 30557a29d5abc51e5f1d5b472e79b7e296f595abcf19fe6b9199dbbc809c6ff4 20 hours ago 1.089 GB
|
||
<none> <none> 0124422dd9f9cf7ef15c0617cda3931ee68346455441d66ab8bdc5b05e9fdce5 20 hours ago 1.089 GB
|
||
<none> <none> 18ad6fad340262ac2a636efd98a6d1f0ea775ae3d45240d3418466495a19a81b 22 hours ago 1.082 GB
|
||
<none> <none> f9f1e26352f0a3ba6a0ff68167559f64f3e21ff7ada60366e2d44a04befd1d3a 23 hours ago 1.089 GB
|
||
tryout latest 2629d1fa0b81b222fca63371ca16cbf6a0772d07759ff80e8d1369b926940074 23 hours ago 131.5 MB
|
||
<none> <none> 5ed6274db6ceb2397844896966ea239290555e74ef307030ebb01ff91b1914df 24 hours ago 1.089 GB
|
||
</code></pre>
|
||
<h4 id="filtering_1">Filtering</h4>
|
||
<p>The filtering flag (<code>-f</code> or <code>--filter</code>) format is of "key=value". If there is more
|
||
than one filter, then pass multiple flags (e.g., <code>--filter "foo=bar" --filter "bif=baz"</code>)</p>
|
||
<p>Current filters:
|
||
* dangling (boolean - true or false)</p>
|
||
<h5 id="untagged-images">Untagged images</h5>
|
||
<pre class="prettyprint well"><code>$ sudo docker images --filter "dangling=true"
|
||
|
||
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
|
||
<none> <none> 8abc22fbb042 4 weeks ago 0 B
|
||
<none> <none> 48e5f45168b9 4 weeks ago 2.489 MB
|
||
<none> <none> bf747efa0e2f 4 weeks ago 0 B
|
||
<none> <none> 980fe10e5736 12 weeks ago 101.4 MB
|
||
<none> <none> dea752e4e117 12 weeks ago 101.4 MB
|
||
<none> <none> 511136ea3c5a 8 months ago 0 B
|
||
</code></pre>
|
||
<p>This will display untagged images, that are the leaves of the images tree (not
|
||
intermediary layers). These images occur when a new build of an image takes the
|
||
<code>repo:tag</code> away from the image ID, leaving it untagged. A warning will be issued
|
||
if trying to remove an image when a container is presently using it.
|
||
By having this flag it allows for batch cleanup.</p>
|
||
<p>Ready for use by <code>docker rmi ...</code>, like:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker rmi $(sudo docker images -f "dangling=true" -q)
|
||
|
||
8abc22fbb042
|
||
48e5f45168b9
|
||
bf747efa0e2f
|
||
980fe10e5736
|
||
dea752e4e117
|
||
511136ea3c5a
|
||
</code></pre>
|
||
<p>NOTE: Docker will warn you if any containers exist that are using these untagged images.</p>
|
||
<h2 id="import">import</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker import URL|- [REPOSITORY[:TAG]]
|
||
|
||
Create an empty filesystem image and import the contents of the tarball (.tar, .tar.gz, .tgz, .bzip, .tar.xz, .txz) into it, then optionally tag it.
|
||
</code></pre>
|
||
<p>URLs must start with <code>http</code> and point to a single file archive (.tar,
|
||
.tar.gz, .tgz, .bzip, .tar.xz, or .txz) containing a root filesystem. If
|
||
you would like to import from a local directory or archive, you can use
|
||
the <code>-</code> parameter to take the data from <code>STDIN</code>.</p>
|
||
<h4 id="examples_5">Examples</h4>
|
||
<p><strong>Import from a remote location:</strong></p>
|
||
<p>This will create a new untagged image.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker import http://example.com/exampleimage.tgz
|
||
</code></pre>
|
||
<p><strong>Import from a local file:</strong></p>
|
||
<p>Import to docker via pipe and <code>STDIN</code>.</p>
|
||
<pre class="prettyprint well"><code>$ cat exampleimage.tgz | sudo docker import - exampleimagelocal:new
|
||
</code></pre>
|
||
<p><strong>Import from a local directory:</strong></p>
|
||
<pre class="prettyprint well"><code>$ sudo tar -c . | sudo docker import - exampleimagedir
|
||
</code></pre>
|
||
<p>Note the <code>sudo</code> in this example – you must preserve
|
||
the ownership of the files (especially root ownership) during the
|
||
archiving with tar. If you are not root (or the sudo command) when you
|
||
tar, then the ownerships might not get preserved.</p>
|
||
<h2 id="info">info</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker info
|
||
|
||
Display system-wide information
|
||
</code></pre>
|
||
<p>For example:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker -D info
|
||
Containers: 14
|
||
Images: 52
|
||
Storage Driver: aufs
|
||
Root Dir: /var/lib/docker/aufs
|
||
Dirs: 545
|
||
Execution Driver: native-0.2
|
||
Kernel Version: 3.13.0-24-generic
|
||
Operating System: Ubuntu 14.04 LTS
|
||
CPUs: 1
|
||
Name: prod-server-42
|
||
ID: 7TRN:IPZB:QYBB:VPBQ:UMPP:KARE:6ZNR:XE6T:7EWV:PKF4:ZOJD:TPYS
|
||
Total Memory: 2 GiB
|
||
Debug mode (server): false
|
||
Debug mode (client): true
|
||
Fds: 10
|
||
Goroutines: 9
|
||
EventsListeners: 0
|
||
Init Path: /usr/bin/docker
|
||
Docker Root Dir: /var/lib/docker
|
||
Username: svendowideit
|
||
Registry: [https://index.docker.io/v1/]
|
||
Labels:
|
||
storage=ssd
|
||
</code></pre>
|
||
<p>The global <code>-D</code> option tells all <code>docker</code> commands to output debug information.</p>
|
||
<p>When sending issue reports, please use <code>docker version</code> and <code>docker -D info</code> to
|
||
ensure we know how your setup is configured.</p>
|
||
<h2 id="inspect">inspect</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker inspect [OPTIONS] CONTAINER|IMAGE [CONTAINER|IMAGE...]
|
||
|
||
Return low-level information on a container or image
|
||
|
||
-f, --format="" Format the output using the given go template.
|
||
</code></pre>
|
||
<p>By default, this will render all results in a JSON array. If a format is
|
||
specified, the given template will be executed for each result.</p>
|
||
<p>Go's <a href="http://golang.org/pkg/text/template/">text/template</a> package
|
||
describes all the details of the format.</p>
|
||
<h4 id="examples_6">Examples</h4>
|
||
<p><strong>Get an instance's IP address:</strong></p>
|
||
<p>For the most part, you can pick out any field from the JSON in a fairly
|
||
straightforward manner.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker inspect --format='{{.NetworkSettings.IPAddress}}' $INSTANCE_ID
|
||
</code></pre>
|
||
<p><strong>Get an instance's MAC Address:</strong></p>
|
||
<p>For the most part, you can pick out any field from the JSON in a fairly
|
||
straightforward manner.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker inspect --format='{{.NetworkSettings.MacAddress}}' $INSTANCE_ID
|
||
</code></pre>
|
||
<p><strong>List All Port Bindings:</strong></p>
|
||
<p>One can loop over arrays and maps in the results to produce simple text
|
||
output:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID
|
||
</code></pre>
|
||
<p><strong>Find a Specific Port Mapping:</strong></p>
|
||
<p>The <code>.Field</code> syntax doesn't work when the field name begins with a
|
||
number, but the template language's <code>index</code> function does. The
|
||
<code>.NetworkSettings.Ports</code> section contains a map of the internal port
|
||
mappings to a list of external address/port objects, so to grab just the
|
||
numeric public port, you use <code>index</code> to find the specific port map, and
|
||
then <code>index</code> 0 contains the first object inside of that. Then we ask for
|
||
the <code>HostPort</code> field to get the public address.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID
|
||
</code></pre>
|
||
<p><strong>Get config:</strong></p>
|
||
<p>The <code>.Field</code> syntax doesn't work when the field contains JSON data, but
|
||
the template language's custom <code>json</code> function does. The <code>.config</code>
|
||
section contains complex JSON object, so to grab it as JSON, you use
|
||
<code>json</code> to convert the configuration object into JSON.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker inspect --format='{{json .config}}' $INSTANCE_ID
|
||
</code></pre>
|
||
<h2 id="kill">kill</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker kill [OPTIONS] CONTAINER [CONTAINER...]
|
||
|
||
Kill a running container using SIGKILL or a specified signal
|
||
|
||
-s, --signal="KILL" Signal to send to the container
|
||
</code></pre>
|
||
<p>The main process inside the container will be sent <code>SIGKILL</code>, or any
|
||
signal specified with option <code>--signal</code>.</p>
|
||
<h2 id="load">load</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker load [OPTIONS]
|
||
|
||
Load an image from a tar archive on STDIN
|
||
|
||
-i, --input="" Read from a tar archive file, instead of STDIN
|
||
</code></pre>
|
||
<p>Loads a tarred repository from a file or the standard input stream.
|
||
Restores both images and tags.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker images
|
||
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
|
||
$ sudo docker load < busybox.tar
|
||
$ sudo docker images
|
||
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
|
||
busybox latest 769b9341d937 7 weeks ago 2.489 MB
|
||
$ sudo docker load --input fedora.tar
|
||
$ sudo docker images
|
||
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
|
||
busybox latest 769b9341d937 7 weeks ago 2.489 MB
|
||
fedora rawhide 0d20aec6529d 7 weeks ago 387 MB
|
||
fedora 20 58394af37342 7 weeks ago 385.5 MB
|
||
fedora heisenbug 58394af37342 7 weeks ago 385.5 MB
|
||
fedora latest 58394af37342 7 weeks ago 385.5 MB
|
||
</code></pre>
|
||
<h2 id="login">login</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker login [OPTIONS] [SERVER]
|
||
|
||
Register or log in to a Docker registry server, if no server is specified "https://index.docker.io/v1/" is the default.
|
||
|
||
-e, --email="" Email
|
||
-p, --password="" Password
|
||
-u, --username="" Username
|
||
</code></pre>
|
||
<p>If you want to login to a self-hosted registry you can specify this by
|
||
adding the server name.</p>
|
||
<pre class="prettyprint well"><code>example:
|
||
$ sudo docker login localhost:8080
|
||
</code></pre>
|
||
<h2 id="logout">logout</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker logout [SERVER]
|
||
|
||
Log out from a Docker registry, if no server is specified "https://index.docker.io/v1/" is the default.
|
||
</code></pre>
|
||
<p>For example:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker logout localhost:8080
|
||
</code></pre>
|
||
<h2 id="logs">logs</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker logs [OPTIONS] CONTAINER
|
||
|
||
Fetch the logs of a container
|
||
|
||
-f, --follow=false Follow log output
|
||
-t, --timestamps=false Show timestamps
|
||
--tail="all" Output the specified number of lines at the end of logs (defaults to all logs)
|
||
</code></pre>
|
||
<p>The <code>docker logs</code> command batch-retrieves logs present at the time of execution.</p>
|
||
<p>The <code>docker logs --follow</code> command will continue streaming the new output from
|
||
the container's <code>STDOUT</code> and <code>STDERR</code>.</p>
|
||
<p>Passing a negative number or a non-integer to <code>--tail</code> is invalid and the
|
||
value is set to <code>all</code> in that case. This behavior may change in the future.</p>
|
||
<p>The <code>docker logs --timestamp</code> commands will add an RFC3339Nano
|
||
timestamp, for example <code>2014-09-16T06:17:46.000000000Z</code>, to each
|
||
log entry. To ensure that the timestamps for are aligned the
|
||
nano-second part of the timestamp will be padded with zero when necessary.</p>
|
||
<h2 id="pause">pause</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker pause CONTAINER
|
||
|
||
Pause all processes within a container
|
||
</code></pre>
|
||
<p>The <code>docker pause</code> command uses the cgroups freezer to suspend all processes in
|
||
a container. Traditionally, when suspending a process the <code>SIGSTOP</code> signal is
|
||
used, which is observable by the process being suspended. With the cgroups freezer
|
||
the process is unaware, and unable to capture, that it is being suspended,
|
||
and subsequently resumed.</p>
|
||
<p>See the
|
||
<a href="https://www.kernel.org/doc/Documentation/cgroups/freezer-subsystem.txt">cgroups freezer documentation</a>
|
||
for further details.</p>
|
||
<h2 id="port">port</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker port CONTAINER [PRIVATE_PORT[/PROTO]]
|
||
|
||
List port mappings for the CONTAINER, or lookup the public-facing port that is NAT-ed to the PRIVATE_PORT
|
||
</code></pre>
|
||
<p>You can find out all the ports mapped by not specifying a <code>PRIVATE_PORT</code>, or
|
||
just a specific mapping:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker ps test
|
||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||
b650456536c7 busybox:latest top 54 minutes ago Up 54 minutes 0.0.0.0:1234->9876/tcp, 0.0.0.0:4321->7890/tcp test
|
||
$ sudo docker port test
|
||
7890/tcp -> 0.0.0.0:4321
|
||
9876/tcp -> 0.0.0.0:1234
|
||
$ sudo docker port test 7890/tcp
|
||
0.0.0.0:4321
|
||
$ sudo docker port test 7890/udp
|
||
2014/06/24 11:53:36 Error: No public port '7890/udp' published for test
|
||
$ sudo docker port test 7890
|
||
0.0.0.0:4321
|
||
</code></pre>
|
||
<h2 id="ps">ps</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker ps [OPTIONS]
|
||
|
||
List containers
|
||
|
||
-a, --all=false Show all containers. Only running containers are shown by default.
|
||
--before="" Show only container created before Id or Name, include non-running ones.
|
||
-f, --filter=[] Provide filter values. Valid filters:
|
||
exited=<int> - containers with exit code of <int>
|
||
status=(restarting|running|paused|exited)
|
||
-l, --latest=false Show only the latest created container, include non-running ones.
|
||
-n=-1 Show n last created containers, include non-running ones.
|
||
--no-trunc=false Don't truncate output
|
||
-q, --quiet=false Only display numeric IDs
|
||
-s, --size=false Display total file sizes
|
||
--since="" Show only containers created since Id or Name, include non-running ones.
|
||
</code></pre>
|
||
<p>Running <code>docker ps</code> showing 2 linked containers.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker ps
|
||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||
4c01db0b339c ubuntu:12.04 bash 17 seconds ago Up 16 seconds webapp
|
||
d7886598dbe2 crosbymichael/redis:latest /redis-server --dir 33 minutes ago Up 33 minutes 6379/tcp redis,webapp/db
|
||
</code></pre>
|
||
<p><code>docker ps</code> will show only running containers by default. To see all containers:
|
||
<code>docker ps -a</code></p>
|
||
<h4 id="filtering_2">Filtering</h4>
|
||
<p>The filtering flag (<code>-f</code> or <code>--filter)</code> format is a <code>key=value</code> pair. If there is more
|
||
than one filter, then pass multiple flags (e.g. <code>--filter "foo=bar" --filter "bif=baz"</code>)</p>
|
||
<p>Current filters:
|
||
* exited (int - the code of exited containers. Only useful with '--all')
|
||
* status (restarting|running|paused|exited)</p>
|
||
<h5 id="successfully-exited-containers">Successfully exited containers</h5>
|
||
<pre class="prettyprint well"><code>$ sudo docker ps -a --filter 'exited=0'
|
||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||
ea09c3c82f6e registry:latest /srv/run.sh 2 weeks ago Exited (0) 2 weeks ago 127.0.0.1:5000->5000/tcp desperate_leakey
|
||
106ea823fe4e fedora:latest /bin/sh -c 'bash -l' 2 weeks ago Exited (0) 2 weeks ago determined_albattani
|
||
48ee228c9464 fedora:20 bash 2 weeks ago Exited (0) 2 weeks ago tender_torvalds
|
||
</code></pre>
|
||
<p>This shows all the containers that have exited with status of '0'</p>
|
||
<h2 id="pull">pull</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker pull [OPTIONS] NAME[:TAG]
|
||
|
||
Pull an image or a repository from the registry
|
||
|
||
-a, --all-tags=false Download all tagged images in the repository
|
||
</code></pre>
|
||
<p>Most of your images will be created on top of a base image from the
|
||
<a href="https://hub.docker.com">Docker Hub</a> registry.</p>
|
||
<p><a href="https://hub.docker.com">Docker Hub</a> contains many pre-built images that you
|
||
can <code>pull</code> and try without needing to define and configure your own.</p>
|
||
<p>It is also possible to manually specify the path of a registry to pull from.
|
||
For example, if you have set up a local registry, you can specify its path to
|
||
pull from it. A repository path is similar to a URL, but does not contain
|
||
a protocol specifier (<code>https://</code>, for example).</p>
|
||
<p>To download a particular image, or set of images (i.e., a repository),
|
||
use <code>docker pull</code>:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker pull debian
|
||
# will pull the debian:latest image, its intermediate layers
|
||
# and any aliases of the same id
|
||
$ sudo docker pull debian:testing
|
||
# will pull the image named debian:testing and any intermediate
|
||
# layers it is based on.
|
||
# (Typically the empty `scratch` image, a MAINTAINER layer,
|
||
# and the un-tarred base).
|
||
$ sudo docker pull --all-tags centos
|
||
# will pull all the images from the centos repository
|
||
$ sudo docker pull registry.hub.docker.com/debian
|
||
# manually specifies the path to the default Docker registry. This could
|
||
# be replaced with the path to a local registry to pull from another source.
|
||
</code></pre>
|
||
<h2 id="push">push</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker push NAME[:TAG]
|
||
|
||
Push an image or a repository to the registry
|
||
</code></pre>
|
||
<p>Use <code>docker push</code> to share your images to the <a href="https://hub.docker.com">Docker Hub</a>
|
||
registry or to a self-hosted one.</p>
|
||
<h2 id="restart">restart</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker restart [OPTIONS] CONTAINER [CONTAINER...]
|
||
|
||
Restart a running container
|
||
|
||
-t, --time=10 Number of seconds to try to stop for before killing the container. Once killed it will then be restarted. Default is 10 seconds.
|
||
</code></pre>
|
||
<h2 id="rm">rm</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...]
|
||
|
||
Remove one or more containers
|
||
|
||
-f, --force=false Force the removal of a running container (uses SIGKILL)
|
||
-l, --link=false Remove the specified link and not the underlying container
|
||
-v, --volumes=false Remove the volumes associated with the container
|
||
</code></pre>
|
||
<h4 id="examples_7">Examples</h4>
|
||
<pre class="prettyprint well"><code>$ sudo docker rm /redis
|
||
/redis
|
||
</code></pre>
|
||
<p>This will remove the container referenced under the link
|
||
<code>/redis</code>.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker rm --link /webapp/redis
|
||
/webapp/redis
|
||
</code></pre>
|
||
<p>This will remove the underlying link between <code>/webapp</code> and the <code>/redis</code>
|
||
containers removing all network communication.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker rm --force redis
|
||
redis
|
||
</code></pre>
|
||
<p>The main process inside the container referenced under the link <code>/redis</code> will receive
|
||
<code>SIGKILL</code>, then the container will be removed.</p>
|
||
<p>This command will delete all stopped containers. The command <code>docker ps
|
||
-a -q</code> will return all existing container IDs and pass them to the <code>rm</code>
|
||
command which will delete them. Any running containers will not be
|
||
deleted.</p>
|
||
<h2 id="rmi">rmi</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker rmi [OPTIONS] IMAGE [IMAGE...]
|
||
|
||
Remove one or more images
|
||
|
||
-f, --force=false Force removal of the image
|
||
--no-prune=false Do not delete untagged parents
|
||
</code></pre>
|
||
<h4 id="removing-tagged-images">Removing tagged images</h4>
|
||
<p>Images can be removed either by their short or long IDs, or their image
|
||
names. If an image has more than one name, each of them needs to be
|
||
removed before the image is removed.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker images
|
||
REPOSITORY TAG IMAGE ID CREATED SIZE
|
||
test1 latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB)
|
||
test latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB)
|
||
test2 latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB)
|
||
|
||
$ sudo docker rmi fd484f19954f
|
||
Error: Conflict, cannot delete image fd484f19954f because it is tagged in multiple repositories
|
||
2013/12/11 05:47:16 Error: failed to remove one or more images
|
||
|
||
$ sudo docker rmi test1
|
||
Untagged: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8
|
||
$ sudo docker rmi test2
|
||
Untagged: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8
|
||
|
||
$ sudo docker images
|
||
REPOSITORY TAG IMAGE ID CREATED SIZE
|
||
test latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB)
|
||
$ sudo docker rmi test
|
||
Untagged: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8
|
||
Deleted: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8
|
||
</code></pre>
|
||
<h2 id="run">run</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
|
||
|
||
Run a command in a new container
|
||
|
||
-a, --attach=[] Attach to STDIN, STDOUT or STDERR.
|
||
--add-host=[] Add a custom host-to-IP mapping (host:ip)
|
||
-c, --cpu-shares=0 CPU shares (relative weight)
|
||
--cap-add=[] Add Linux capabilities
|
||
--cap-drop=[] Drop Linux capabilities
|
||
--cidfile="" Write the container ID to the file
|
||
--cpuset="" CPUs in which to allow execution (0-3, 0,1)
|
||
-d, --detach=false Detached mode: run the container in the background and print the new container ID
|
||
--device=[] Add a host device to the container (e.g. --device=/dev/sdc:/dev/xvdc:rwm)
|
||
--dns=[] Set custom DNS servers
|
||
--dns-search=[] Set custom DNS search domains (Use --dns-search=. if you don't wish to set the search domain)
|
||
-e, --env=[] Set environment variables
|
||
--entrypoint="" Overwrite the default ENTRYPOINT of the image
|
||
--env-file=[] Read in a line delimited file of environment variables
|
||
--expose=[] Expose a port or a range of ports (e.g. --expose=3300-3310) from the container without publishing it to your host
|
||
-h, --hostname="" Container host name
|
||
-i, --interactive=false Keep STDIN open even if not attached
|
||
--ipc="" Default is to create a private IPC namespace (POSIX SysV IPC) for the container
|
||
'container:<name|id>': reuses another container shared memory, semaphores and message queues
|
||
'host': use the host shared memory,semaphores and message queues inside the container. Note: the host mode gives the container full access to local shared memory and is therefore considered insecure.
|
||
--link=[] Add link to another container in the form of name:alias
|
||
--lxc-conf=[] (lxc exec-driver only) Add custom lxc options --lxc-conf="lxc.cgroup.cpuset.cpus = 0,1"
|
||
-m, --memory="" Memory limit (format: <number><optional unit>, where unit = b, k, m or g)
|
||
--mac-address="" Container MAC address (e.g. 92:d0:c6:0a:29:33)
|
||
--name="" Assign a name to the container
|
||
--net="bridge" Set the Network mode for the container
|
||
'bridge': creates a new network stack for the container on the docker bridge
|
||
'none': no networking for this container
|
||
'container:<name|id>': reuses another container network stack
|
||
'host': use the host network stack inside the container. Note: the host mode gives the container full access to local system services such as D-bus and is therefore considered insecure.
|
||
-P, --publish-all=false Publish all exposed ports to the host interfaces
|
||
-p, --publish=[] Publish a container's port to the host
|
||
format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort
|
||
(use 'docker port' to see the actual mapping)
|
||
--privileged=false Give extended privileges to this container
|
||
--restart="" Restart policy to apply when a container exits (no, on-failure[:max-retry], always)
|
||
--rm=false Automatically remove the container when it exits (incompatible with -d)
|
||
--security-opt=[] Security Options
|
||
--sig-proxy=true Proxy received signals to the process (non-TTY mode only). SIGCHLD, SIGSTOP, and SIGKILL are not proxied.
|
||
-t, --tty=false Allocate a pseudo-TTY
|
||
-u, --user="" Username or UID
|
||
-v, --volume=[] Bind mount a volume (e.g., from the host: -v /host:/container, from Docker: -v /container)
|
||
--volumes-from=[] Mount volumes from the specified container(s)
|
||
-w, --workdir="" Working directory inside the container
|
||
</code></pre>
|
||
<p>The <code>docker run</code> command first <code>creates</code> a writeable container layer over the
|
||
specified image, and then <code>starts</code> it using the specified command. That is,
|
||
<code>docker run</code> is equivalent to the API <code>/containers/create</code> then
|
||
<code>/containers/(id)/start</code>. A stopped container can be restarted with all its
|
||
previous changes intact using <code>docker start</code>. See <code>docker ps -a</code> to view a list
|
||
of all containers.</p>
|
||
<p>There is detailed information about <code>docker run</code> in the <a href="/reference/run/">Docker run reference</a>.</p>
|
||
<p>The <code>docker run</code> command can be used in combination with <code>docker commit</code> to
|
||
<a href="#commit-an-existing-container"><em>change the command that a container runs</em></a>.</p>
|
||
<p>See the <a href="/userguide/dockerlinks/">Docker User Guide</a> for more detailed
|
||
information about the <code>--expose</code>, <code>-p</code>, <code>-P</code> and <code>--link</code> parameters,
|
||
and linking containers.</p>
|
||
<h4 id="examples_8">Examples</h4>
|
||
<pre class="prettyprint well"><code>$ sudo docker run --cidfile /tmp/docker_test.cid ubuntu echo "test"
|
||
</code></pre>
|
||
<p>This will create a container and print <code>test</code> to the console. The <code>cidfile</code>
|
||
flag makes Docker attempt to create a new file and write the container ID to it.
|
||
If the file exists already, Docker will return an error. Docker will close this
|
||
file when <code>docker run</code> exits.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker run -t -i --rm ubuntu bash
|
||
root@bc338942ef20:/# mount -t tmpfs none /mnt
|
||
mount: permission denied
|
||
</code></pre>
|
||
<p>This will <em>not</em> work, because by default, most potentially dangerous kernel
|
||
capabilities are dropped; including <code>cap_sys_admin</code> (which is required to mount
|
||
filesystems). However, the <code>--privileged</code> flag will allow it to run:</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker run --privileged ubuntu bash
|
||
root@50e3f57e16e6:/# mount -t tmpfs none /mnt
|
||
root@50e3f57e16e6:/# df -h
|
||
Filesystem Size Used Avail Use% Mounted on
|
||
none 1.9G 0 1.9G 0% /mnt
|
||
</code></pre>
|
||
<p>The <code>--privileged</code> flag gives <em>all</em> capabilities to the container, and it also
|
||
lifts all the limitations enforced by the <code>device</code> cgroup controller. In other
|
||
words, the container can then do almost everything that the host can do. This
|
||
flag exists to allow special use-cases, like running Docker within Docker.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker run -w /path/to/dir/ -i -t ubuntu pwd
|
||
</code></pre>
|
||
<p>The <code>-w</code> lets the command being executed inside directory given, here
|
||
<code>/path/to/dir/</code>. If the path does not exists it is created inside the container.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker run -v `pwd`:`pwd` -w `pwd` -i -t ubuntu pwd
|
||
</code></pre>
|
||
<p>The <code>-v</code> flag mounts the current working directory into the container. The <code>-w</code>
|
||
lets the command being executed inside the current working directory, by
|
||
changing into the directory to the value returned by <code>pwd</code>. So this
|
||
combination executes the command using the container, but inside the
|
||
current working directory.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker run -v /doesnt/exist:/foo -w /foo -i -t ubuntu bash
|
||
</code></pre>
|
||
<p>When the host directory of a bind-mounted volume doesn't exist, Docker
|
||
will automatically create this directory on the host for you. In the
|
||
example above, Docker will create the <code>/doesnt/exist</code>
|
||
folder before starting your container.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker run -t -i -v /var/run/docker.sock:/var/run/docker.sock -v ./static-docker:/usr/bin/docker busybox sh
|
||
</code></pre>
|
||
<p>By bind-mounting the docker unix socket and statically linked docker
|
||
binary (such as that provided by <a href="https://get.docker.com">https://get.docker.com</a>), you give the container the full access to create and
|
||
manipulate the host's Docker daemon.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker run -p 127.0.0.1:80:8080 ubuntu bash
|
||
</code></pre>
|
||
<p>This binds port <code>8080</code> of the container to port <code>80</code> on <code>127.0.0.1</code> of
|
||
the host machine. The <a href="/userguide/dockerlinks/">Docker User Guide</a>
|
||
explains in detail how to manipulate ports in Docker.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker run --expose 80 ubuntu bash
|
||
</code></pre>
|
||
<p>This exposes port <code>80</code> of the container for use within a link without
|
||
publishing the port to the host system's interfaces. The <a href="/userguide/dockerlinks">Docker User
|
||
Guide</a> explains in detail how to manipulate
|
||
ports in Docker.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker run -e MYVAR1 --env MYVAR2=foo --env-file ./env.list ubuntu bash
|
||
</code></pre>
|
||
<p>This sets environmental variables in the container. For illustration all three
|
||
flags are shown here. Where <code>-e</code>, <code>--env</code> take an environment variable and
|
||
value, or if no "=" is provided, then that variable's current value is passed
|
||
through (i.e. <code>$MYVAR1</code> from the host is set to <code>$MYVAR1</code> in the container). All
|
||
three flags, <code>-e</code>, <code>--env</code> and <code>--env-file</code> can be repeated.</p>
|
||
<p>Regardless of the order of these three flags, the <code>--env-file</code> are processed
|
||
first, and then <code>-e</code>, <code>--env</code> flags. This way, the <code>-e</code> or <code>--env</code> will
|
||
override variables as needed.</p>
|
||
<pre class="prettyprint well"><code>$ cat ./env.list
|
||
TEST_FOO=BAR
|
||
$ sudo docker run --env TEST_FOO="This is a test" --env-file ./env.list busybox env | grep TEST_FOO
|
||
TEST_FOO=This is a test
|
||
</code></pre>
|
||
<p>The <code>--env-file</code> flag takes a filename as an argument and expects each line
|
||
to be in the <code>VAR=VAL</code> format, mimicking the argument passed to <code>--env</code>. Comment
|
||
lines need only be prefixed with <code>#</code></p>
|
||
<p>An example of a file passed with <code>--env-file</code></p>
|
||
<pre class="prettyprint well"><code>$ cat ./env.list
|
||
TEST_FOO=BAR
|
||
|
||
# this is a comment
|
||
TEST_APP_DEST_HOST=10.10.0.127
|
||
TEST_APP_DEST_PORT=8888
|
||
|
||
# pass through this variable from the caller
|
||
TEST_PASSTHROUGH
|
||
$ sudo TEST_PASSTHROUGH=howdy docker run --env-file ./env.list busybox env
|
||
HOME=/
|
||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||
HOSTNAME=5198e0745561
|
||
TEST_FOO=BAR
|
||
TEST_APP_DEST_HOST=10.10.0.127
|
||
TEST_APP_DEST_PORT=8888
|
||
TEST_PASSTHROUGH=howdy
|
||
|
||
$ sudo docker run --name console -t -i ubuntu bash
|
||
</code></pre>
|
||
<p>This will create and run a new container with the container name being
|
||
<code>console</code>.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker run --link /redis:redis --name console ubuntu bash
|
||
</code></pre>
|
||
<p>The <code>--link</code> flag will link the container named <code>/redis</code> into the newly
|
||
created container with the alias <code>redis</code>. The new container can access the
|
||
network and environment of the <code>redis</code> container via environment variables.
|
||
The <code>--name</code> flag will assign the name <code>console</code> to the newly created
|
||
container.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker run --volumes-from 777f7dc92da7 --volumes-from ba8c0c54f0f2:ro -i -t ubuntu pwd
|
||
</code></pre>
|
||
<p>The <code>--volumes-from</code> flag mounts all the defined volumes from the referenced
|
||
containers. Containers can be specified by repetitions of the <code>--volumes-from</code>
|
||
argument. The container ID may be optionally suffixed with <code>:ro</code> or <code>:rw</code> to
|
||
mount the volumes in read-only or read-write mode, respectively. By default,
|
||
the volumes are mounted in the same mode (read write or read only) as
|
||
the reference container.</p>
|
||
<p>The <code>-a</code> flag tells <code>docker run</code> to bind to the container's <code>STDIN</code>, <code>STDOUT</code> or
|
||
<code>STDERR</code>. This makes it possible to manipulate the output and input as needed.</p>
|
||
<pre class="prettyprint well"><code>$ echo "test" | sudo docker run -i -a stdin ubuntu cat -
|
||
</code></pre>
|
||
<p>This pipes data into a container and prints the container's ID by attaching
|
||
only to the container's <code>STDIN</code>.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker run -a stderr ubuntu echo test
|
||
</code></pre>
|
||
<p>This isn't going to print anything unless there's an error because we've
|
||
only attached to the <code>STDERR</code> of the container. The container's logs
|
||
still store what's been written to <code>STDERR</code> and <code>STDOUT</code>.</p>
|
||
<pre class="prettyprint well"><code>$ cat somefile | sudo docker run -i -a stdin mybuilder dobuild
|
||
</code></pre>
|
||
<p>This is how piping a file into a container could be done for a build.
|
||
The container's ID will be printed after the build is done and the build
|
||
logs could be retrieved using <code>docker logs</code>. This is
|
||
useful if you need to pipe a file or something else into a container and
|
||
retrieve the container's ID once the container has finished running.</p>
|
||
<p>$ sudo docker run --device=/dev/sdc:/dev/xvdc --device=/dev/sdd --device=/dev/zero:/dev/nulo -i -t ubuntu ls -l /dev/{xvdc,sdd,nulo}
|
||
brw-rw---- 1 root disk 8, 2 Feb 9 16:05 /dev/xvdc
|
||
brw-rw---- 1 root disk 8, 3 Feb 9 16:05 /dev/sdd
|
||
crw-rw-rw- 1 root root 1, 5 Feb 9 16:05 /dev/nulo</p>
|
||
<p>It is often necessary to directly expose devices to a container. The <code>--device</code>
|
||
option enables that. For example, a specific block storage device or loop
|
||
device or audio device can be added to an otherwise unprivileged container
|
||
(without the <code>--privileged</code> flag) and have the application directly access it.</p>
|
||
<p>By default, the container will be able to <code>read</code>, <code>write</code> and <code>mknod</code> these devices.
|
||
This can be overridden using a third <code>:rwm</code> set of options to each <code>--device</code>
|
||
flag:</p>
|
||
<pre class="prettyprint well"><code> $ sudo docker run --device=/dev/sda:/dev/xvdc --rm -it ubuntu fdisk /dev/xvdc
|
||
|
||
Command (m for help): q
|
||
$ sudo docker run --device=/dev/sda:/dev/xvdc:r --rm -it ubuntu fdisk /dev/xvdc
|
||
You will not be able to write the partition table.
|
||
|
||
Command (m for help): q
|
||
|
||
$ sudo docker run --device=/dev/sda:/dev/xvdc --rm -it ubuntu fdisk /dev/xvdc
|
||
|
||
Command (m for help): q
|
||
|
||
$ sudo docker run --device=/dev/sda:/dev/xvdc:m --rm -it ubuntu fdisk /dev/xvdc
|
||
fdisk: unable to open /dev/xvdc: Operation not permitted
|
||
</code></pre>
|
||
|
||
<p><strong>Note:</strong></p>
|
||
<blockquote>
|
||
<p><code>--device</code> cannot be safely used with ephemeral devices. Block devices that
|
||
may be removed should not be added to untrusted containers with <code>--device</code>.</p>
|
||
</blockquote>
|
||
<p><strong>A complete example:</strong></p>
|
||
<pre class="prettyprint well"><code>$ sudo docker run -d --name static static-web-files sh
|
||
$ sudo docker run -d --expose=8098 --name riak riakserver
|
||
$ sudo docker run -d -m 100m -e DEVELOPMENT=1 -e BRANCH=example-code -v $(pwd):/app/bin:ro --name app appserver
|
||
$ sudo docker run -d -p 1443:443 --dns=10.0.0.1 --dns-search=dev.org -v /var/log/httpd --volumes-from static --link riak --link app -h www.sven.dev.org --name web webserver
|
||
$ sudo docker run -t -i --rm --volumes-from web -w /var/log/httpd busybox tail -f access.log
|
||
</code></pre>
|
||
<p>This example shows five containers that might be set up to test a web
|
||
application change:</p>
|
||
<ol>
|
||
<li>Start a pre-prepared volume image <code>static-web-files</code> (in the background)
|
||
that has CSS, image and static HTML in it, (with a <code>VOLUME</code> instruction in
|
||
the Dockerfile to allow the web server to use those files);</li>
|
||
<li>Start a pre-prepared <code>riakserver</code> image, give the container name <code>riak</code> and
|
||
expose port <code>8098</code> to any containers that link to it;</li>
|
||
<li>Start the <code>appserver</code> image, restricting its memory usage to 100MB, setting
|
||
two environment variables <code>DEVELOPMENT</code> and <code>BRANCH</code> and bind-mounting the
|
||
current directory (<code>$(pwd)</code>) in the container in read-only mode as <code>/app/bin</code>;</li>
|
||
<li>Start the <code>webserver</code>, mapping port <code>443</code> in the container to port <code>1443</code> on
|
||
the Docker server, setting the DNS server to <code>10.0.0.1</code> and DNS search
|
||
domain to <code>dev.org</code>, creating a volume to put the log files into (so we can
|
||
access it from another container), then importing the files from the volume
|
||
exposed by the <code>static</code> container, and linking to all exposed ports from
|
||
<code>riak</code> and <code>app</code>. Lastly, we set the hostname to <code>web.sven.dev.org</code> so its
|
||
consistent with the pre-generated SSL certificate;</li>
|
||
<li>Finally, we create a container that runs <code>tail -f access.log</code> using the logs
|
||
volume from the <code>web</code> container, setting the workdir to <code>/var/log/httpd</code>. The
|
||
<code>--rm</code> option means that when the container exits, the container's layer is
|
||
removed.</li>
|
||
</ol>
|
||
<h4 id="restart-policies">Restart Policies</h4>
|
||
<p>Using the <code>--restart</code> flag on Docker run you can specify a restart policy for
|
||
how a container should or should not be restarted on exit.</p>
|
||
<p>An ever increasing delay (double the previous delay, starting at 100 milliseconds)
|
||
is added before each restart to prevent flooding the server. This means the daemaon
|
||
will wait for 100 mS, then 200 mS, 400, 800, 1600, and so on until either the
|
||
<code>on-failure</code> limit is hit, or when you <code>docker stop</code> or even <code>docker rm -f</code>
|
||
the container.</p>
|
||
<p>When a restart policy is active on a container, it will be shown in <code>docker ps</code>
|
||
as either <code>Up</code> or <code>Restarting</code> in <code>docker ps</code>. It can also be useful to use
|
||
<code>docker events</code> to see the restart policy in effect.</p>
|
||
<p><strong> no </strong> - Do not restart the container when it exits.</p>
|
||
<p><strong> on-failure </strong> - Restart the container only if it exits with a non zero exit status.</p>
|
||
<p><strong> always </strong> - Always restart the container regardless of the exit status.</p>
|
||
<p>You can also specify the maximum amount of times Docker will try to
|
||
restart the container when using the <strong> on-failure </strong> policy. The
|
||
default is that Docker will try forever to restart the container.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker run --restart=always redis
|
||
</code></pre>
|
||
<p>This will run the <code>redis</code> container with a restart policy of <strong> always </strong> so that if
|
||
the container exits, Docker will restart it.</p>
|
||
<pre class="prettyprint well"><code>$ sudo docker run --restart=on-failure:10 redis
|
||
</code></pre>
|
||
<p>This will run the <code>redis</code> container with a restart policy of <strong>
|
||
on-failure </strong> and a maximum restart count of 10. If the <code>redis</code>
|
||
container exits with a non-zero exit status more than 10 times in a row
|
||
Docker will abort trying to restart the container. Providing a maximum
|
||
restart limit is only valid for the <strong> on-failure </strong> policy.</p>
|
||
<h3 id="adding-entries-to-a-container-hosts-file">Adding entries to a container hosts file</h3>
|
||
<p>You can add other hosts into a container's <code>/etc/hosts</code> file by using one or more
|
||
<code>--add-host</code> flags. This example adds a static address for a host named <code>docker</code>:</p>
|
||
<pre class="prettyprint well"><code> $ docker run --add-host=docker:10.180.0.1 --rm -it debian
|
||
$$ ping docker
|
||
PING docker (10.180.0.1): 48 data bytes
|
||
56 bytes from 10.180.0.1: icmp_seq=0 ttl=254 time=7.600 ms
|
||
56 bytes from 10.180.0.1: icmp_seq=1 ttl=254 time=30.705 ms
|
||
^C--- docker ping statistics ---
|
||
2 packets transmitted, 2 packets received, 0% packet loss
|
||
round-trip min/avg/max/stddev = 7.600/19.152/30.705/11.553 ms
|
||
</code></pre>
|
||
|
||
<blockquote>
|
||
<p><strong>Note:</strong>
|
||
Sometimes you need to connect to the Docker host, which means getting the IP
|
||
address of the host. You can use the following shell commands to simplify this
|
||
process:</p>
|
||
<pre class="prettyprint well"><code> $ alias hostip="ip route show 0.0.0.0/0 | grep -Eo 'via \S+' | awk '{ print \$2 }'"
|
||
$ docker run --add-host=docker:$(hostip) --rm -it debian
|
||
</code></pre>
|
||
</blockquote>
|
||
<h2 id="save">save</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker save [OPTIONS] IMAGE [IMAGE...]
|
||
|
||
Save an image(s) to a tar archive (streamed to STDOUT by default)
|
||
|
||
-o, --output="" Write to a file, instead of STDOUT
|
||
</code></pre>
|
||
<p>Produces a tarred repository to the standard output stream.
|
||
Contains all parent layers, and all tags + versions, or specified <code>repo:tag</code>, for
|
||
each argument provided.</p>
|
||
<p>It is used to create a backup that can then be used with <code>docker load</code></p>
|
||
<pre class="prettyprint well"><code>$ sudo docker save busybox > busybox.tar
|
||
$ ls -sh busybox.tar
|
||
2.7M busybox.tar
|
||
$ sudo docker save --output busybox.tar busybox
|
||
$ ls -sh busybox.tar
|
||
2.7M busybox.tar
|
||
$ sudo docker save -o fedora-all.tar fedora
|
||
$ sudo docker save -o fedora-latest.tar fedora:latest
|
||
</code></pre>
|
||
<p>It is even useful to cherry-pick particular tags of an image repository</p>
|
||
<p>$ sudo docker save -o ubuntu.tar ubuntu:lucid ubuntu:saucy</p>
|
||
<h2 id="search">search</h2>
|
||
<p>Search <a href="https://hub.docker.com">Docker Hub</a> for images</p>
|
||
<pre class="prettyprint well"><code>Usage: docker search [OPTIONS] TERM
|
||
|
||
Search the Docker Hub for images
|
||
|
||
--automated=false Only show automated builds
|
||
--no-trunc=false Don't truncate output
|
||
-s, --stars=0 Only displays with at least x stars
|
||
</code></pre>
|
||
<p>See <a href="/userguide/dockerrepos/#searching-for-images"><em>Find Public Images on Docker Hub</em></a> for
|
||
more details on finding shared images from the command line.</p>
|
||
<blockquote>
|
||
<p><strong>Note:</strong>
|
||
Search queries will only return up to 25 results </p>
|
||
</blockquote>
|
||
<h2 id="start">start</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker start [OPTIONS] CONTAINER [CONTAINER...]
|
||
|
||
Restart a stopped container
|
||
|
||
-a, --attach=false Attach container's STDOUT and STDERR and forward all signals to the process
|
||
-i, --interactive=false Attach container's STDIN
|
||
</code></pre>
|
||
<p>When run on a container that has already been started,
|
||
takes no action and succeeds unconditionally.</p>
|
||
<h2 id="stop">stop</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...]
|
||
|
||
Stop a running container by sending SIGTERM and then SIGKILL after a grace period
|
||
|
||
-t, --time=10 Number of seconds to wait for the container to stop before killing it. Default is 10 seconds.
|
||
</code></pre>
|
||
<p>The main process inside the container will receive <code>SIGTERM</code>, and after a
|
||
grace period, <code>SIGKILL</code>.</p>
|
||
<h2 id="tag">tag</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]
|
||
|
||
Tag an image into a repository
|
||
|
||
-f, --force=false Force
|
||
</code></pre>
|
||
<p>You can group your images together using names and tags, and then upload
|
||
them to <a href="/userguide/dockerrepos/#contributing-to-docker-hub"><em>Share Images via Repositories</em></a>.</p>
|
||
<h2 id="top">top</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker top CONTAINER [ps OPTIONS]
|
||
|
||
Display the running processes of a container
|
||
</code></pre>
|
||
<h2 id="unpause">unpause</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker unpause CONTAINER
|
||
|
||
Unpause all processes within a container
|
||
</code></pre>
|
||
<p>The <code>docker unpause</code> command uses the cgroups freezer to un-suspend all
|
||
processes in a container.</p>
|
||
<p>See the
|
||
<a href="https://www.kernel.org/doc/Documentation/cgroups/freezer-subsystem.txt">cgroups freezer documentation</a>
|
||
for further details.</p>
|
||
<h2 id="version">version</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker version
|
||
|
||
Show the Docker version information.
|
||
</code></pre>
|
||
<p>Show the Docker version, API version, Git commit, and Go version of
|
||
both Docker client and daemon.</p>
|
||
<h2 id="wait">wait</h2>
|
||
<pre class="prettyprint well"><code>Usage: docker wait CONTAINER [CONTAINER...]
|
||
|
||
Block until a container stops, then print its exit code.
|
||
</code></pre>
|
||
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="push-footer"></div>
|
||
|
||
</div>
|
||
|
||
|
||
|
||
<div id="footer-container" class="container">
|
||
<div id="footer" class="grey-body">
|
||
<div class="row">
|
||
<div class="span2">
|
||
<span class="footer-title">Community</span>
|
||
<ul class="unstyled">
|
||
<li><a class="primary-button" href="https://www.docker.com/community/events/">Events</a></li>
|
||
<li><a class="primary-button" href="http://posts.docker.com">Friends' Posts</a></li>
|
||
<li><a class="primary-button" href="https://www.docker.com/community/meetups/">Meetups</a></li>
|
||
<li><a class="primary-button" href="https://www.docker.com/community/governance/">Governance</a></li>
|
||
<li><a class="primary-button" href="http://forums.docker.com">Forums</a></li>
|
||
<li><a class="primary-button" href="http://botbot.me/freenode/docker">IRC</a></li>
|
||
<li><a class="primary-button" href="https://github.com/docker/docker">GitHub</a></li>
|
||
<li><a class="primary-button" href="http://stackoverflow.com/search?q=docker">Stackoverflow</a></li>
|
||
<li><a class="primary-button" href="http://www.cafepress.com/docker">Swag</a></li>
|
||
</ul>
|
||
</div>
|
||
<div class="span2">
|
||
<span class="footer-title">Enterprise</span>
|
||
<ul class="unstyled">
|
||
<li><a class="primary-button" href="https://www.docker.com/enterprise/support/">Support</a></li>
|
||
<li><a class="primary-button" href="https://www.docker.com/enterprise/education/">Education</a></li>
|
||
<li><a class="primary-button" href="https://www.docker.com/enterprise/services/">Services</a></li>
|
||
</ul>
|
||
<span class="footer-title">Partner Solutions</span>
|
||
<ul class="unstyled">
|
||
<li><a class="primary-button" href="https://www.docker.com/partners/find/">Find a Partner</a></li>
|
||
<li><a class="primary-button" href="https://www.docker.com/partners/program/">Partner Program</a></li>
|
||
<li><a class="primary-button" href="https://www.docker.com/partners/learn/">Learn More</a></li>
|
||
</ul>
|
||
</div>
|
||
<div class="span2">
|
||
<span class="footer-title">Resources</span>
|
||
<ul class="unstyled">
|
||
<li><a class="primary-button" href="https://docs.docker.com">Documentation</a></li>
|
||
<li><a class="primary-button" href="https://www.docker.com/resources/help/">Help</a></li>
|
||
<li><a class="primary-button" href="https://www.docker.com/resources/usecases/">Use Cases</a></li>
|
||
<li><a class="primary-button" href="http://www.docker.com/tryit/">Online Tutorial</a></li>
|
||
<li><a class="primary-button" href="https://www.docker.com/resources/howtobuy/">How To Buy</a></li>
|
||
<li><a class="primary-button" href="http://status.docker.com">Status</a></li>
|
||
<li><a class="primary-button" href="https://www.docker.com/resources/security/">Security</a></li>
|
||
</ul>
|
||
</div>
|
||
<div class="span2">
|
||
<span class="footer-title">Company</span>
|
||
<ul class="unstyled">
|
||
<li><a class="primary-button" href="https://www.docker.com/company/aboutus/">About Us</a></li>
|
||
<li><a class="primary-button" href="https://www.docker.com/company/team/">Team</a></li>
|
||
<li><a class="primary-button" href="https://www.docker.com/company/news/">News</a></li>
|
||
<li><a class="primary-button" href="https://www.docker.com/company/press/">Press</a></li>
|
||
<li><a class="primary-button" href="https://www.docker.com/company/careers/">Careers</a></li>
|
||
<li><a class="primary-button" href="https://www.docker.com/company/contact/">Contact</a></li>
|
||
</ul>
|
||
</div>
|
||
<div class="span3">
|
||
<span class="footer-title">Connect</span>
|
||
<div class="search">
|
||
<span>Subscribe to our newsletter</span>
|
||
<form action="https://www.docker.com/subscribe_newsletter/" method="post">
|
||
<input type='hidden' name='csrfmiddlewaretoken' value='aWL78QXQkY8DSKNYh6cl08p5eTLl7sOa' />
|
||
<tr><th><label for="id_email">Email:</label></th><td><input class="form-control" id="id_email" name="email" placeholder="Enter your email" type="text" /></td></tr>
|
||
|
||
<button type="submit"><i class="icon-arrow-right"></i> </button>
|
||
</form>
|
||
</div>
|
||
<ul class="unstyled social">
|
||
<li><a title="Docker on Twitter" class="primary-button blog" href="http://blog.docker.com">Blog</a></li>
|
||
<li><a title="Docker on Twitter" class="primary-button twitter" href="http://twitter.com/docker">Twitter</a></li>
|
||
<li><a title="Docker on Google+" class="primary-button googleplus" href="https://plus.google.com/u/0/communities/108146856671494713993">Google+</a></li>
|
||
<li><a title="Docker on Facebook" class="primary-button facebook" href="https://www.facebook.com/docker.run">Facebook</a></li>
|
||
<li><a title="Docker on Youtube" class="primary-button youtube" href="http://www.youtube.com/user/dockerrun">YouTube</a></li>
|
||
</ul>
|
||
<ul class="unstyled social">
|
||
<li><a title="Docker on SlideShare" class="primary-button slideshare" href="http://www.slideshare.net/Docker">Slideshare</a></li>
|
||
<li>
|
||
<a title="Docker on LinkedIn" class="primary-button" href="https://www.linkedin.com/company/docker">
|
||
<span class="linkedin"></span>
|
||
LinkedIn
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a title="Docker on GitHub" class="primary-button" href="https://github.com/docker/">
|
||
<span class="github"></span>
|
||
GitHub
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a title="Docker on Reddit" class="primary-button" href="http://www.reddit.com/r/docker">
|
||
<span class="reddit"></span>
|
||
Reddit
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a title="Docker on AngelList" class="primary-button" href="https://angel.co/docker-inc-1">
|
||
<span class="angellist"></span>
|
||
AngelList
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
<div class="row clearfix">
|
||
<div class="span6 pagination-right copyright">
|
||
<span>© 2014-2015 Docker, Inc.</span>
|
||
</div>
|
||
<div class="span6 pagination-left copyright">
|
||
<a href="http://www.docker.com/legal/terms_of_service">Terms</a> ·
|
||
<a href="http://www.docker.com/legal/privacy_policy">Privacy</a> ·
|
||
<a href="http://www.docker.com/legal/trademark_guidelines">Trademarks</a>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script src="/js/jquery-1.10.2.min.js"></script>
|
||
<script src="/js/jquery.cookie.js" ></script>
|
||
<script src="/js/jquery-scrolltofixed-min.js"></script>
|
||
<script src="/js/bootstrap-3.0.3.min.js"></script>
|
||
<script src="/js/prettify-1.0.min.js"></script>
|
||
<script src="/js/dockerfile_tutorial.js"></script>
|
||
<script src="/js/dockerfile_tutorial_level.js"></script>
|
||
<script src="/js/base.js"></script>
|
||
<script src="/tipuesearch/tipuesearch_set.js"></script>
|
||
<script src="/tipuesearch/tipuesearch.min.js"></script>
|
||
<script type="text/javascript">
|
||
piAId = '45082';
|
||
piCId = '1482';
|
||
|
||
(function() {
|
||
function async_load(){
|
||
var s = document.createElement('script'); s.type = 'text/javascript';
|
||
s.src = ('https:' == document.location.protocol ? 'https://pi' : 'http://cdn') + '.pardot.com/pd.js';
|
||
var c = document.getElementsByTagName('script')[0]; c.parentNode.insertBefore(s, c);
|
||
}
|
||
if(window.attachEvent) { window.attachEvent('onload', async_load); }
|
||
else { window.addEventListener('load', async_load, false); }
|
||
})();
|
||
</script>
|
||
<script type="text/javascript">
|
||
$(document).ready(function() {
|
||
$('#content').css("min-height", $(window).height() - 553 );
|
||
// if the URL contains a version string, update the version picker to reflect that
|
||
version = document.location.pathname.match(/^\/(v\d\.\d)\/.*/)
|
||
if (version && version[1]) {
|
||
$('#document-version-number')[0].text = 'Version '+version[1];
|
||
} else {
|
||
$('#document-version-number')[0].text = $('#document-version-number')[0].text + " (Latest)"
|
||
}
|
||
// load the complete versions list
|
||
$.get("/versions.html_fragment", function( data ) {
|
||
$('#documentation-version-list').prepend(data);
|
||
//remove any "/v1.1/" bits from front, so we can add the path to the version selection dropdown.
|
||
path = document.location.pathname.replace(/^\/v\d\.\d/, "");
|
||
$('#documentation-version-list a.version').each(function(i, e) {
|
||
e.href = e.href+path;
|
||
$(e).removeClass()
|
||
});
|
||
});
|
||
|
||
})
|
||
var userName = getCookie('docker_sso_username');
|
||
if (userName) {
|
||
$('.topmostnav_loggedout').hide();
|
||
$('.topmostnav_loggedin').show();
|
||
$('#logged-in-header-username').text(userName);
|
||
} else {
|
||
$('.topmostnav_loggedout').show();
|
||
$('.topmostnav_loggedin').hide();
|
||
}
|
||
</script>
|
||
</body>
|
||
</html> |