Linux搭建docker环境并简单实用
记录生活:
配置阿里云镜像源docker YUM
[root@centos-linux ~]# sudo yum install -y yum-utils device-mapper-persistent-data lvm2
[root@centos-linux ~]# sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装 Docker-CE
[root@centos-linux ~]# sudo yum install docker-ce
启动docker
# 开机自启 [root@centos-linux ~]# sudo systemctl enable docker # 启动docker服务 [root@centos-linux ~]# sudo systemctl start docker
查看版本
[root@centos-linux ~]# docker -v Docker version 19.03.8, build afacb8b
查看详情
[root@centos-linux ~]# docker version Client: Docker Engine - Community Version: 19.03.8 API version: 1.40 Go version: go1.12.17 Git commit: afacb8b Built: Wed Mar 11 01:27:04 2020 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 19.03.8 API version: 1.40 (minimum version 1.12) Go version: go1.12.17 Git commit: afacb8b Built: Wed Mar 11 01:25:42 2020 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.2.13 GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429 runc: Version: 1.0.0-rc10 GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd docker-init: Version: 0.18.0 GitCommit: fec3683 [root@centos-linux ~]# docker info Client: Debug Mode: false Server: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 19.03.8 Storage Driver: overlay2 Backing Filesystem: <unknown> Supports d_type: true Native Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs 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: runc Default Runtime: runc Init Binary: docker-init containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd init version: fec3683 Security Options: seccomp Profile: default Kernel Version: 3.10.0-1062.el7.x86_64 Operating System: CentOS Linux 7 (Core) OSType: linux Architecture: x86_64 CPUs: 2 Total Memory: 482.4MiB Name: centos-linux.shared ID: DFEQ:IXET:QELN:7ZA6:BM6D:5ENE:2TEN:Y3MD:BVOG:KM54:CTAS:IUK4 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
下载centos镜像,测试
[root@centos-linux ~]# docker pull centos
查看列表
[root@centos-linux ~]# docker images
运行容器,当出现root@《一串数字》表示进入
[root@centos-linux ~]# docker run -it centos /bin/bash [root@7f32d43c7e53 /]# ls bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
退出容器
exit
查看所有的容器信息, 能获取容器的id
[root@centos-linux ~]# docker ps -a
docker commit -m=“备注” 你的CONTAINER_ID 你的IMAGE
请自行将 -m 后面的信息改成自己的容器的信息
以及删除容器命令rmi
[root@centos-linux ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7f32d43c7e53 centos "/bin/bash" 2 minutes ago Exited (0) 27 seconds ago sharp_cohen [root@centos-linux ~]# docker commit -m='lious' 7f32d43c7e53 centos sha256:8d75dd2b1d0150decc7c82bc0d3ca467856fefb5c4ec20d4b35f03f61fc7faab [root@centos-linux ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7f32d43c7e53 470671670cac "/bin/bash" 3 minutes ago Exited (0) About a minute ago sharp_cohen [root@centos-linux ~]# docker commit -m='lious' 7f32d43c7e53 liousdeimage sha256:0131fbbdfe2c5589a77356f77406f349c6aa7c3275835a7cdfd94be2a2d2b256 [root@centos-linux ~]# ls anaconda-ks.cfg original-ks.cfg redis-4.0.2 redis-4.0.2.tar.gz [root@centos-linux ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7f32d43c7e53 470671670cac "/bin/bash" 5 minutes ago Exited (0) 3 minutes ago sharp_cohen [root@centos-linux ~]# docker commit -m='备注' 7f32d43c7e53 470671670cac sha256:c003336be27108c9c2485ae43b02587b224d02b4a3ac79c7f46227bc22c6bc4d [root@centos-linux ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 470671670cac latest c003336be271 13 seconds ago 237MB liousdeimage latest 0131fbbdfe2c About a minute ago 237MB centos latest 8d75dd2b1d01 3 minutes ago 237MB centos <none> 470671670cac 3 months ago 237MB [root@centos-linux ~]# docker rmi 470671670cac:latest Untagged: 470671670cac:latest Deleted: sha256:c003336be27108c9c2485ae43b02587b224d02b4a3ac79c7f46227bc22c6bc4d [root@centos-linux ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE liousdeimage latest 0131fbbdfe2c 2 minutes ago 237MB centos latest 8d75dd2b1d01 4 minutes ago 237MB centos <none> 470671670cac 3 months ago 237MB
更多docker命令链接:https://www.jianshu.com/p/2dae7b13ce2f
作者:四叶草的诗雨
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.