【Docker】docker常用指令

网友投稿 257 2022-10-20

【Docker】docker常用指令

开启docker,并设置开机自启动

老式写法:

service docker startchkconfig docker on

新式写法:

systemctl start docker.servicesystemctl enable docker.service

Build an image from a Dockerfile

docker build -t friendlyhello .

tag一个image,并push

语法:

docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]docker push username/repository:tag

示例:

[root@localhost ~]# docker login //登录[root@localhost ~]# docker tag friendlyhello ssslinppp/get-started:part1 //tag[root@localhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEfriendlyhello latest 0a60bcfe3e8d 28 minutes ago 194MBssslinppp/get-started part1 0a60bcfe3e8d 28 minutes ago 194MBpython 2.7-slim d962f7a9f2f1 2 weeks ago 182MBhello-world latest 1815c82652c0 3 weeks ago 1.84kB[root@localhost ~]# docker push ssslinppp/get-started:part1 //上传[root@localhost ~]# docker run -p 4000:80 ssslinppp/get-started:part1 //运行测试 * Running on (Press CTRL+C to quit)

容器相关操作

在容器内运行进程

# 后台执行docker exec -d containerID CMDdocker exec -d containerID touch /etc/new_config_file # 示例# 交互式执行docker exec -t -i containerID /bin/bash

查看容器内进程

docker top containerID

查看容器详细信息

docker inspect containerID

查看容器的端口映射情况

docker port containerID

镜像相关操作

查看镜像是如何被构建出来

docker history imageID

官方提供的常用命令

docker build -t friendlyname . # Create image using this directory's Dockerfiledocker run -p 4000:80 friendlyname # Run "friendlyname" mapping port 4000 to 80docker run -d -p 4000:80 friendlyname # Same thing, but in detached modedocker ps # See a list of all running containersdocker stop # Gracefully stop the specified containerdocker ps -a # See a list of all containers, even the ones not runningdocker kill # Force shutdown of the specified containerdocker rm # Remove the specified container from this machinedocker rm $(docker ps -a -q) # Remove all containers from this machinedocker images -a # Show all images on this machinedocker rmi # Remove the specified image from this machinedocker rmi $(docker images -q) # Remove all images from this machinedocker login # Log in this CLI session using your Docker credentialsdocker tag username/repository:tag # Tag for upload to registrydocker push username/repository:tag # Upload tagged image to registrydocker run username/repository:tag # Run image from a registry

docker stack ls # List all running applications on this Docker hostdocker stack deploy -c # Run the specified Compose filedocker stack services # List the services associated with an appdocker stack ps # List the running containers associated with an appdocker stack rm # Tear down an application

docker-machine create --driver virtualbox myvm1 # Create a VM (Mac, Win7, Linux)docker-machine create -d hyperv --hyperv-virtual-switch "myswitch" myvm1 # Win10docker-machine env myvm1 # View basic information about your nodedocker-machine ssh myvm1 "docker node ls" # List the nodes in your swarmdocker-machine ssh myvm1 "docker node inspect " # Inspect a nodedocker-machine ssh myvm1 "docker swarm join-token -q worker" # View join tokendocker-machine ssh myvm1 # Open an SSH session with the VM; type "exit" to enddocker-machine ssh myvm2 "docker swarm leave" # Make the worker leave the swarmdocker-machine ssh myvm1 "docker swarm leave -f" # Make master leave, kill swarmdocker-machine start myvm1 # Start a VM that is currently not runningdocker-machine stop $(docker-machine ls -q) # Stop all running VMsdocker-machine rm $(docker-machine ls -q) # Delete all VMs and their disk imagesdocker-machine scp docker-compose.yml myvm1:~ # Copy file to node's home dirdocker-machine ssh myvm1 "docker stack deploy -c " # Deploy an app

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Redis-dump Docker搭建的快速指南
下一篇:java理论基础Stream reduce实现集合元素归约
相关文章

 发表评论

暂时没有评论,来抢沙发吧~