docker

1、登录阿里云docker命令:
docker login --username=dayzhang1987@163.com registry.cn-hangzhou.aliyuncs.com
登录密码:
Zhang@123

2、将镜像推送到阿里云Registry
$ sudo docker login --username=dayzhang1987@163.com registry.cn-hangzhou.aliyuncs.com $ sudo docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/[命名空间]/[仓库名称]:[镜像版本号] $ sudo docker push registry.cn-hangzhou.aliyuncs.com/[命名空间]/[仓库名称]:[镜像版本号]

3、创建镜像
$ docker build -t [镜像名称] . $ docker build -t lgy-mysql-zh .

4、启动容器
$ docker run --name [容器别名] -d -p [主机端口]:[镜像内端口] [镜像名称] $ docker run --name mysql_test01 -d -p 3308:3306 test/docker-mysql

docker-compose/docker-compose.yml文件

# docker-compose.yml文件的版本
version: "3"
# 管理的服务
services:
  nginx:
    image: nginx:1.17.8
    restart: always
    container_name: nginx
    environment:
      - TZ=Asia/Shanghai
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - "/opt/docker/docker-compose/volume/nginx/nginx.conf:/etc/nginx/nginx.conf"
      - "/opt/docker/docker-compose/volume/nginx/conf.d:/etc/nginx/conf.d"
      - "/opt/docker/docker-compose/volume/nginx/log:/var/log/nginx"
      - "/opt/docker/docker-compose/volume/nginx/www:/etc/nginx/html"
      - "/opt/docker/docker-compose/volume/nginx/letsencrypt:/etc/letsencrypt"

  nacos:
    restart: on-failure
    image: nacos/nacos-server:1.1.4
    container_name: nacos-standalone
    volumes:
      - "/opt/docker/docker-compose/volume/nacos/standalone-logs/:/home/nacos/logs"
      - "/opt/docker/docker-compose/volume/nacos/custom.properties:/home/nacos/init.d/custom.properties"
    ports:
      - "8848:8848"
      - "9555:9555"
    environment:
      - PREFER_HOST_MODE=hostname
      - MODE=standalone
      - MYSQL_DATABASE_NUM=1
      - SPRING_DATASOURCE_PLATFORM=mysql
      - MYSQL_MASTER_SERVICE_HOST=mysql
      - MYSQL_MASTER_SERVICE_DB_NAME=nacos_devtest
      - MYSQL_MASTER_SERVICE_PORT=3306
      - MYSQL_MASTER_SERVICE_USER=root
      - MYSQL_MASTER_SERVICE_PASSWORD=12345
    depends_on:
      - mysql

  redis:
    restart: always
    # 指定镜像
    image: redis:4
    container_name: redis
    ports:
      # 端口映射
      - 9050:6379
    volumes:
      # 目录映射
      - "${REDIS_DIR}/conf:/usr/local/etc/redis"
      - "${REDIS_DIR}/data:/data"
    command:
      # 执行的命令
      redis-server /usr/local/etc/redis/redis.conf

  mysql:
    restart: always
    image: mysql:5.7
    container_name: mysql57
    ports:
      - 9051:3306
    volumes:
      - "${MYSQL_DIR}/data:/var/lib/mysql"
      - "${MYSQL_DIR}/conf.d:/etc/mysql/conf.d"
    environment:
      # 环境变量
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}

  gateway:
    image: java:8
    restart: always
    container_name: gateway
    ports:
      - "9052:9000"
    volumes:
      - "/opt/docker/docker-compose/services/gateway-0.0.1-SNAPSHOT.jar:/opt/jar/gateway-0.0.1-SNAPSHOT.jar"
    entrypoint: java -jar -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=128m -Xms128m -Xmx256m -Xmn128m -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC /opt/jar//gateway-0.0.1-SNAPSHOT.jar
    depends_on:
      - nacos


  oauth:
    image: java:8
    restart: always
    container_name: oauth
    ports:
      - "9053:6060"
    volumes:
      - "/opt/docker/docker-compose/services/oauth2-0.0.1-SNAPSHOT.jar:/opt/jar/oauth2-0.0.1-SNAPSHOT.jar"
    entrypoint: java -jar -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=128m -Xms128m -Xmx512m -Xmn128m -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC /opt/jar/oauth2-0.0.1-SNAPSHOT.jar
    depends_on:
      - nacos
      - gateway

  user:
    image: java:8
    restart: always
    container_name: user
    ports:
      - "9054:7070"
    volumes:
      - "/opt/docker/docker-compose/services/user-0.0.1-SNAPSHOT.jar:/opt/jar/user-0.0.1-SNAPSHOT.jar"
    entrypoint: java -jar -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=128m -Xms128m -Xmx512m -Xmn128m -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC /opt/jar/user-0.0.1-SNAPSHOT.jar
    depends_on:
      - nacos
      - gateway


  cli:
    image: java:8
    restart: always
    container_name: cli
    ports:
      - "9055:12001"
    volumes:
      - "/opt/docker/docker-compose/services/cb-platform-index-0.0.1-SNAPSHOT.jar:/opt/jar/cb-platform-index-0.0.1-SNAPSHOT.jar"
    entrypoint: java -jar -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=128m -Xms128m -Xmx512m -Xmn128m -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC /opt/jar/cb-platform-index-0.0.1-SNAPSHOT.jar
    depends_on:
      - nacos

  manager:
    image: java:8
    restart: always
    container_name: manager
    ports:
      - "9058:12002"
    volumes:
      - "/opt/docker/docker-compose/services/cb-platform-manager-0.0.1-SNAPSHOT.jar:/opt/jar/cb-platform-manager-0.0.1-SNAPSHOT.jar"
    entrypoint: java -jar -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=128m -Xms128m -Xmx1024m -Xmn128m -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC /opt/jar/cb-platform-manager-0.0.1-SNAPSHOT.jar
    depends_on:
      - nacos

  yq:
    image: java:8
    restart: always
    container_name: yq
    ports:
      - "9059:12004"
    volumes:
      - "/opt/docker/docker-compose/services/cb-platform-yq-2.0.0.jar:/opt/jar/cb-platform-yq-2.0.0.jar"
    entrypoint: java -jar -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=128m -Xms128m -Xmx1024m -Xmn128m -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC /opt/jar/cb-platform-yq-2.0.0.jar
    depends_on:
      - nacos

