程序猿辉辉


Docker常用命令

辉辉 2018-06-01 87浏览 0条评论
首页/正文
分享到: / / / /

安装docker、docker-compose

#!/bin/bash
# 安装docker
if ! [ -x "$(command -v docker)" ]; then
  echo '检测到 Docker 尚未安装,正在试图安装 Docker ...'

  if [ -x "$(command -v yum)" ]; then
    sudo yum install -y python3-pip yum-utils device-mapper-persistent-data lvm2
    sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    yum list docker-ce --showduplicates | sort -r
    sudo yum install docker-ce
  else
    sudo apt-get update
    sudo dpkg --configure -a
    sudo apt-get install python3-pip apt-transport-https ca-certificates curl software-properties-common
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    sudo apt-get update
    sudo apt-get install docker-ce
  fi

  # 启动docker和开机自启动
  sudo systemctl start docker
  sudo systemctl enable docker
fi


 # 安装docker-compose
if ! [ -x "$(command -v docker-compose)" ]; then
  echo '检测到 Docker-Compose 尚未安装,正在试图安装 Docker-Compose ...'
  if ! [ -x "$(command -v pip3)" ]; then
      curl -L https://github.com/docker/compose/releases/download/1.25.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
      chmod +x /usr/local/bin/docker-compose
  else
      pip3 install --upgrade pip
      pip3 install docker-compose
  fi
fi

docker version
docker-compose -version

if ! [ -x "$(command -v docker)" ]; then
	echo 'Docker 安装失败,请检测您当前的环境(或网络)是否正常。'
fi

if ! [ -x "$(command -v docker-compose)" ]; then
	echo 'Docker-Compose 安装失败,请检测您当前的环境(或网络)是否正常。'
fi

rm -f install.sh

Docker常用启动命令

1.启动 :systemctl start docker

2.守护进程重启:sudo systemctl daemon-reload

3.重启docker服务:systemctl restart docker

4.重启docker服务:sudo service docker restart

5.关闭:docker service docker stop   

6.关闭:docker systemctl stop docker

Docker容器相关常用命令

1.查看本地镜像:docker images

2.删除本地镜像:docker rmi 本地镜像id

3.列出所有容器:docker ps -a

4.停止容器运行:docker stop 容器id

5.删除容器:docker rm 容器id

6.进入容器:docker exec -it 容器id bash

7.实时动态查看容器最后n行日志:docker logs -f -t --tail n 容器id

8.查看容器挂载路径:docker inspect --format {{.Config.Volumes}}" 容器id

Docker Compose常用命令

1.启动容器:docker-compose start

2.停止容器运行:docker-compose stop

3.重启容器:docker-compose restart

4.重新构建容器:docker-compose up -d --build
最后修改:2018-06-01 12:00:15 © 著作权归作者所有

评论列表

还没有人评论哦~赶快抢占沙发吧~