Docker-ce-19.03.9-3.el7安装使用

Docker-ce-19.03.9-3.el7安装使用

1.关闭selinux 关闭swap分区 关闭NetworkManager 关闭firewalld

# setenforce 0
# sed -i  's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# swapoff on
# sed -i '/swap/s/\(.*\)/#\1/' /etc/fstab
# systemctl stop firewalld
# systemctl disable firewalld
# systemctl stop NetworkManager
# systemctl disable NetworkManager
# systemctl  stop  iptables 
# systemctl disable  iptables

2.卸载原有docker

# rpm -qa | grep dcoker
# yum remove docker docker-common docker-client -y

3.安装依赖包

# yum install -y yum-utils device-mapper-persistent-data lvm2

4.安装docker-ce yum源

# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

5.查询docker-ce版本

# yum list docker-ce --showduplicates | sort -r

6.安装docker-ce-19.03.9

# yum -y install docker-ce-19.03.9-3.el7

7.启动docker

# systemctl start docker
# systemctl enable docker

8.配置阿里镜像加速

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://tbctmogl.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

9.下载镜像

[root@localhost yum.repos.d]# docker pull centos:latest
latest: Pulling from library/centos
a1d0c7532777: Pull complete 
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest

10.查看镜像

[root@localhost yum.repos.d]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       latest    5d0da3dc9764   3 months ago   231MB

11.镜像导入导出

# 导出镜像
[root@localhost ~]# docker save -o centos.tar centos:latest
[root@localhost ~]# ls centos.tar 
centos.tar
# 导入镜像
[root@localhost ~]# docker load --input centos.tar 
Loaded image: centos:latest
[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       latest    5d0da3dc9764   3 months ago   231MB

12.本地镜像打标签

[root@localhost ~]# docker tag centos:latest mycentos
[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       latest    5d0da3dc9764   3 months ago   231MB
mycentos     latest    5d0da3dc9764   3 months ago   231MB

13.删除镜像

[root@localhost ~]# docker rmi mycentos:latest
Untagged: mycentos:latest
[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       latest    5d0da3dc9764   3 months ago   231MB

14.启动容器

[root@localhost yum.repos.d]# docker run -ti centos:latest /bin/bash
[root@c5982d8105fa /]# 

15.查看容器

[root@localhost yum.repos.d]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@localhost yum.repos.d]# docker ps -a
CONTAINER ID   IMAGE           COMMAND       CREATED              STATUS                      PORTS     NAMES
c5982d8105fa   centos:latest   "/bin/bash"   About a minute ago   Exited (0) 12 seconds ago             infallible_lamport

16.容器启停

[root@localhost yum.repos.d]# docker start  c5982d8105fa
c5982d8105fa
[root@localhost yum.repos.d]# docker ps
CONTAINER ID   IMAGE           COMMAND       CREATED         STATUS         PORTS     NAMES
c5982d8105fa   centos:latest   "/bin/bash"   3 minutes ago   Up 5 seconds             infallible_lamport
[root@localhost yum.repos.d]# docker stop c5982d8105fa
c5982d8105fa

17.查看容器详细信息

[root@localhost yum.repos.d]# docker inspect c5982d8105fa

18.交互式登陆容器

[root@localhost yum.repos.d]# docker attach c5982d8105fa
[root@c5982d8105fa /]# ps
  PID TTY          TIME CMD
    1 pts/0    00:00:00 bash
   14 pts/0    00:00:00 ps
[root@c5982d8105fa /]# exit
exit
[root@localhost yum.repos.d]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
#attach 是以进程1进入容器,退出后容器也会停止,所以大部分情况不使用attach,使用exec进入
root@localhost yum.repos.d]# docker exec -ti c5982d8105fa /bin/bash
[root@c5982d8105fa /]# ps
  PID TTY          TIME CMD
   14 pts/1    00:00:00 bash
   27 pts/1    00:00:00 ps
[root@c5982d8105fa /]# exit
exit
[root@localhost yum.repos.d]# docker ps
CONTAINER ID   IMAGE           COMMAND       CREATED          STATUS          PORTS     NAMES
c5982d8105fa   centos:latest   "/bin/bash"   19 minutes ago   Up 33 seconds             infallible_lamport

19.使用 Dockerfile 制作镜像

vim Dockerfile
FROM centos:7
ENV doc_root=/var/www/html listen_port=80
RUN yum makecache && yum install -y httpd php php-mysql
ADD phpinfo.php ${doc_root}
EXPOSE 80/tcp
VOLUME ${doc_root}
CMD ["/usr/sbin/httpd","-DFOREGROUND"]
# 执行build命令时一定要在Dockerfile同一级目录
docker build -t myhttpd:v1 .

20.制作好的镜像上传到镜像仓库

[root@docker ~]# docker push 192.168.1.90/private/centos:latest
The push refers to repository [192.168.1.90/private/centos]
74ddd0ec08fa: Mounted from public/centos 
latest: digest: sha256:a1801b843b1bfaf77c501e7a6d3f709401a1e0c83863037fa3aab063a7fdb9dc size: 529
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

roc_yan2019

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值