01. Common Docker commands

πŸ“Œ Common Docker commands

πŸ“š Viewing an Image

docker images
Copy the code

πŸ“š View the run container

docker ps
Copy the code

πŸ“š Create a running service

Docker run --privileged= true-itd -p 9006:22 --name Service name Image:tag /sbin/initCopy the code

🏷 such as:

docker run --privileged=true -itd -p 9006:22 -p 8080:8080 -p 9005:21 -p 3306:3306 --name dev-centos Danbojava/centos: v3.0 / sbin/initCopy the code

πŸ“š container packaged as image

Docker commit -a=" author "-m=" Description" Run container ID Packaged image name: versionCopy the code

🏷 such as:

Docker commit -a="Danbo" -m=" 6fd900DA8c2d Danbojava/MySQL :v3.0Copy the code

πŸ“š Run packing

docker-compose -f example/standalone-derby.yaml up
Copy the code

πŸ“šDocker image address

{
  "registry-mirrors": [
    "https://docker.mirrors.ustc.edu.cn",
    "https://kfwkfulq.mirror.aliyuncs.com",
    "https://2lqq34jg.mirror.aliyuncs.com",
    "https://pee6w651.mirror.aliyuncs.com",
    "https://registry.docker-cn.com",
    "http://hub-mirror.c.163.com"
  ],
  "insecure-registries": [],
  "debug": false,
  "experimental": false,
  "features": {
    "buildkit": true
  }
}
Copy the code

02. Docker commonly used image records

mysql

version: "3.1"
services:
    mysql:
        container_name: mysql
        environment:
          MYSQL_ROOT_PASSWORD: "caixibei"
          MYSQL_USER: 'caixibei'
          MYSQL_PASS: 'caixibei'
        image: "Mysql: 5.7"
        volumes:
          - /c/docker-amireux/data:/var/lib/mysql
          - /c/docker-amireux/conf/my.cnf:/etc/my.cnf
        ports:
          - "3306:3306"
        deploy:
          resources:
            limits:
                cpus: '0.02'
                memory: 200M
            reservations:
                cpus: '0.02'
                memory: 200M
Copy the code

vsftpd

version: "3"
services:
    vsftpd:
        image: "fauria/vsftpd"
        container_name: vsftp
        volumes:
          - /c/docker-amireux/vsftp/ftp:/home/vsftpd
        ports:
          - "And"
          - "21100-21110:21100-21110"
        environment:
          - FTP_USER=root
          - FTP_PASS=root...
          - PASV_ADDRESS = 127.0.0.1
          - PASV_MIN_PORT=21100
          - PASV_MAX_PORT=21110
          - write_enable=YES
        deploy:
          resources:
            limits:
                cpus: '0.02'
                memory: 200M
            reservations:
                cpus: '0.02'
                memory: 200M
Copy the code

redis

version: "3"
services:
  redis:
    image: "redis:latest"
    container_name: redis
    restart: always
    ports:
      - 6379: 6379
    volumes:
      - /c/docker-amireux/conf/redis.conf:/etc/redis/redis.conf:rw
      - /c/docker-amireux/redis-data/:/data:rw
    command:
      redis-server /etc/redis/redis.conf --appendonly yes
    deploy:
      resources:
        limits:
            cpus: '0.02'
            memory: 200M
        reservations:
            cpus: '0.02'
            memory: 200M
Copy the code

rabbitmq

version: '3.7'
services:
  # service name
  rabbitmq:
    # container name
    container_name: rabbitmq
    # mirror name
    image: The rabbitmq: 3.7.7 - management
    Always reboot after startup
    # restart: always
    # port mapping
    ports:
      - 5672: 5672
      - 15672: 15672
    # mount
    volumes:
      - /c/docker-amireux/rabbitmq:/var/lib/rabbitmq
    # Environment variables
    environment:
      # - RABBITMQ_DEFAULT_VHOST=my_vhost
      - RABBITMQ_DEFAULT_USER=root
      - RABBITMQ_DEFAULT_PASS=root
    deploy:
      resources:
        limits:
            cpus: '0.02'
            memory: 200M
        reservations:
            cpus: '0.02'
            memory: 200M
