preface

In fact, I have been in touch with Docker for some time, but I haven’t made a summary. Now there are many introductions about Docker on the Internet. In line with the principle that a good memory is better than a bad pen, I’d better record another wave by myself.

Achieve the goal

  • Install the docker ce
  • Explore the basic concepts and usage of Docker

Environment to prepare

  • Centos7 64-bit, kernel version 3.10 or higher

Install the docker ce

The following commands must be executed under root permission.

Uninstall the old docker:

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine
Copy the code

Installation software dependency package:

 yum install -y yum-utils \
           device-mapper-persistent-data \
           lvm2
Copy the code

Add yum software source:

The one added here is the domestic source, which is faster

sudo yum-config-manager \
    --add-repo \
    https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo
Copy the code

Install using yum command:

Sudo yum install docker-ce sudo yum install docker-ceCopy the code

Start Docker CE:

sudo systemctl enable docker
sudo systemctl start docker
Copy the code

Test whether the installation is successful:

Print version number:

Docker -v # docker version 18.09.1, build 4C52b90Copy the code

Test the hello docker

Docker run hello-worldCopy the code

The results are shown below:

  • The docker run command runs an image and generates a container that first looks for the image from the local image library
  • If no mirror exists, pull the mirror from the remote device

Docker basic commands

  • Viewing a Local Mirror

    docker images
    Copy the code

    You can see all local mirror information:

    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    hello-world         latest              fce289e99eb9        12 days ago         1.84kB
    Copy the code
  • View the running container

    docker ps
    Copy the code
  • View all containers including closed containers

    docker ps -a
    Copy the code
  • Delete a stopped container

    Docker rm + Container ID/container nameCopy the code
  • Stop the running container

    Docker stop Container ID/container nameCopy the code
  • Remove the mirror

    Docker RMI Image ID/image nameCopy the code

The last

A brief record of docker entry practice, the next article will record Jenkins + Gitlab + Maven automatic package deployment project, the use of Docker installation needs Jenkins, welcome to pay attention to the public number “Zhang Shaolin students”!