2 Docker Installation and Use

Note that if docker is installed in the virtual machine, the firewall can be closed first to avoid unknown problems.
install
If the docker version is too low, you can list the information of the software that contains the docker field by following commands

# rpm -qa | grep docker 

Uninstall software using Yum remote

# yum remove docker-1.13.1-53.git774336d.el7.centos.x86_64 
# yum remove docker-client-1.13.1-53.git774336d.el7.centos.x86_64 
# yum remove docker-common-1.13.1-53.git774336d.el7.centos.x86_64

Upgrade to the latest version using curl

# curl -fsSL https://get.docker.com/ | sh

Start Docker

systemctl start docker

View the docker version

docker version

docker image acceleration

vim /etc/docker/daemon.json

Add the following

{
"insecure-registries":["192.168.157.65:8888"],
 "registry-mirrors": ["https://v4z55rzu.mirror.aliyuncs.com"]
}

Use

(1) Common docker commands

docker pull openjdk
docker run openjdk:latest java -version
docker rmi {imageName} delete mirror
docker rm {containName} Delete container
docker-compose up -d 
docker exec -it ${container} redis-cli -h 127.0.0.1 -p 6379 Check if the container is properly started

docker ps -a View History Startup Container
docker rm -f {container ID} Force deletion of containers

Look at the log after the specified time and display only the last 100 rows:

$ docker logs -f -t --since="2018-02-08" --tail=100 CONTAINER_ID

Check the logs of the last 30 minutes:

$ docker logs --since 30m CONTAINER_ID

Look at the log after a certain time:

$ docker logs -t --since="2018-02-08T13:23:37" CONTAINER_ID

View the log for a certain period of time:

$ docker logs -t --since="2018-02-08T13:23:37" --until "2018-02-09T12:23:37" CONTAINER_ID

(2) idea configuration docker-Integration (pay attention to closing firewall)

Course address: https://my.oschina.net/wuweixiang/blog/2874064
Docker Opens Remote Access

[root@izwz9eftauv7x69f5jvi96z docker]# vim /usr/lib/systemd/system/docker.service

# Modify ExecStart line

ExecStart=/usr/bin/dockerd  -H tcp://0.0.0.0:2375  -H unix:///var/run/docker.sock

# reload configuration file

[root@izwz9eftauv7x69f5jvi96z docker]# systemctl daemon-reload    

# Restart service

[root@izwz9eftauv7x69f5jvi96z docker]# systemctl restart docker.service 

# Check whether the port is open

[root@izwz9eftauv7x69f5jvi96z docker]# netstat -nlpt

# Direct curl to see if it works

[root@izwz9eftauv7x69f5jvi96z docker]# curl http://127.0.0.1:2375/info

(3) Solve the problem that local navicat can't connect to mysql in docker, local navicat connects error client does not support authentication, and resolves scrambling code

docker exec -it {container ID} sh
mysql -u root -p 
use mysql; 
alter user 'root'@'localhost' identified with mysql_native_password by '123456';
alter user 'root'@'%' identified with mysql_native_password by '123456';
flush privileges;

Used to solve scrambling

SET NAMES 'utf8';

(4) Installation and application of Docker container

docker ps
docker exec -it container id /bin/bash
apt-get update
apt-get install vim

(5) docker-compose use

version: "2"
services:
  eurekaserver1:      # By default, other services can connect to the service using the service name. Therefore, for peer2 nodes, it needs to connect http://peer1:8761/eureka/, so it needs to configure the name of the service to be peer1.
    image: eureka:1.0
    ports:
      - "7900:8900"
    environment:
      - spring.profiles.active=test_ha_1
  eurekaserver2:
    image: eureka:1.0
    ports:
      - "7800:8900"
    environment:
      - spring.profiles.active=test_ha_2
  redis:
    image: redis
    ports:
      - "6379:6379"
  mysql:
    container_name: mysql
    image: mysql
    volumes:
      - ./mysql:/var/lib/mysql
    ports:
      - "3306:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=412826
    restart: always

Run command: docker-compose up-d

Keywords: Docker MySQL yum curl

Added by leon77 on Fri, 04 Oct 2019 21:05:05 +0300