目录
一、docker安装步骤
Ⅰ、官方安装文档
Install Docker Engine | Docker Documentation
Ⅱ、具体安装步骤
1、卸载原来安装过的docker,如果没有安装可以不需要卸载
yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine
2、安装yum相关工具,下载docker-ce
yum install -y yum-utils yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo
3、安装docker引擎
yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
container engine容器引擎
docker是一个容器管理的软件
docker-ce是服务器端软件
serverdocker-ce-cli是客户端软件client
docker-compose-plugin是compose插件,用来批量后动很多容器,在单台机器上containerd.io底层用来后动容器的
4、启动docker服务
[root@shimm ~]# systemctl start docker
[root@shimm ~]# ps -ef|grep docker
root 9841 1 0 11:40 ? 00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root 9969 6331 0 11:40 pts/0 00:00:00 grep --color=auto docker
[root@shimm ~]#
5、设置开机自启:
[root@shimm ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@shimm ~]#
docker
docker进程与镜像 --docker ps/images
[root@shimm ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@shimm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@shimm ~]#
<!--images镜像--> <!--镜像里面包含了我们需要的软件的代码和基础环境,以及依赖软件-->
[root@shimm ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
7a6db449b51b: Pull complete
ca1981974b58: Pull complete
d4019c921e20: Pull complete
7cb804d746d4: Pull complete
e7a561826262: Pull complete
7247f6e5c182: Pull complete
Digest: sha256:b95a99feebf7797479e0c5eb5ec0bdfa5d9f504bc94da550c2f58e839ea6914f
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@shimm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 2b7d6430f78d 2 days ago 142MB
[root@shimm ~]#
6、启动docker容器
[root@shimm ~]# docker run -d -p 8090:80 --name sc-nginx nginx
544c8aabacb957c6225a4f01e6f1a9ad2555dc76d53d870cd6334cf155d5c069
[root@shimm ~]# docker ps #查看启动的进程
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
544c8aabacb9 nginx "/docker-entrypoint.…" 7 minutes ago Up 7 minutes 0.0.0.0:8090->80/tcp, :::8090->80/tcp sc-nginx
[root@shimm ~]#
docker run 是启动容器的命令
启动一个容器是,可以理解为开启一台虚拟机
-d 在后台运行 daemon 守护进程
-p 8090:80指定端口映射 DNAT访问本机的809e端口,转发到docker容器的80端口
name sc-nginx指定容器的名字
nginx 是镜像的名字
7、客户机测试是否能访问
若不成功尝试关闭虚拟机防火墙(service firewalld stop),重启服务(service docker)
涉及docker命令
docker --version 查看docker版本号
docker ps 查看进程
docker imager 查看镜像
docker run (下载某个容器)
docker pull (nginx) 下载(nginx)镜像
docker start 启动一个容器
补:
[root@shimm ~]# **docker info**
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Docker Buildx (Docker Inc., v0.8.2-docker)
compose: Docker Compose (Docker Inc., v2.6.0)
scan: Docker Scan (Docker Inc., v0.17.0)
Server:
Containers: 1
Running: 1
Paused: 0
Stopped: 0
Images: 1
Server Version: 20.10.17
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: systemd
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 0197261a30bf81f1ee8e6a4dd2dea0ef95d67ccb
runc version: v1.1.3-0-g6724737
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-1160.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.777GiB
Name: shimm
ID: I3GL:BOQV:PC4K:KJ6Z:OFKZ:UHCD:CH5H:TE7Y:6NJ5:LRAE:43GD:Y22I
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false