环境centos7.2 docker安装内核版本必须在3.10及其以上
uname -r 查看内核版本
首先去docker官网download
docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm
docker-ce-selinux-17.03.0.ce-1.el7.centos.noarch.rpm
安装docker
yum install --setopt=obsoletes=0 docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm
启动docker
systemctl start docker
查看docker版本信息
docker version
到这里docker就安装好了
如果对docker命令有什么问题可以直接输入命令 docker查看
Management Commands: ##管理命令
container Manage containers
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
volume Manage volumes
Commands: ##命令
attach Attach to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
对命令的参数有什么问题可以直接 docker + 命令 + --help查看
接下来开始使用docker,使用docker之前我们应该拉取镜像,可是从国外的官网拉取镜像的话,速度比较慢,所以我们从国内的官网镜像平台阿里拉取
https://account.aliyun.com/login/login.htm?oauth_callback=https%3A%2F%2Fcr.console.aliyun.com%2F#/accelerator
阿里容器服务网址
进去之后创建账号登录
找到你的专属链接,然后在/etc/docker目录下面创建daemon.json文件,按照图片中的方式操作
接下来我们平滑启动daemon服务和docker服务
systemctl daemon-reload
systemctl restart docker
docker的一些常用命令总结:
docker images ##查看镜像
docker ps -a ##查看全部容器
docker ps ##查看运行的容器
docker stop 容器ID ##停止一个或者多个正在运行的容器
docker kill 容器ID ##杀掉一个正在运行的容器
docker rm 镜像ID ##删除一个镜像
docker rmi 容器ID ##删除一个容器 加 -f参数 强制删除
docker pull 镜像名 ##拉取镜像
docker push 镜像名 ##上传镜像
docker attach 容器ID ##连接容器
docker commit 容器ID 容器名 ##本地提交一个镜像
docker inspect 容器ID ##查看容器信息
docker search 镜像名 ##在镜像库里面查找镜像
现在开始拉取镜像,首先我拉取centos镜像制作sshd-centos镜像,包装sshd服务
docker pull centos
docker run -it --name=cenots-ssh centos /bin/bash 用镜像创建一个容器启动 -it进入交互模式 -d 后台运行 --name 容器名 以/bin/bash/运行
进入容器交互模式之后:
yum -y updateyum install -y openssh-server