docker 入门 https://labs.play-with-docker.com 4小时免费
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 $ docker exec -it 容器id bash $ docker rm -f 容器id $ docker commit 容器id 镜像名称:版本号 $ docker commit -a "author" -m "my xxx" 9sfsuiy734jd mynginx:v1 $ docker push mynginx:v1 $ dockers images $ docker tag user1/xxx:tag user2/xxx:tag $ docker push user2/xxx:tag $ nano Dockerfile $ docker build -t 镜像名称:版本号 . $ docker build github.com/creack/docker-firefox $ docker save 镜像名称 >1.tar $ docker rmi 镜像名称 $ docker load 1.tar
docker 安装 国外 docker 安装 https://docs.docker.com/install/linux/docker-ce/centos/
1 2 3 curl -ssL https://get.docker.com/ | sh systemctl enable docker systemctl start docker
docker-compose 安装 https://docs.docker.com/compose/install/#install-compose
1 2 sudo curl -L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s) -$(uname -m) " -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose
1 2 3 4 docker-compose --version docker-compose up -d docker-compose stop docker-compose down
国内 docker 安装 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine sudo yum install -y yum-utils device-mapper-persistent-data lvm2 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo sudo yum install -y docker-ce docker-ce-cli containerd.io sudo systemctl enable docker sudo systemctl start docker sudo groupadd docker sudo usermod -aG docker ${USER} logout mkdir -p /etc/dockertee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors" :[ "http://hub-mirror.c.163.com" ], "dns" :[ "114.114.114.114" , "8.8.8.8" ] } EOF sudo pkill -SIGHUP dockerd sudo systemctl daemon-reload sudo systemctl restart docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors" : [ "https://3laho3y3.mirror.aliyuncs.com" , "https://hub-mirror.c.163.com" , "https://docker.mirrors.ustc.edu.cn" , "http://f1361db2.m.daocloud.io" , "https://registry.docker-cn.com" , "https://dockerhub.azk8s.cn" ] } EOF docker run -it --rm =true --name=test alpine:3.10 ash sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/alpine/g' /etc/apk/repositories npm config set registry https://registry.npm.taobao.org/ composer config -g repo.packagist composer https://packagist.phpcomposer.com pip install -i https://mirrors.aliyun.com/pypi/simple --upgrade pip docker-compose pip install -i https://pypi.doubanio.com/simple/ --upgrade pip docker-compose curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo cat <<EOF > /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/ enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF yum install -y kubelet kubeadm kubectl systemctl enable kubelet && systemctl start kubelet
docker-compose 安装 1 2 3 sudo yum install -y epel-release sudo yum install -y python-pip pip install -i https://pypi.doubanio.com/simple/ --upgrade pip docker-compose
常规命令语法 删除 exited 容器 1 docker rm $(docker ps -a | grep "Exited" | awk '{print $1 }' )
删除 none 镜像 1 docker rmi $(docker images | grep "none" | awk '{print $3}' )
进入容器 1 2 docker exec -it "容器name" bash docker exec -it "容器id" sh
其它命令 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 $ docker-compose up -d nginx $ docker-compose exec nginx bash $ docker-compose down $ docker-compose ps $ docker-compose restart nginx $ docker-compose run --no-deps --rm php-fpm php -v $ docker-compose build nginx $ docker-compose build --no-cache nginx $ docker-compose logs nginx $ docker-compose logs -f nginx $ docker-compose config -q $ docker-compose events --json nginx $ docker-compose pause nginx $ docker-compose unpause nginx $ docker-compose rm nginx $ docker-compose stop nginx $ docker-compose start nginx