docker基本操作
Posted 畑鹿驚
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker基本操作相关的知识,希望对你有一定的参考价值。
安装
$ sudo yum remove docker \ # 移除旧版本
docker-common docker-selinux docker-engine
$ curl -sSL https://get.daocloud.io/docker | sh # 超时
$ sudo yum -y install docker-io
$ sudo chkconfig docker on
$ sudo docker version
Client:
Version: 1.12.6
API version: 1.24
Package version: docker-1.12.6-61.git85d7426.el7.centos.x86_64
Go version: go1.8.3
Git commit: 85d7426/1.12.6
Built: Tue Oct 24 15:40:21 2017
OS/Arch: linux/amd64
Server:
Version: 1.12.6
API version: 1.24
Package version: docker-1.12.6-61.git85d7426.el7.centos.x86_64
Go version: go1.8.3
Git commit: 85d7426/1.12.6
Built: Tue Oct 24 15:40:21 2017
OS/Arch: linux/amd64
docker加速器
https://cr.console.aliyun.com/?spm=5176.1972343.0.2.739d6968UdvRn2#/accelerator
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-‘EOF‘
{
"registry-mirrors": ["https://xxx"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
使用
docker pull hello-world # 下载
docker images # 查看
docker rmi image-id #删除
docker run --name container-name -d image-name # 运行镜像为容器
docker ps # 容器列表
docker start/stop container-name/container-id
docker logs container-name/container-id # 查看容器日志
docker rm container-id
docker pull redis # 获取redis镜像
docker run -d -p 6378:6379 --name port-redis redis # daemon方式运行,并且映射容器的6379端口到本机的6378端口
push自己的镜像
$ sudo docker login [email protected] registry.cn-hangzhou.aliyuncs.com
# 默认为版本号为latest
$ sudo docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/lawlietfans/my-oracle-xe-11g:[镜像版本号]
$ sudo docker push registry.cn-hangzhou.aliyuncs.com/lawlietfans/my-oracle-xe-11g:[镜像版本号]
$ sudo docker tag f794779ccdb9 registry.cn-hangzhou.aliyuncs.com/lawlietfans/my-oracle-xe-11g:v20171130
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
wnameless/oracle-xe-11g latest f794779ccdb9 7 weeks ago 2.23GB
registry.cn-hangzhou.aliyuncs.com/lawlietfans/my-oracle-xe-11g v20171130 f794779ccdb9 7 weeks ago 2.23GB
$ sudo docker push registry.cn-hangzhou.aliyuncs.com/lawlietfans/my-oracle-xe-11g:v20171130
done
另一个例子:
References
以上是关于docker基本操作的主要内容,如果未能解决你的问题,请参考以下文章