Common docker commands

Source: Internet
Author: User
Tags docker hub
Common docker command Directories
  • Search for images
  • Get container Image
  • Create an instance
  • View the container list
  • Create an image
  • Remove one or more container instances
  • Delete an image
Search for images

Search for images from docker hub.
Comand:

$ sudo docker search TERM

Options:

-- Automatically = false: whether to show only automatically created images -- no-trunc = false whether to cut the output-S, -- stars = 0 only show images with at least X stars

Example:

$ sudo docker search centos

Get container Image

Download the image from docker hub.
Comand:

$ sudo docker pull NAME[:TAG]

Example:

$ sudo docker pull centos:latest

Create an instance

Command:

$ sudo docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Options:
-A, -- attach = []Attach to stdin, stdout or stderr.
Associated with standard input, standard output, or standard error output
-C, -- CPU-shares = 0CPU quota (relative weight)
-- Cpuset = ""CPU (0-3)
-M, -- Memory = "" memory quota (Format: <number> <unit> unit = B, K, M, or G)
-- Cidfile = "" write the container instance id to a file
-D, -- detach = false: run the container in the background and output the container ID.
-- DNS = [] custom DNS Server
-- DNS-search custom DNS search domain
-E, -- Env = [] Set Environment Variables
-- Env-file = [] reading environment variables from a file
-- Entrypoint = ""Overwrite the default image entry point
-- Expose = []Expose a port of the container instead of making it public through the host
-H, -- hostname = "" container Host Name
-I, -- Interactive = false keep the standard input open even if there is no association
-- Link connection (Name: alias)
-- Lxc-Conf(Available in the lxc driver) add custom lxc options
-- Lxc-conf = "lxc. cgroup. cpuset. CPUs = 0, 1"

-- Name = "" set a name for the container
-- Net = "bridge" sets the container Network Mode
'Bridge ': Create a new network stack on the docker bridge Nic
'None': No network connection is set.
'Container: <name | ID> ': Reuse the network stack of another container
'Host': use the network stack of the host in the container.
Note: The Host Mode gives full access to the services of the local container system.
(Such as D-Bus), because it is considered unsafe.

-P, -- publish-All = false open all opened ports to the host Nic
-P, -- publish = [] Open a port of the container to the host
Format:IP: host port: Container Port
OrIP: Container Port
OrHost port: Container Port
Run the 'docker port' command to view the actual port ing.
-- Privileged = false: grant the extension permission to the container.
-- Rm = false: automatically remove the container when it exits (-DParameter conflict)
-- Sig-proxy = true proxify signals to the process (even in non-tty
Mode). sigchld is not proxied.
-T, -- tty = false: allocate a Pseudo Terminal.
-U, -- user = "" User Name or uid
-V, -- Volume = [] mount the volume to the specified directory (for example, mount from the host:-V/Host:/Container
Slave container:-V/container)
-- Volumes-from = [] mounting volumes from a specific container
-W, -- workdir = "" working directory in the container

Create a container and open a shell
$ sudo docker run -t -i centos:latest /bin/bash

View the container list

Command:

$ sudo docker ps [OPTIONS]

Option:
-A, -- all = false show all containers. By default, only running containers are displayed.
-- Before = "" Only displays the container before a container is created, including the container that is not running.
-L, -- latest = false: only the last created container is displayed, including the non-running container.
-N =-1: displays the last n created containers, including non-running containers.
-- No-trunc = false: the output is not truncated.
-Q, -- Quiet = false: only the container value ID is displayed.
-S, -- size = false display size
-- Since = "" Only displays containers after a container is created, including containers that are not running.

Create an image from a changed container instance

Command:
$ sudo docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
Option:
-A, -- author = "" author (for example, "<cimoing & gmail.com> ")
-M, -- message = "" submit comments
-P, -- Pause = true: Tentative container when submitting

Use DockfileCreate an image

Command:
$ sudo docker build [OPTIONS] PATH | URL | -
You need to create a dockerfile. For details, see dockerfile.
Option:-- Force-Rm = false: the media container is forcibly deleted, even if the image creation fails.
-- No-Cache = false: no cache is used when a container is built.
-Q, -- Quiet = false: Detailed output is not displayed when a file is created.
-- Rm = true: when the image is created successfully, the media container is deleted.
-T, -- tag = "" when the image is created successfully, set the resource library name (and an optional tag)

Remove one or more container instances

Command:
$ sudo docker rm [OPTIONS] CONTAINER [CONTAINER...]

Remove all running containers:
$ sudo docker rm sudo docker ps -aq

Delete an image

Command:
$ sudo docker rmi IMAGE [IMAGE...]

Delete an image:
$ sudo docker rmi centos:latest

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.