Copy the code

Note a problem: if you cannot access the RabbitMQ management page using this startup, it is likely that the deploy is too small and the plugin will not run. Alternatively, you can run the docker run command: docker run -itd -p 15672:15672 -p 5672:5672 –name rabbitMQ rabbitMQ :3.7.7-management

Summary:

version: "3"
services:
    mysql:
        container_name: mysql
        environment:
          MYSQL_ROOT_PASSWORD: "caixibei"
          MYSQL_USER: 'caixibei'
          MYSQL_PASS: 'caixibei'
        image: "Mysql: 5.7"
        volumes:
          - "./data:/var/lib/mysql"
          - "./conf/my.cnf:/etc/my.cnf"
        ports:
          - "3306:3306"
        deploy:
          resources:
            limits:
                cpus: '0.02'
                memory: 200M
            reservations:
                cpus: '0.02'
                memory: 200M
        
      # service name
      rabbitmq:
        # container name
        container_name: rabbitmq
        # mirror name
        image: The rabbitmq: 3.7.7 - management
        Always reboot after startup
        # restart: always
        # port mapping
        ports:
          - 5672: 5672
          - 15672: 15672
        # mount
        volumes:
          - /c/docker-amireux/rabbitmq:/var/lib/rabbitmq
        # Environment variables
        environment:
          # - RABBITMQ_DEFAULT_VHOST=my_vhost
          - RABBITMQ_DEFAULT_USER=root
          - RABBITMQ_DEFAULT_PASS=root
        deploy:
          resources:
            limits:
                cpus: '0.02'
                memory: 200M
            reservations:
                cpus: '0.02'
                memory: 200M
    
    redis:
        image: "redis:latest"
        container_name: redis
        restart: always
        ports:
          - 6379: 6379
        volumes:
          - /c/docker-amireux/conf/redis.conf:/etc/redis/redis.conf:rw
          - /c/docker-amireux/redis-data/:/data:rw
        command:
          redis-server /etc/redis/redis.conf --appendonly yes
        deploy:
          resources:
            limits:
                cpus: '0.02'
                memory: 200M
            reservations:
                cpus: '0.02'
                memory: 200M
    
    vsftpd:
        image: "fauria/vsftpd"
        container_name: vsftp
        volumes:
          - /c/docker-amireux/vsftp/ftp:/home/vsftpd
        ports:
          - "And"
          - "21100-21110:21100-21110"
        environment:
          - FTP_USER=root
          - FTP_PASS=root...
          - PASV_ADDRESS = 127.0.0.1
          - PASV_MIN_PORT=21100
          - PASV_MAX_PORT=21110
          - write_enable=YES
        deploy:
          resources:
            limits:
                cpus: '0.02'
                memory: 200M
            reservations:
                cpus: '0.02'
                memory: 200M
Copy the code

03. Publish the local Jar to docker

Required:

  1. createDockfileFile used to build the image
FROM anapsix/alpine-java:8_server-jre_unlimited
MAINTAINER xxx@163.com
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo "Asia/Shanghai" > /etc/timezone
RUN mkdir -p /fog
WORKDIR /fog
EXPOSE 80
ADD ./fog- 1.0.0.jar ./
CMD java -Djava.security.egd=file:/dev/./urandom -jar -Duser.timezone=GMT+08 fog- 1.0.0.jar
Copy the code
#Build the mirror
docker build -f Dockerfile .
Copy the code
  1. And when you build it, you’ll see thattagandnameAre all<none>

#Modify the tag
docker tag IMAGE_ID lkdt-fog:latest
Copy the code
  1. Release operation
docker run --privileged=true -itd -p 80:80 --name lkdt-fog lkdt-fog:latest
Copy the code