Docker common commands

1.container Lifecycle Management Command

run

# -- name='NAME' container name Container runs to know its name.
# -d running in background mode.
# -it runs interactively and goes to the container to view the content.
# -p specifies the port of the container-p 8080. Of course, there are also the following types.
# -p ip: host port: container port (commonly used).
# -p host port: container port (commonly used).
# -p container port

docker run -p port nubmer:port number -d mirror iamge
docker run -p 8080:8080 -d helloworld

update

#Containers run through docker run will not be restarted when the server is restarted

#How to make the docker container start and run automatically after the server is restarted?

docker update container id --restart=always

#More update help

docker update --help

restartedstart/stop/restart

docker start id #start container
docker restart id #restart container
docker stop id #stop container
exit #Container stops and exits
Ctrl+P+Q #The container does not stop,exit the container

kill

docker kill id #Force to stop the current container

rm

docker rm -f id  #delete a container 
docker rm -f $(docker ps -qa) #delete all containers

create
exec

#Docker exec: start a new terminal after entering the container, which you can operate in (commonly used)

docker exec -it id /bin/bash   #Enter the currently running container

 #Docker attach: entering the terminal where the container is executing will not start a new process

docker attach id #Enter the container

pause/unpause

2.container operation command

ps

# -a list of containers that are currently running and containers that have been run in the past.
# -n=? Show recently created containers.
# -q displays only the container number

docker ps  #View running containers

# view all containers

docker ps -a

inspect

docker inspect id #view container metadata

top

docker top id #View container process information

events
logs

-f display all logs.
-t with a timestamp.
-- tail n followed by the number n shows the current n logs

docker logs [Parameters] id

export
port

3.image warehouse command

login/logout

#log in to the docker container server

docker login --username=hi313*****@aliyun.com registry.cn-hangzhou.aliyuncs.com

push

#Push an image to the docker container server

docker push registry.cn-hangzhou.aliyuncs.com/gosrc/godemo:v1

pull

#Pull an image from the docker repository

docker pull registry.cn-hangzhou.aliyuncs.com/gosrc/godemo:v1

search

docker search helloworld

4.local image management command

images

#view mirror 

docker images -a

rmi

#delete a mirror image

docker rmi -f id

tag

#give the image a tag  

docker tag hello:v1 registry.cn-hangzhou.aliyuncs.com/gosrc/godemo:v1

build

#build a mirror image

docker build -t image name:version number Mirror storage directory
docker build -t hello:v1 .

cp

docker cp id:In-container path destination path #Copy the file from the container to the host
docker cp d1077234a:/root/hello.go /root

history
save
load
import

5.basic version information

info

docker info

version

docker -v

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值