Docker 常用命令

docker run -p 80:80 nginx

input docker will get the command in the console

sage: docker [OPTIONS] COMMAND

A self-sufficient runtime for containers


Management Commands:
app* Docker Application (Docker Inc., v0.8.0)
builder Manage builds
buildx* Build with BuildKit (Docker Inc., v0.3.1-tp-docker)
config Manage Docker configs
container Manage containers
context Manage contexts
image Manage images
manifest Manage Docker image manifests and manifest lists
mutagen* Synchronize files with Docker Desktop (Docker Inc., testing)
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes

Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes

 

Docker帮助命令:

docker info

 

镜像命令:

dokcer images

dokcer imges -a 

 

 

docker rmi -f

docker rmi -f $(docker images -qa)

 

Docker 容器命令:

docker pull centos

 

Docker files:

************************************************

docker ps -a  显示所有的容器,包括未运行的。

 

 

 

docker stop 6efab790f83e  停止一个运行中的容器

docker kill :杀掉一个运行中的容器。
 cd /var/btn/deploy
 ./deploy_docker.sh var-api 20001

cat deploy_docker.sh

startTime=`date +%s`
echo "$1开始部署"
#基础参数
dockername=$1
imagename="dockerdev.gwmfc.com/btn/btn-btfp/$dockername"
version="latest"
imagefullname="$imagename:$version"
port=$2

#筛选出容器id
cid=$(docker ps | grep $dockername| awk '{print $1}')
#如果镜像启动,id存在,关闭并删除容器和镜像
echo "【第一步:关闭并删除容器和镜像】"
if [ x"$cid" != x ];then
docker kill $cid
docker rm $cid
docker rmi $(docker images | grep $imagename| awk '{print $3}')
fi

#如果镜像未启动,d不存在,根据容器id删除,最后查找镜像并删除
if [ x"$cid" = x ];then
cid=$(docker ps -a | grep $dockername| awk '{print $1}')
if [ x"$cid" != x ];then
echo $cid
docker rm $cid
fi
docker rmi $(docker images | grep $imagename| awk '{print $3}')
fi

#拉取镜像
echo "【第二步:拉取镜像】"
docker pull $imagefullname

#等待10秒
#sleep 10

#启动镜像
echo "【第三步:启动容器】"
docker run -d --rm -p $port:$port -v /var/btn/logs:/logs -v /opt:/opt --name $dockername --net=host $imagefullname
endTime=`date +%s`
sumTime=$(( $endTime - $startTime ))
echo "部署成功,总耗时 $sumTime 秒"

**********************************************************************

 

posted @ 2023-04-04 08:41  tzmok  阅读(17)  评论(0编辑  收藏  举报