Image, container, and data volume operation instructions commonly used in docker platform

Image, container, and data volume operation instructions commonly used in docker platform

  • Uninstall Docker

    • sudo yum remove docker-ce
      docker-ce-client
      docker-client-latest
      docker-common
      docker-latest
      docker-latest-logrotate
      docker-logrotate
      docker-engine
  • Install docker Online

    • The first step is to install a set of tools:

      sudo yum install -y yum-utils
      
    • Step 2: set the yum warehouse address

      sudo yum-config-manager \
          --add-repo \
          https://download.docker.com/linux/centos/docker-ce.repo
      
      
      sudo yum-config-manager \
           --add-repo \
           http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
      
      
    • Step 3: update yum cache

      sudo yum makecache fast #yum is package management
      
    • Step 4: install the new docker

      sudo yum install -y docker-ce docker-ce-cli containerd.io
      
  • Offline installation of Docker

    • Download docker offline package:

      • https://download.docker.com/linux/static/stable/x86_64/docker-20.10.6.tgz
    • Download offline installation tools

      • https://github.com/Jrohy/docker-install/
    • In the linux environment, create the / root/setup/docker directory, and then copy the downloaded resources to this directory (you can directly upload them to the linux directory through MobaXterm tool)

    • Perform the installation operation

      • # Enter the / root/setup/docker folder
        cd /root/setup/docker
        
        # Add execution permissions for install.sh
        chmod +x install.sh
        
        # install
        ./install.sh -f docker-20.10.6.tgz
        
        
    • Check the installation status after successful installation

      • docker info
        
  • Basic operations of Docker service

    • start-up docker Services: systemctl start docker
       see docker Status: systemctl status docker
       set up docker Startup and self start: systemctl enable docker
       Disable docker Startup and self start: systemctl disable docker
       Restart docker Services: systemctl restart docker
       see docker Information: docker info
       stop it docker Services: systemctl stop docker
      
  • Docker image operation

    • Download Image: docker pull hello-world
       View all mirrors: docker image
       View image details: docker inspect hello-world(Image name or image id Or mirror id Top three of)
      To view mirror history: docker history hello-world
       Export image file: docker save hello-world | gzip > hello-world.tar.gz
       To delete a mirrored file: docker image rm hello-world
       Import mirror operation (to be hello-world.tar.gz File directory: docker load < hello-world.tar.gz
       Run mirror file: docker run hello-world
      
  • Docker container operation practice

    • -it: These are two parameters (- i for interactive operation, - t for terminal)

    • bash means to enter the operation terminal and carry out relevant operations based on interaction

    • download CentOS Mirror image: docker pull centos:7
       To create and start a container: docker run -it Image name/image id First few bash
      		For example: docker run -it centos:7 bash
       see docker Running container (to be executed on the host) docker Instruction: docker ps
       see docker All containers in operation: docker ps -a
       View container log logs Information: docker container logs 802(container id Top three of)
      Stop container: docker container stop 802
       Restart container: dockerscontainer restart 802
       When the container is running, it can be used to enter the container docker exec command(If there is no runtime, executing this command will cause problems): docker exec -it 802 bash
      
      Exit container: exit
       Delete container: docker container rm 802(If container is running, an error occurs when executing this command)
      Delete running container: docker container rm -f 802
       Clear all terminated containers: docker container prune(After execution, you can docker ps -a Check whether the container has been deleted)
      
  • Data volume operation:

    • Create data volume: docker volume create container-vol
       View all data volumes: docker volume ls
       To view information about a specified data volume: docker volume inspect container-vol
       Start the container that mounts the data volume: docker run -it --mount source=container-vol,target=/root centos:7 bash (Abbreviation: docker run -it -v  container-vol:/root centos:7 bash)
      Delete data volume (data volume cannot be deleted if it is used by container): docker volume rm container-vol
       Clean up unmanaged data volumes: docker volume prunm
      
      
  • Dockerfile and image making practice

    • Copy the compressed package jdk-8u51-linux-x64.tar.gz to / root/setup/jdk

    • Enter the directory of jdk-8u51-linux-x64.tar.gz file: create Dockerfile based on vim: vim Dockerfile

    • Copy:
      FROM centos:7
      ADD jdk-8u51-linux-x64.tar.gz /usr/local/docker
      ENV JAVA_HOME=/usr/local/docker/jdk1.8.0_51 \
          PATH=/usr/local/docker/jdk1.8.0_51/bin:$PATH
      CMD ['bash']
      
    • Create JDK image

    • Create a jdk image file: execute the docker build command in the directory where the Dockerfile is located

      • docker build -t jdk:8 .  #Don't lose the dot here, - t stands for the image ID (image name), which is the abbreviation of tag
        
    • Run JDK image file

      • docker run -it jdk:8 bash
        
    • Start sentinel based on JDK image:

      • Step 1: copy sentinel-dashboard-1.8.0.jar to the specified directory of the host, such as / root/servers directory (the servers directory does not exist and can be created by yourself).

      • Start the image container and run the web service through java

        Start and run sentinel service based on jdk:8 image (the service can be accessed on the host through localhost:8180 after startup)

        docker run -d -p 8180:8080 --name sentinel \
        -v /root/servers:/usr/sca \
        jdk:8 java -jar /usr/sca/sentinel-dashboard-1.8.0.jar
        
        1. -d indicates background operation
        2. -p is used to implement port mapping (assuming that external users must do port mapping to access this container)
        3. – name indicates a name for the container to start
      • Here, after the service is started, you can view the started service through the docker ps command. If you can't see the service, it may fail to start. You can view the specific log through the following command

        docker container logs  689 #Here 689 is the container id or your container name
        
      • Step 3: open the browser and access sentinel service
        Open the browser in windows, enter your ip address (this ip is the ip address of the remote host), and the port number is the port number of the host. (8081)

    • Create Sentinel image file

    • Check whether centos:7 exists through the docker images command, and then put jdk-8u51-linux-x64.tar.gz,sentinel-dashboard-1.8.0.jar in the / root/setup/sentinel directory (if the directory does not exist, create it yourself)

      • Step 1: create a Dockerfile file in the directory where sentinel is located, and add the following

        • FROM centos:7
          ADD jdk-8u51-linux-x64.tar.gz  /usr/local/
          ADD sentinel-dashboard-1.8.0.jar  /usr/local/
          ENV JAVA_HOME=/usr/local/jdk1.8.0_51 \
              PATH=/usr/local/jdk1.8.0_51/bin:$PATH
          EXPOSE 8080
          ENTRYPOINT ["java","-jar","/usr/local/sentinel-dashboard-1.8.0.jar"]
          
          
      • Step 2: use Dockerfile to build an image (execute the docker instruction in the directory where Dockerfile is located)

        • docker build -t  sentinel:8 .  #Don't lose the point here
          
      • Step 3: run sentinel container in the background

        • docker run -d --name sentinel8181 -p 8181:8080 sentinel:8  #-d indicates background operation, - p is used to specify port mapping, sentinel:8 is the image file name
          
      • Step 4: View sentinel container

        • docker ps
          
      • Step 5: access sentinel service

  • Install Mysql database

    • Install mysql

      • Download: docker pull mysq: 8.0.23
         Check: docker images
         function mysql Mirror image:
        	sudo docker run -p 3306:3306 --name mysql \
            -v /usr/local/docker/mysql/mysql-files:/var/lib/mysql-files \
            -v /usr/local/docker/mysql/conf:/etc/mysql \
            -v /usr/local/docker/mysql/logs:/var/log/mysql \
            -v /usr/local/docker/mysql/data:/var/lib/mysql \
            -e MYSQL_ROOT_PASSWORD=root \
            -d mysql:8.0.23
         If the installation fails, you can docker ps -a View the previous container. If it already exists, click docker rm image id Delete and reinstall.
        
    • Log in to mysql service:

      • Enter container: sudo docker exec -it mysql bash
         Sign in mysql,Be sure to enter first mysql: mysql -uroot -proot
         stop it mysql: docker stop mysql
         start-up mysql: docker start mysql
         see mysql Log at startup: docker container logs mysql
         set up mysql Startup and self startup: docker update mysql --restart=always
        
  • Install Redis database

    • Install redis

      • Download Image File: docker pull redis
         Prepare profile:
        	1.establish redis Profile directory: mkdir -p /usr/local/docker/redis01/conf
        	2.Create under profile record redis.conf configuration file(This file must be created. Otherwise, it will be created by default when we mount the directory	Recognize that a directory is generated): touch /usr/local/docker/redis01/conf/redis.conf
         establish redis Instance and start:
            sudo docker run -p 6379:6379 --name redis01 \
            -v /usr/local/docker/redis01/data:/data \
            -v /usr/local/docker/redis01/conf/redis.conf:/etc/redis/redis.conf \
            -d redis redis-server /etc/redis/redis.conf 
        View running processes: docker ps
        
    • To access the redis server:

      • Step 1: connect the console directly redis Test: docker exec -it redis01 bash
         Step 2: detection redis edition: redis-server  -v  Or: redis-cli -v
         Step 3: Login redis(No password is required by default): redis-cli
         Or you can directly combine the above two steps into one step. The instructions are as follows: ocker exec -it redis01 redis-cli
        
        Stop access: docker stop redis01
         Start access: docker start redis01
         Restart access: docker restart redis01
        
        
  • Install Nginx agent

    • Installing Nginx

      • Download: docker pull nginx
         see: docker images
         Create data volume(This object will create a directory directly on the host): docker volume create nginx-vol
         View the host directory corresponding to the data volume,You can use the following instructions:docker inspect nginx-vol
         start-up nginx Services: docker run --name nginx  -p 80:80 -v nginx-vol:/etc/nginx -d nginx
        
        Stop access: docker stop nginx
         Start access: docker start nginx
         Restart access: docker restart nginx
        
  • Installing Nacos components

    • To install the nacos component:

      • Step 1: Download: docker pull nacos/nacos-server:1.4.1
        
        Step 2: mysql Medium execution nacos of sql Script file
        1)Add this file nacos-mysql.sql(This file is available from code Server download)copy to mysql The mount directory corresponding to the host of the container(Can pass docker inspect mysql View you mysql Mount directory for)
        2)stay linux Start and log in under environment mysql get into mysql container(Premise is mysql Started): docker exec -it mysql bash
         Sign in mysql: mysql -uroot -p
        3)adopt source Instructions run in the container directory sql File: source  /etc/mysql/nacos-mysql.sql  #Here, / etc/mysql is a directory in the container (select the directory you want to mount)
        
        
        Step 3: create and start nacos container(When copying the following,The account and password should be hosted by yourself ip,Account and password of your own database): 
                    docker run  \
                    -e TZ="Asia/Shanghai" \
                    -e MODE=standalone \
                    -e SPRING_DATASOURCE_PLATFORM=mysql \
                    -e MYSQL_DATABASE_NUM=1 \
                    -e MYSQL_SERVICE_HOST=192.168.126.129 \
                    -e MYSQL_SERVICE_PORT=3306 \
                    -e MYSQL_SERVICE_USER=root \
                    -e MYSQL_SERVICE_PASSWORD=root \
                    -e MYSQL_SERVICE_DB_NAME=nacos_config \
                    -p 8848:8848 \
                    --name nacos \
                    --restart=always \
                    -d nacos/nacos-server:1.4.1
        
        Step 4: check nacos Services: docker ps
         If the startup fails, check the startup log, for example: docker container logs nacos(Among them, nacos Startup log for/home/nacos/logs/start.out File.
        
        visit nacos service
         start-up nacos,Then in windows Medium input http://ip:port/nacos access test (Port: 8848)
        
        
        Stop access: docker stop nacos
         Start access: docker start nacos
         Restart access: docker restart nacos
        

Tags: Linux CentOS Docker

Posted on Tue, 12 Oct 2021 01:30:09 -0400 by Stalingrad