docker-compose/.env文件

# .env文件内容
# redis
REDIS_DIR=/opt/docker/docker-compose/volume/redis

# mysql
MYSQL_DIR=/opt/docker/docker-compose/volume/mysql
MYSQL_ROOT_PASSWORD=12345

#nacos
#PREFER_HOST_MODE=ip
#MODE=standalone
#SPRING_DATASOURCE_PLATFORM=mysql
#MYSQL_SERVICE_HOST=172.16.152.238
#MYSQL_SERVICE_DB_NAME=nacos_devtest
#MYSQL_SERVICE_PORT=9501
#MYSQL_SERVICE_USER=root
#MYSQL_SERVICE_PASSWORD=12345

#MYSQL_MASTER_SERVICE_HOST=172.16.152.238
#MYSQL_MASTER_SERVICE_PORT=9501
#MYSQL_MASTER_SERVICE_DB_NAME=nacos_devtest
#MYSQL_MASTER_SERVICE_USER=root
#MYSQL_MASTER_SERVICE_PASSWORD=12345

docker-compose/volume/nginx/nginx.conf

user  root;
worker_processes  1;

pid        /var/run/nginx.pid;

worker_rlimit_nofile 65535;

events {
    use epoll;
    multi_accept on;
    worker_connections  65535;
}

http {
    charset utf-8;
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    server_tokens off;
    log_not_found off;
    types_hash_max_size 2048;
    client_max_body_size 16M;

    # MIME
    include /etc/nginx/conf.d/mime.types;
    default_type application/octet-stream;

    # logging
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;
    error_log  /var/log/nginx/error.log warn;

    # SSL
    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:50m;
    ssl_session_tickets off;

    # OCSP Stapling
    ssl_stapling on;
    ssl_stapling_verify on;
    resolver 1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4 208.67.222.222 208.67.220.220 valid=60s;
    resolver_timeout 2s;
	
    # index.php
    index index.php index.html index.htm;

    # load configs
    include /etc/nginx/conf.d/*.conf;
}

docker-compose/volume/redis/conf/redis.conf

requirepass redispassword
masterauth redisauth

docker-compose/volume/mysql/conf.d/my.cnf

[mysqld]
default-time-zone='+8:00'
innodb_rollback_on_timeout='ON'
max_connections=500
innodb_lock_wait_timeout=500
lower_case_table_names=1
posted @ 2021-08-15 20:48  lee2guang  阅读(38)  评论(0编辑  收藏  举报