Docker Common Commands

Source: Internet
Author: User
Tags docker ps docker cp docker run docker registry

Container-related operations
  • Docker Create # Creates a container but does not start it

  • Docker run # Creates and launches a container

  • Docker Stop # Stops the container from running and sends a signal sigterm

  • Docker start # Starts a container with a stopped state

  • Docker Restart # reboot a container

  • Docker RM # Delete a container

  • Docker kill # Sends a signal to the container, default Sigkill

  • Docker Attach # Connect (enter) to a running container

  • Docker wait # blocks to a container until the container stops running


Get container-related information
  • Docker PS # Displays a container with a status of run (UP)

  • Docker Ps-a # shows all containers, including in-run (up) and exited (Exited)

  • Docker inspect # Deep inside the container gets all the information about the container

  • Docker logs # View container's logs (Stdout/stderr)

  • Docker events # Get real-time event for Docker server

  • Docker Port # shows container's ports mapping

  • Docker Top # Displays process information for the container

  • Docker diff # shows changes before and after container file system

Export container
    • Docker CP # Copy files or directories out of the container

    • Docker Export # Exports the entire file system of the container as a tar package without layers, tag, etc.

Perform
    • Docker EXEC # Executes a command in the container that can execute bash into interactive

Mirroring operations
  • Docker Images # Displays a list of all local mirrors

  • Docker Import # Creates a mirror from a tar package and is often used in conjunction with export

  • Docker build # Create image with Dockerfile (recommended)

  • Docker Commit # Creates a mirror from a container

  • Docker RMI # Delete a mirror

  • Docker load # Creates a mirror from a tar package and uses it with Save

  • Docker Save # Saves an image as a tar package with layers and tag information

  • Docker History # Displays a historical command to generate an image

  • Docker Tag # an alias for mirroring

Mirror Warehouse (Registry) operations
    • Docker Login # Log in to a registry

    • Docker search # Searching for mirrors from registry warehouse

    • Docker Pull # Download image from warehouse to local

    • Docker push # Push a mirror to the registry repository

Get container IP address (container status must be up)
Docker Inspect ID | grep IPAddress | Cut-d ' "'-F 4
Get Port Mappings
Docker inspect-f ' {range $p, $conf: =. Networksettings.ports}} {{$p}} and {{(index $conf 0). Hostport}} {{end}} ' ID
Get Environment variables
Docker exec container_id Env
Kill all the containers that are running
Docker kill $ (Docker ps-q)
Delete old (created a week ago) container
Docker Ps-a | grep ' weeks ago ' | awk ' {print '} ' | Xargs Docker RM
To delete a container that has stopped
Docker RM ' Docker ps-a-Q '
Remove all mirrors, be careful
Docker RMI $ (Docker images-q)
Dockerfile

The Dockerfile is the foundation of the Docker build image and the important feature of Docker that distinguishes it from other containers, and it is dockerfile,docker automation and portability that makes it possible.

Whether it's development or operations, learning to write dockerfile is almost essential, which helps you understand the entire container's operation.

From, building a new image from a base image
From Ubuntu
Maintainer, maintainers ' information
Maintainer William <[email protected]>
ENV, setting environment variables
ENV TEST 1
Run, non-interactive running shell command
Run apt-get-y update run apt-get-y install Nginx
Add, copy the external file into the image, SRC can be a URL
ADD http://nicescale.com//data/nicescale.tgz
Workdir/path/to/workdir, setting the working directory
Workdir/var/www
User, setting the UserID
USER Nginx
Vulume < #dir;, setting volume
VOLUME ['/data ']
EXPOSE, which ports are exposed
EXPOSE 80 443
entrypoint [' executable ', ' param1 ', ' param2 '] execute commands
entrypoint ["/usr/sbin/nginx"]
CMD ["param1", "param2"]
CMD ["Start"]

The command executed when Docker creates and starts container, and if entrypoint is set, CMD will be the parameter

Dockerfile Best Practices
    • Try to put some of the usual unchanging instructions to the front

    • CMD and entrypoint use JSON arrays as much as possible

Build image with Dockerfile
Docker build csphere/nginx:1.7.
Mirrored Warehouse Registry

After mirroring is generated from the Dockerfile build, you need to push (push) the mirror to the mirrored warehouse. Within the enterprise, a private Docker registry needs to be built, and this registry can be seen as a binary scm,ci/cd that needs to be done around registry.

Deploying registry
Mkdir/registrydocker run-p 80:5000-e storage_path=/registry-v/registry:/registry registry:2.0
Save the push image to the warehouse

Suppose 192.168.1.2 is the address of the Registry warehouse:

Docker tag csphere/nginx:1.7 192.168.1.2/csphere/nginx:1.7docker push 192.168.1.2/csphere/nginx:1.7


This article is from the "Huangyi blog" blog, please be sure to keep this source http://linuxpython.blog.51cto.com/10015972/1682219

Docker Common Commands

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.