查看
docker info
docker stats
docker version
docker search tutorial
docker ps
docker ps -a
docker ps -all
docker ps -l
docker inspect 44fc0f0582d9
docker inspect -f {{.State.Pid}} 44fc0f0582d9
docker inspect --format='{{.NetworkSettings.IPAddress}}' mycentos3
镜像
docker images
docker images rmi
docker build -t holiday:v1 /usr/local/docker/holiday
docker tag kafka-monitor:v1 kubebiz/kafka-monitor:v1
docker push kubebiz/kafka-monitor:v1
docker pull kubebiz/kafka-monitor:v1
docker ps |grep holiday |awk '{print $1}' |xargs -i docker stop {}
docker commit 1a442630f4a9 test/javaweb:0.0
使用docker exec
进入Docker容器
docker ps
docker exec -it 775c7c9ee1e1 /bin/bash
日志
docker logs 2f2de065fd05
停止与删除
docker kill $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker rmi $(docker images -q -f dangling=true)
docker rmi $(docker images -q)
从容器中复制文件
docker cp 371f3ff1f43b:/usr/local/bin/etcdctl /usr/local/bin/etcdctl
别名
alias dockerkill='docker kill $(docker ps -a -q)'
alias dockercleanc='docker rm $(docker ps -a -q)'
alias dockercleani='docker rmi $(docker images -q -f dangling=true)'
alias dockerclean='dockercleanc || true && dockercleani'
运行
# 运行docker镜像
docker run -i -t -v /root/software/:/mnt/software/ --privileged=true index.alauda.cn/alauda/ubuntu /bin/bash
# 运行一个jenkins镜像的例子命令
sudo docker run \
-d -p 8088:8080 -p 50000:50000 \
-v /home/docker/jenkins_home/:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(which docker):/usr/bin/docker \
-v $(which git):/usr/bin/git \
-v ~/.ssh:/var/jenkins_home/.ssh \
--name=jenkins jenkinsci/jenkins
# 运行一个tomcat
docker run --name tomcat-demo -m 1G tomcat:9.0.39-jdk8-openjdk
一个完整的运行步骤
sudo docker run --name myjenkins -p 8088:8080 -p 50000:50000 -d docker.io/jenkinsci/jenkins
docker stop myjenkins
docker start myjenkins
docker ps -a 获取到ff2d09d0ddd8
docker commit ff2d09d0ddd8 test/jenkins:0.2
查看docker运行容器的ip
sudo docker run --name myjenkins -p 8088:8080 -p 50000:50000 -d docker.io/jenkinsci/jenkins
cat /etc/hosts
会显示自己以及(– link)软连接的容器IP
docker inspect --format '{{ .NetworkSettings.IPAddress }}' <container-ID>
或
docker inspect <container id>
或
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id
function docker_ip() {
sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' $1
}
source ~/.bashrc 然后:
$ docker_ip <container-ID>
172.11.0.6
docker inspect -f '{{.Name}} - {{.NetworkSettings.IPAddress }}' $(docker ps -aq)
如果使用docker-compose命令将是:
docker inspect -f '{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)
docker inspect --format='{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)