centos docker installation

Reference: https://qizhanming.com/blog/2019/01/25/how-to-install-docker-ce-on-centos-7

Installation Preparation

For added convenience source software, support devicemapper storage type, install the following packages

$ sudo yum update
$ sudo yum install -y yum-utils  device-mapper-persistent-data  lvm2

Add yum software source

Add Docker stable version of yum software source

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

Installation Docker

Yum update about cache source software, and install Docker.

$ sudo yum update
$ sudo yum install docker-ce

If a pop-up to receive tips GPG key, confirm whether 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35, and if so, can accept and continue with the installation.

So far, Docker has completed the installation, Docker service is not started, the operating system in the docker group is created, but no users in this group.

note

The default is no docker group of users (that is required to use docker using sudo command).
You can add users to docker group (the user can use the direct command of the docker).

Join docker User Group command

$ sudo usermod -aG docker USER_NAME

After updating the user group information, log back into the system to take effect.

Install the specified version

If you want to install the specified version of the Docker, you can check version and install it.

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

. 3-ce.x86_64 Docker: 18.09.1-3.el7 the stable-CE-Docker
Docker-ce.x86_64. 3: 18.09.0-3.el7 the stable-CE-Docker
Docker-ce.x86_64. 3-18.06.1.ce Docker-ce-stable .el7
Docker-ce.x86_64 18.06.0.ce-3.el7 Docker-ce-stable
can specify the installed version, the version number can be ignored: and el7, such as docker-ce-18.09.1

$ sudo yum install docker-ce-<VERSION STRING>

At this point, the specified version of Docker also the installation is complete, the same, within the operating system docker service does not start, only to create a docker group, and there are no user group.

Start Docker

If you want to add to the boot

$ sudo systemctl enable docker

Start docker Service

$ sudo systemctl start docker

Verifying the Installation

Verify Docker CE installed correctly, you can run hello-world image

$ sudo docker run hello-world

Update and uninstall Docker

Use yum management, updating, and uninstalling easy.

Update Docker CE

$ sudo yum update docker-ce

Uninstall Docker CE

$ sudo yum remove docker-ce

Delete the local file
note, Docker local file, comprising a mirror (Images), containers (Containers), storage volumes (Volumes), etc., need to be manually removed. The default directory is stored in / var / lib / docker.

$ sudo rm -rf /var/lib/docker

Common docker command

docker pull centosDownload the image to a local
docker imagesview map list
docker run -i -t centos /bin/bashto start an interactive container
docker run centos echo 'Hello World'

Summary information, docker info
container view that the process of view, docker ps -a
the recent container view,docker ps -l

(2) start container, docker run -d -p 8080: 80 nginx, nginx to 80 ports in a container, port mapping to the current 8080 server, the current server ip is 192.168.1.120, browser type http: // 192.168.1.120:8080/, you can see the nginx started,
(3) and then start more than one container, docker run -d -p 8081: 80 nginx, browser input http://192.168.1.120:8081/, it you can see another nginx has been started
you can also curl 127.0.0.1:8080 to test for open ports
(4) to be able to demonstrate the difference here Docker deploy applications and traditional application deployment, the traditional deployment, then the need to manually copy more of a nginx, and then configure the port, while Docker deploy it, in ready-made mirrored on the basis of one command can deploy a new application

(5) docker inspect a219737ce905 locate the container port command, the host can directly access the container: http://172.17.0.2/:80

(1) docker ps -a container may display ID
(2) STOP 8dc6a2b6f903 Docker stop the container
(3) docker rm 8dc6a2b6f903 remove the container
(4) docker ps currently running display container

docker commit 235923e34a nginx / centos will build their own good 235923e34a submitted to the local container can be used again as the next image
Docker RUN --name = Nexus -i -t CentOS / bin / bash
Docker the Inspect Nexus
Docker Start -i Nexus again start has stopped container

docker run --name = nexus -i -t centos / bin / bash CTRL + P CTRL + Q to exit the interactive, after service station operation
docker attach nexus may be raised to the interactive service running in the background running
docker run --name = nexus CentOS -d / bin / SH -C "to true the while; do echo 'Hello World'; SLEEP. 1; DONE"
Docker logs -t -f --tail 10 nexus 10 shows the latest print log nexus container, designated 10 0 when showing all log
docker top nexus view nexus process operation
docker exec -i -t nexus / bin / bash bash in adding new process has been started nexus vessel, CTRL + P CTRL + Q to exit the interactive, after service station run by docker top nexus command to view the process
docker stop nexus sends a stop signal to stop an elegant container
docker kill nexus directly stop the container
docker network ls view the container network created

Docker exec -it container ID and the container ID docker attach the container can be raised to the foreground. However attach method, when the exit in the container, the container exit, even if the specified start time is the background to start; and exec method, when the exit in the window, just exit the current operation of the terminal, without exiting the process.

Guess you like

Origin www.cnblogs.com/billxxx/p/12117128.html
Recommended