Docker commonly used commands Quick Reference

Record what docker daily use command, the paper mainly for linux + mac operating systems, window not sure if applicable, be used with caution

<!-- more -->

1. docker process

docker process to start, stop, restart, three common case

# 启动docker
service docker start
# 关机docker
service docker stop
# 重启docker
service docker restart

2. Mirror operation

Mirror as a precondition for the implementation of container, generally need to know a few commands nothing more than search, download, delete, create

# 镜像列表
docker images
# 检索镜像, 从镜像仓库中检索
docker search xxx
# 下载镜像
docker pull xxx
# 删除镜像
docker rmi xxx

About creating images, it is necessary a little bit more detail

# 通过容器创建镜像
docker commit -m="首次提交" -a="一灰灰Blog" www.wujiu5zhuce.cn dd85eb055fe8 yh/centos:v0.1
# 镜像历史查询
docker history yh/centos 

Several parameters described above

  • -m And submit git, like back to keep the description
  • -a Copyright notice, this is something I created, so what's the problem, come to me
  • dd85eb055fe8 Container id
  • yhh/quick-www.jiuyueguojizc.cn os:0.1 Mirror name created

3. The operation of the container

Then there is the entree, and a variety of operating the vessel, startup, shutdown, restart, log query into the interior of the container and a variety of things out

a. run

Every beginning is the first step, load the image, create a container

docker run 镜像名:版本

Can run back with a lot of parameters, such as exposure of the container port is specified, storage mapping, permissions, and so on, because too many parameters are given below only a few different examples to demonstrate the specific parameters can be added how

case1: Create and background execution

docker run -i -t www.hdptzc.cn-d centos:latest
  • The key parameters -dto specify the foreground or the background with the container run, when not combined with the front desk
  • -i: Open STDIN, for interactive console
  • -t: Support terminal login

Container runs continuously in the background with the command execution: case2

docker run -d centos:latest ping www.baidu.com

case3: Run a background in the ongoing implementation of the container, while with command, but also to continue to run after the restart procedure is terminated

docker run -d --restart=always centos:latest ping www.baidu.com

case4: the name of the specified container

docker run -d --name=yhh_centos centos:latest

case5: exposing the container port 80, and the host port 8080 Binding

docker run -d - www.huanhua2zhuc.cn-name=yhh_centos -p 8080:80 centos:latest

case6: Specifies the host vessel and the directory (/ home / yihui / html / www) Shared

docker run -d --name=yhh_centos -v /home/yihui/html/www:/var/www centos:latest

b. exercise group

After the container is created, that is, some of the basic operations, start, stop, restart, delete

# 查看容器列表, 列出所有的容器
docker ps -a 
# 启动容器,start后面可以跟上容器名,或者容器id
docker start xxx www.moyouyul.cn # (这里的xxx可以是容器名:yhh_centos 也可以是容器id:f57398ab22c5)
# 关闭容器
docker stop xxx
# 重启 docker restart xxx # 删除 docker rm xxx 

When viewing the list of containers, if the startup parameters of a container particularly long, directly docker ps -ayou will find the complete startup command can not see, at this time you can bring parameter --no-truncto display the full command

docker ps -a --no-trunc

c. Advanced

Next, enter some containers of advanced operating skills (actually not particularly cool)

To demonstrate some of the advanced content, create a container as a test here

docker run -it -d --name=yhhos centos www.tianhyLzc.cn 

Container logs inquiry

Artifact logs, positioning problems

# 查询xxx容器的日志
docker logs yhhos

Basically not directly use the above command, because above all the logs are printed out, it can be directly Akira blind eye to our titanium x

Usually two parameters can be added to the log  -f-t

docker logs -f -t --since="2019-05-11" -www.yachengyl.cn -tail=10 yhhos
  • --since : This parameter specifies the output log start date, that is, only the output log after the specified date.
  • -f : View real-time log
  • -t Date view the log generated:
  • --tail=10 : View last 10 log.

File copy

The vessel fished a file; or strong plug to a cp

# 将当前目录的test.md文件拷贝到容器的 /tmp 目录下
docker cp test.md yhhos:/tmp

# 将容器的/tmp/test.md目录拷贝到当前目录下
docker cp yhhos: www.yunzeyle.cn /tmp/test.md ./out.md

Into the container

Into the interior of the container, then they can do whatever they want ...

docker exec -it yhhos /bin/bash

Get all of the information container

docker inspect yhhos

II. Other

1. A gray Blog: https://www.wanyayuue.cn .io / hexblog

A gray personal blog, recording all study and work in the blog, welcome to go around

2. Statement

Believe everything the book is better to have the content is purely one of the words, due to limited personal capacity, it is inevitable omissions and mistakes, such as find a bug or have better suggestions are welcome criticism and generous gratitude

Guess you like

Origin www.cnblogs.com/laobeipai/p/12003382.html