docker使用大全

1.docker的安装和配置

1.linux下:
	1. sudo apt-get install -y curl
	2.curl -sSL https://get.docker.com/ubuntu/ | sudo sh

2.windows下
	**https://www.cnblogs.com/bjfuouyang/p/3798198.html
	https://docs.docker.com/v17.09/docker-for-windows/install/#download-docker-for-windows**
3.将docker添加进用户组
	sudogroupadd docker
	sudo gpasswd -a ${USER} docker
	sudo service docker restart	
4.Docker 修改国内镜像地址
	curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://86d2a50b.m.daocloud.io

在配置完成后,请根据终端中的提示重启 docker,以使配置生效。

2.容器的基本操作

1.首次从镜像启动容器	
	dockre run -p 80  --name image -i -t IAMGE /bin/bash
		-P --publish-all=true|false 默认为false  映射所有端口
		-p --publish=[]    映射指定端口
		-p 80    
		-p 8080:80
		-p 0.0.0.0:80
		-p 0.0.0.0:8080:80
		--name  设置容器名称
		-i --interactive=true |false 默认是false  守护进程
		-t --tty-true | false 默认是false   创建shell界面
		IMAGE 镜像名称
		/bin/bash 启动容器后自动执行的第一条命令,创建shell界面

2.退出交互式容器容器
	ctrl+p+q
	
3.重新进入交互式容器
	docker attach container id | image
	
4.查看所有容器
	docker ps -a -l
		-a 列出所有的容器
		-l 列出最新创建的容器	
		
5.查看某个容器的详细信息
	docker inspect image
	
5.停止守护式容器
	docker stop 容器名  等待
	docker kill 容器名     直接停止
	
6.重新启动已经停止的容器
	docker start -i 容器名

7.删除停止的容器
	docker rm 容器名
	
8.查看容器日志
	docker logs -f -t --tail 容器名
		-f  --follows=true | false默认为false    一直跟踪日志的变化并返回结果
		-t --timestamps=true |false 默认为false  返回的结果上加上时间戳
		--tail="all"   返回结尾处多少数量的日志

9.查看容器内进程
	docker top 容器名

10.在运行的容器内启动新的进程
	docker exec -d -i -t IMAGE [ COMMAND] [ARG...] 
		docker exec web nginx

2.镜像的基本操作

1.搜索镜像
	docker search [options] term
		--automated=false onlgy shwo automated builds
		--no-trunc=false don't tuncate output
		-s, --stars=0 only displays with at least x stars
		
2.拉取镜像
	docker pull [options] name [:tag]
	-a, --all-tags=false download all tagged iamges in the repository

3.推送镜像
	docker push name[:tag]

4.使用commit构建镜像
	docker commit [options] container_id  [repository[:tag]
		-a, --author=""  指定作者信息
		-m, --message="" commit message    指定提交信息
		-p, --pause=true  pause container during commit  构建镜像时是否打断运行
		container_id 要生成镜像的容器id
		respository:tag  自定义生成后的镜像名称以及tag
		例子:docker commit -a "fei" -m "test" bfa0a6d644f4 fei/ubuntu16.04-python3.6.1-django1.11:v1.0
		
5.导出镜像
	docker save –o images_name.tar image:latest
		images_name.tar  导出后的文件名
		image:latest   要导出的镜像名和tag
		-o  输出到文件
		
6.载入镜像
	docker load —input testimage.tar
	--input 从tar归档文件读取镜像,而不是标准输入流
	或者
	docker load < testimage.tar
	
7.删除镜像
	docker rmi [options] image
		-f, --force=false
		--no-prune=false
		
8.查看镜像
		docker inspect [options] container|image
			-f ,--format = ""

猜你喜欢

转载自blog.csdn.net/qq_43192730/article/details/89195951