docker学习1
安装docker
yum安装docker
修改docker的yum源:
删除已安装的Docker:
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
配置阿里云Docker Yum源
# Set up repository
yum install -y yum-utils device-mapper-persistent-data lvm2
# Use Aliyun Docker
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
查看docker可安装的版本
安装较旧版本(比如Docker 17.03.2) 时需要指定完整的rpm包的包名,并且加上--setopt=obsoletes=0 参数:
# Install docker
# on a new system with yum repo defined, forcing older version and ignoring obsoletes introduced by 17.06.0
yum install -y --setopt=obsoletes=0 \
docker-ce-17.03.2.ce-1.el7.centos.x86_64 \
docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch
或安装Docker较新版本(比如Docker 18.03.0)时加上rpm包名的版本号部分:
sudo yum install docker-ce-18.03.0.ce
或安装Docker最新版本,无需加版本号:
sudo yum install docker-ce
--------------
二进制安装docker
启动Docker服务
# Start docker service
systemctl enable docker
systemctl start docker
测试docker
# test docker
docker run hello-world
# check docker
docker ps -a
# check docker info
docker info
docker version
create a 'nginx' Docker
docker run -it nginx # -t让docker分配一个伪终端并绑定到容器的标准输入上, -i则让容器的标准输入保持打开.
查看docker的信息:
docker inspect f942aba4eee7
查看docker的网络
docker inspect f942aba4eee7|grep IPAddress
访问docker
curl 172.17.0.2
进入docker
docker exec -it <Docker-id/Docker-name> bash # docker exec :在运行的容器中执行命令