[root@localhost ~]# systemctl start docker[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
镜像加速
tee /etc/docker/daemon.json <<-'EOF'{"registry-mirrors":["从阿里云的镜像加速获取到的地址"]}
EOF
[root@localhost ~]# docker tag nginx:latest nginx:test[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest ed21b7a8aee9 8 days ago 127MB
nginx test ed21b7a8aee9 8 days ago 127MB
保存镜像
[root@localhost ~]# docker save -o /opt/nginx nginx:latest[root@localhost ~]# cd /opt[root@localhost opt]# ls
containerd nginx rh
[root@localhost home]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
删除镜像
[root@localhost home]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest ed21b7a8aee9 8 days ago 127MB
nginx test ed21b7a8aee9 8 days ago 127MB
[root@localhost home]# docker rmi nginx:test
Untagged: nginx:test
[root@localhost home]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest ed21b7a8aee9 8 days ago 127MB
启动容器
[root@localhost home]# docker run -it nginx:latest /bin/bash
root@1a5319a4fa45:/# exitexit[root@localhost home]# docker ps -qa
1a5319a4fa45
[root@localhost home]# docker start 1a5319a4fa45
1a5319a4fa45
[root@localhost home]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1a5319a4fa45 nginx:latest "/bin/bash" 2 minutes ago Up 11 seconds 80/tcp hardcore_meninsky
关闭容器
[root@localhost home]# docker stop 1a5319a4fa45
1a5319a4fa45
[root@localhost home]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1a5319a4fa45 nginx:latest "/bin/bash" 4 minutes ago Exited (0) 5 seconds ago hardcore_meninsky
docker的几种状态
created #镜像pull下来,没有加载
up #容器在运行中
exited #0表示正常退出 其他数表示异常退出
进入到容器里面
[root@localhost home]# docker run -it nginx:latest /bin/bash
root@1d634837b6c7:/# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
root@1d634837b6c7:/# exitexit[root@localhost home]# docker start 1a5319a4fa45
1a5319a4fa45
[root@localhost home]# docker exec -it 1a5319a4fa45 /bin/bash
root@1a5319a4fa45:/# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
root@1a5319a4fa45:/# exitexit
获取centos7的镜像,并进行简单操作
[root@localhost home]# docker pull centos:7
7: Pulling from library/centos
ab5ef0e58194: Pull complete
Digest: sha256:4a701376d03f6b39b8c2a8f4a8e499441b0d567f9ab9d58e4991de4472fb813c
Status: Downloaded newer image for centos:7
docker.io/library/centos:7
[root@localhost home]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest ed21b7a8aee9 8 days ago 127MB
centos 7 5e35e350aded 4 months ago 203MB
[root@localhost home]# docker create -it centos:7 /bin/bash
ca9cdcbe215c01788607b37a19844e46fd9b268d88cb6bea68f37cb1c867ef09
[root@localhost home]# docker start ca9cdcbe215c01788607b37a19844e46fd9b268d88cb6bea68f37cb1c867ef09
ca9cdcbe215c01788607b37a19844e46fd9b268d88cb6bea68f37cb1c867ef09
[root@localhost home]# docker ps -q[root@localhost home]# docker run centos:7 /usr/bin/bash -c ls /
anaconda-post.log
bin
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
[root@localhost home]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
88a55e5aa881 centos:7 "/usr/bin/bash -c ls…" 11 seconds ago Exited (0) 10 seconds ago beautiful_clarke
ca9cdcbe215c centos:7 "/bin/bash" 2 minutes ago Up 2 minutes sad_satoshi
195abeb364a1 nginx:latest "/bin/bash" 14 minutes ago Exited (0) 13 minutes ago modest_mclaren
1d634837b6c7 nginx:latest "/bin/bash" 18 minutes ago Exited (0) 18 minutes ago vigilant_darwin
1a5319a4fa45 nginx:latest "/bin/bash" 26 minutes ago Exited (0) 15 minutes ago hardcore_meninsky
[root@localhost home]# docker stop ca9cdcbe215c
ca9cdcbe215c