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可安装的版本

# yum list docker-ce  --showduplicates | sort -r
# yum -y install docker-ce-18.09.6
# systemctl start docker.service
# systemctl enable docker.service 


安装较旧版本(比如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
下载二进制包
tar -xvf docker-18.09.6.tgz
 
Or
 
将主程序放到/usr/bin目录下
cp ./docker/* /usr/bin/
 
创建systemd文件
cat > docker.service <<"EOF"
[[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.io
 
[Service]
#WorkingDirectory=/var/lib/docker
Environment="PATH=/bin:/sbin:/usr/bin:/usr/sbin"
#EnvironmentFile=-/run/flannel/docker
ExecStart=/usr/bin/dockerd $DOCKER_NETWORK_OPTIONS
ExecReload=/bin/kill -s HUP $MAINPID
Restart=on-failure
RestartSec=5
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Delegate=yes
KillMode=process
 
[Install]
WantedBy=multi-user.target
EOF
 
 
mv docker.service /usr/lib/systemd/system/docker.service
 
 
/sbin/iptables -P FORWARD ACCEPT
 
cat > /etc/docker/docker-daemon.json <<EOF
{
    "insecure-registries": ["docker02:35000"],
    "max-concurrent-downloads": 20,
    "live-restore": true,
    "max-concurrent-uploads": 10,
    "debug": true,
    "data-root": "/var/lib/docker/data",
    "exec-root": "/var/lib/docker/exec",
    "log-opts": {
      "max-size": "100m",
      "max-file": "5"
    }
}
EOF 

 

启动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 :在运行的容器中执行命令

posted @ 2019-11-24 09:26  hlc-123  阅读(137)  评论(0编辑  收藏  举报