First Docker notes (iii) Getting started with Docker

Source: Internet
Author: User
Tags custom name docker ps docker cp

Third, Getting Started with Docker (the following operating environment is on the Cetos6.364bit system)

1. Create a container

#docker run-i-T Ubuntu/bin/bash

The-I flag guarantees that the STDIN in the container is open, although we are not attached to the container,the-t Flag tells Docker to assign a pseudo-TTY terminal to the container to be created .

Appendix: The following issues are encountered when executing this instruction:

FATA[0000] Gethttp:///var/run/docker.sock/v1.17/images/search?term=ubuntu:dial Unix/var/run/docker.sock:no such File or directory. is trying to connect to atls-enabled daemon without TLS?

cause:Docker service does not start: Servicedocker start set boot:chkconfigdocker on

FATA[0000] Cannot connect tothe Docker daemon. Is ' docker-d ' running on this host?

Cause:The docker-d process did not start

try to solve: docker-d &

Error :

====================================================================

INFO[0000] +jobserveapi (unix:///var/run/docker.sock)

INFO[0000] warning:you arerunning Linux kernel version 2.6.32-431.11.7.el6.ucloud.x86_64, which might beunstable running Docker. Upgrade your kernel to 3.8.0.

Docker:relocation error:docker:symbol Dm_task_get_info_with_deferred_remove, version Base not Definedin file libdevmapper.so.1.02 with link Time reference

[1]+ Exit 127 docker-d

====================================================================

workaround : Install the necessary plugins Yumupgrade device-mapper-libs

Execute command :d ocker-d&

Continue # dockerrun-i-T Ubuntu/bin/bash it means creating a container based on an Ubuntu image and using an interactive shell environment. the Docker run command first scans the local host mirror and, if not found, establishes a connection to the Docker repository and downloads the corresponding image.

2. Common commands:

View Image

# Docker Search Ubuntu # searching for images

# Docker pull Ubuntu # Download Image

# Docker Images # View local Mirror Resources

# docker Images-a : List all images(including history)

# Docker Images--tree : Show all layers of mirroring (layer)

# Docker RMI <image id>: Delete one or more image

View Container

# docker PS : List all currently running container

# docker Ps-l : List The most recently launched container

# docker Ps-a : List all container(including history, running container)

# docker Ps-q : List The last run of Containerid

actions for the container:

# docker start/stop/restart<container> : Open / stop / restart container

# docker start[container_id] : Run a container again (including historical container)

# docker attach[container_id] : Connect a running container instance (that is, the instance must be the start state, multiple windows can attach a container instance) is actually going into the container

# docker start-i<container> : Start a container and enter interactive mode (equivalent to start first, in attach)

# docker Run-i-t<image>/bin/bash : Use image to create container and enter interactive mode , login Shell is /bin/bash

# docker Run-i-t-p: Map The host port to the container to facilitate external access to the container service,Host_port can be omitted, Omitting means mapping container_port to a dynamic port.

Note: Using start is a startup that has been created container, using Run to open a new container with the image .

Delete Container

# docker RM <container...> : Delete one or more container

# docker RM ' Docker ps-a-Q ': Remove all container

# docker Ps-a-Q | Xargsdocker rm : Ibid ., Delete all container

3. The container is created with a custom command operation:

# Docker run--name custom name -i-t <images>/bin/bash

where the custom name contains the following characters: lowercase letters A-Z,uppercase letters A-Z, numeric 0-9, underscores, dots, dashes. The name of the container must be unique

4. re-enter the restart

# Dockerattach container name

if the shell of the container is introduced , the container will also stop running

5. Create a daemon container

# Docker Run--name <name>-dubuntu/bin/sh-c "while True;do echo Hello world;sleep 1;done"

Create a daemon container (using the-D parameter to make the container run in the background) execute a command (-c)

Instance operation: (Reference : http://segmentfault.com/a/1190000000755980)

Experiment with the official nginx Image:

# Docker Pull Nginx

generate a test page that is stored in a directory ( e.g. /opt/nginx/)

# echo "

Create a container based on the nginx image, and use -V to assign the default file in the container to the custom site directory on the host, port mapping: 8000 à container of 80 of the host machine Port -D parameter causes the container to run in the background

# Docker Run--name nginx1.9.0-v/opt/nginx/:/usr/share/nginx/html:ro-p 8000:80-d nginx:1.9.0

Copy files from the Docker container to the host ( but not vice versa )

# docker CP nginx1.9.0:/etc/nginx/nginx.conf/opt/nginx/

6. View the logs, processes inside the container

# Docker Logs nginx1.9.0

# docker logs-f nginx1.9.0 à equivalent to Tail-f

# Docker logs--tail nginx1.9.0 view last line

# Docker logs--tail 0 nginx1.9.0 View the latest log information

# Docker Top nginx1.9.0

7. run the specified process in the container

# docker exec-d nginx1.9.0 touch/opt/nginx/test.txt Create an empty file inside the container

# docker EXEC-T-I nginx1.9.0/bin/bash start an interactive shell task in a container

8. Stop the daemon container

# Docker Stop nginx1.9.0 ( or container ID)

9. set up the container to run automatically to prevent certain errors from causing the container to stop affecting the business

# Docker Run--restart=always--namenginx1.9.0-d nginx:1.9.0/bin/bash-c XX

the--RESTART flag can be set to

Always: Docker automatically restarts the container regardless of the container's exit code

On-failure: automatically restarts only if the container's exit code is not 0

# Docker Run--restart=on-failure:5--name nginx1.9.0-d nginx:1.9.0/bin/bash-c XX

Docker automatically restarts 5 times when the container exit code is not 0

Learn more about containers

# Docker Inspect nginx1.9.0

You can view some details about the container, including open ports, installation paths, configuration files, system configuration, etc.

# Docker Inspect--format ' {{. State.running}} ' nginx1.9.0

True

to view the running status of a container

# Docker Inspect--format ' {{. Networksettings.ipaddress}} ' nginx1.9.0

View the container's IP Address

# Docker Inspect-f ' {. Name}} {{. State.running}} ' nginx1.9.0 ubuntu14.04

/nginx1.9.0 true

/ubuntu14.04 true

View the names and operations of multiple containers

One by one. Delete all containers

# docker RM ' Docker ps-a-Q '


This article is from "Dolphin Watching" blog, please be sure to keep this source http://swht1278.blog.51cto.com/7138082/1643570

First Docker notes (iii) Getting started with Docker

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.