Get Docker CE for CentOS

configure Docker source

Detail url:https://docs.docker.com/engine/installation/linux/docker-ce/centos/
1.Uninstall old versions

Older versions of Docker were called docker or docker-engine. If these are installed, uninstall them, along with associated dependencies.

$ sudo yum remove docker docker-common docker-selinux docker-engine
2.Set up the repository
  • Install required packages
	$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
  • set up the stable repository
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
3.Install Docker CE
$ sudo yum install docker-ce
4.Start Docker
$ sudo systemctl start docker
5.running the hello-world image
$ sudo docker run hello-world
6.Docker Hub

login https://dev.aliyun.com/search.html

vim /etc/docker/daemon.json

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://0i5z79j3.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
7.Docker start remote manager --centos not this step
  • modify configure

vim /etc/systemd/system/multi-user.target.wants/docker.service

	ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0
  • systemctl daemon-reload
  • systemctl restart docker
  • $docker -H 127.0.0.1 info
8.Docker run stop delete
[root@master ~]# docker images
[root@master ~]# docker ps -a

DockerFile

FROM scratch
COPY hello /
CMD ["/hello"]

[root@master ~]# docker pull centos

	FROM scratch
	ADD centos-7-docker.tar.xz /

	LABEL name="CentOS Base Image" \
    vendor="CentOS" \
    license="GPLv2" \
    build-date="20170911"

	CMD ["/bin/bash"]

# uname -r
# docker run -ti centos /bin/bash
Dockerfile
# Version: 0.0.1
FROM centos     1.新镜像不再是从 scratch 开始,而是直接在 centos base 镜像上构建。
MAINTAINER wzlinux
RUN yum update && yum install -y emacs   2.安装 emacs 编辑器。
RUN yum install -y apache2               3.安装 apache2。
CMD ["/bin/bash"]                        4.容器启动时运行 bash。

[root@master ~]# docker build -t rhel_httpd2:2.4 .

[root@master ~]# docker rm $(docker ps -qa)

Custom image

[root@master tmp]# docker run -ti rhel /bin/bash
[root@f54311d5c910 /]# yum -y install httpd
[root@master tmp]# docker ps -a
[root@master tmp]# docker commit f54311d5c910 wzlinux/centos_with_centos
[root@master tmp]# docker images

push local image to docker repository

[root@master tmp]# docker login ---login https://hub.docker.com

building private repository

 docker pull registry
 docker images
 docker run -d -p 5000:5000 registry:latest
 docker ps
 docker tag 5709795eeffa localhost:5000/leejaylinux/mysql:2.0
 docker images
 docker push localhost:5000/leejaylinux/mysql

enter container two way

  1. root@ubuntu:~# docker exec -ti 780ec986be0f /bin/bash

  2. root@ubuntu:~# docker start 0972061092ac

    root@ubuntu:~# docker attach 0972061092ac

能够动态查看日志的产生

[root@master tmp]# docker logs -f ba4681c485e5